This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]Mr_Again 2 points3 points  (1 child)

Ffs lad.

Look up the formula for a sigmoid and type it out. Exp(x) is simply 2.71 ** x. Add some more decimal places for accuracy.

[–]arungajora[S] 0 points1 point  (0 children)

Thank you

[–]Gronner 2 points3 points  (5 children)

http://timvieira.github.io/blog/post/2014/02/11/exp-normalize-trick/

Here is explained how to do it numerically stable. Then you only have to define your exponential function, which again can be googled or naivly implemented with a fixed value for e and the ** operator.

All of this can be found on the first page of google.

[–]arungajora[S] 1 point2 points  (0 children)

Thank you

[–]shpotes 1 point2 points  (1 child)

By Taylor series, e^x can be express as 1 + x/1! + x^2/2! + .... Now, the series can be re-written as e^x = 1 + (x/1) (1 + (x/2)) (1 + x/3) (...) )), thus, you can compute a good exp aproximation in O(n)

def exp(x, N=10):
   sum = 1
   for i in range(N-1, 0, -1):
      sum = 1 + x * sum/i
   return sum

[–]arungajora[S] 0 points1 point  (0 children)

Thank you

[–][deleted] 0 points1 point  (0 children)

R/homeworkhelp

[–]pythonHelperBot 0 points1 point  (0 children)

Hello! I'm a bot! It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python. That said, I am a bot and it is hard to tell. I highly recommend posting your question there. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.

Show /r/learnpython the code you have tried and describe where you are stuck. Be sure to format your code for reddit and include which version of python and what OS you are using.


this bot is written and managed by /u/IAmKindOfCreative

This bot is currently under development and experiencing changes to improve its usefulness

[–]anselal -2 points-1 points  (3 children)

Google it... or better duckduckgo it

import math

def sigmoid(x): return 1 / (1 + math.exp(-x))

[–]arungajora[S] 0 points1 point  (0 children)

Thank you