tylerl-uxai - 1 year ago 77

Javascript Question

How do I know what the letter e equals in the sigmoid function?

1/(1+e^activationFunction)

In javascript is it just

return 1/(1+Math.E^(x));

Or is E not euleger's number?

`console.log(1/(1+Math.exp(0))); // .5`

console.log(1/(1+2.718281828459045^(0))); // 0.3333333333333333

Math.exp definitely works but when I do Math.exp(1) I get 2.718281828459045. When I plug that in and raise it to a power, it breaks?

`console.log(1/(1+Math.pow(2.718281828459045, 1))); // 0.2689414213699951 It works!`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

*e* is eulers number. In javascript, use Math.exp(*x*) to obtain it:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp

To get 1/(1+e^x) in javascript, use

```
var y = 1 / (1 + Math.exp(x)); // y = 1/(1+e^x)
```

The ^ symbol is the XOR operator, not to be confused with the mathematical exponent operator. To get the exponent *n* of a base number *b*, use

```
Math.pow(b,n);
```

If you insist on "extracting" the value of *e* before using it, use this:

```
var e = Math.exp(1);
var y = Math.pow(e,x); // = e^x
```