简体   繁体   中英

Syntax of a SIgmoid Function - Javascript

I've been trying to make this function work to no avail. Could anyone potentially shed some light?

It is a Sigmoid with some applied boundaries/transormations. Here's the link to the function in desmos . That is working perfectly. It looks like this:

sigmoid 图像

And that's the formula:

功能

But when I tried to 'translate' that into my Javascript code, I can't get it to perform as intended. Here's what I tried:

y = m*((0.5/(1/(1+(Math.pow(Math.E,((-1)*d))))-0.5))*((1/((1+(Math.pow(Math.E, (((-1)*d)*(1/h)*x-1))))))-0.5))+0.5;

The function is not being bounded as expected and it should be passing through 0,0 like in the Desmos example... but it isn't, I know there are probably too many brackets in there and the solution will be glaringly obvious to someone with better understanding of this so? could you help me please?

Thank you!!

You accidentally put the last +0.5 outside the brackets.

Note: you do not need to use (-1)*d , as that is equal to -d .

Here is my improved version:

y = m*((0.5/(1/(1+(Math.pow(Math.E, -d)))-0.5))*((1/((1+(Math.pow(Math.E, -d*((1/h)*x-1))))))-0.5)+0.5);

I tried it with the variables specified on desmos :

m = 2;
d = 1;
h = 0.5;

// you wanted to check for this point
x = 0;

/* [The code above] */

I tested it for the values at 0, 1 and 42 and every time it works (not a scientific, but practical proof ^^)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM