Implementing Sigmoid Curves in C++

2019-09-01 14:17发布

问题:

I've been trying to implement Sigmoid curves since 12 hours ago and i could not manage to get it up.

I'm using Microsoft Visual Studio 2010.

The formula is y = 1/(1+exp(-e))

Yet when i try implementing in the codes it does not work, why? Can any experts please guide me along, thank you.

for(int y=0; y<bih.biHeight; y++)
{
for(int x=0; x<bih.biWidth; x++)
{   
SetPixel(hdc, (double)1/((double)1+exp(double(-x))), bih.biHeight-x, red);
}
}

回答1:

Your result for the (double)1/((double)1+exp(double(-x))) expression is between 0 and 1. You can't draw "subpixels" can you?

So to fix it, you need to multiply the result of the function by a value that will make it go through a visible range. For example:

(double)1/((double)1+exp(double(-x))) * bih.biHeight