Skip to content

Instantly share code, notes, and snippets.

@y-tag
Created March 10, 2013 05:46
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 y-tag/5127284 to your computer and use it in GitHub Desktop.
Save y-tag/5127284 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cmath>
double mixed_entropy(double e, double n) {
if (n == 0.0) {
return 0.0;
}
return log(n) - e / n;
}
int main(int argc, char** argv) {
double n = 3;
double e_d = 3 * log(3);
double e_e = - e_d / 3 + log(3);
double d = 0.0;
d = e_e;
fprintf(stdout, "d = %g\n", d);
d = (n == 0.0) ? 0.0 : (log(n) - e_d / n);
fprintf(stdout, "d = %g\n", d);
d = mixed_entropy(e_d, n);
fprintf(stdout, "d = %g\n", d);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment