Skip to content

Instantly share code, notes, and snippets.

@yoya
Created April 1, 2019 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoya/1f8f54416abb0f30095202b9134ec9ae to your computer and use it in GitHub Desktop.
Save yoya/1f8f54416abb0f30095202b9134ec9ae to your computer and use it in GitHub Desktop.
sigmoid equation compare
#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