Created
April 1, 2019 13:01
-
-
Save yoya/1f8f54416abb0f30095202b9134ec9ae to your computer and use it in GitHub Desktop.
sigmoid equation compare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <cfloat> | |
static float sigmoid1(float x) { | |
return 1.0 / (1.0 + exp(-x)); | |
} | |
static float sigmoid2(float x) { | |
return exp(x) / (1.0 + exp(x)); | |
} | |
int main(void) { | |
float x, xarr[] = {FLT_MAX, 1000, 710, 709, 100, 89, 88, 10, 0, -10, -88, -89, -100, -709, -710, -1000, -FLT_MAX}; | |
for (int i = 0 ; i < sizeof(xarr)/sizeof(xarr[0]) ; i++) { | |
x = xarr[i]; | |
std::cerr << "| " << x << " | "; | |
std::cerr << exp(-x) << " | " << sigmoid1(x) << " | "; | |
std::cerr << exp(x) << " | " << sigmoid2(x) << " |" << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment