Created
November 11, 2015 07:36
-
-
Save Ruzzie/41c4ce3aa32ffae02270 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
public static class Statistics | |
{ | |
public static double StreamAverage(double previousAverage, double currentNumber, double currentCount) | |
{ | |
return ((previousAverage*currentCount) + currentNumber)/(currentCount + 1); | |
} | |
public static double Entropy<T>(this IDictionary<T, int> histogram, int dataSize) | |
{ | |
double entropy = 0; | |
foreach (KeyValuePair<T, int> numberCount in histogram) | |
{ | |
double probability = (double)numberCount.Value / dataSize; | |
entropy += probability * Math.Log(1 / probability, 2); | |
} | |
return entropy; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment