How to calculate exp (x) for really big integers in Python?

I use the sigmoid function for my artificial neural network. The value that I pass to the function is from 10,000 to 300,000. I need a highly accurate answer, because it will serve as the weight of the connection between nodes in my artificial neural network. I tried to look at zero, but no luck. Is there any way to calculatee^(-x)

+4
source share
3 answers

The regular python math and number modules will overflow on exp (300000).

You need an arbitrary precision floating point library.

Prereq: pip install mpmath

from mpmath import *
mp.dps=300
print exp(300000)
2.21090954962043147554031964344003334958746533182776533253160702399084245726328190320934903726540800347936047182773804396858994958295396516475277561815722954583856797032504775443385287094864178178111231967140927970972263439977028621274619241097429676587262948251263990280758512853239132411057394977398e+130288

see also http://code.google.com/p/mpmath/

+4

@Paul

- - , - . , . , , :

  • / /
  • , .

. Neural Networks Learning Machines Haykin.

+4

decimal stdlib exp(-300000) :

>>> import decimal
>>> decimal.getcontext().prec = 300
>>> decimal.Decimal(-300000).exp()
Decimal('4.52302537736869338168154543856941208987901785730658877589102779454404342316583413710153707357620016787644963947448152347606024065141665176979995260298156742722510150887341893137830615617098803353373668680329179329422367091094657806579661636984526349130940466600671093389647604708034230900336526970689E-130289')

@lejlot: , , - .

+2

Source: https://habr.com/ru/post/1534012/


All Articles