Skip to content

Instantly share code, notes, and snippets.

@Ruzzie
Created November 11, 2015 07:36
Show Gist options
  • Save Ruzzie/41c4ce3aa32ffae02270 to your computer and use it in GitHub Desktop.
Save Ruzzie/41c4ce3aa32ffae02270 to your computer and use it in GitHub Desktop.
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