Created
March 10, 2013 05:46
-
-
Save y-tag/5127284 to your computer and use it in GitHub Desktop.
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 <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