protected void CountProbs(decimal mean, decimal variance, int N) { Array.Sort(Randvariables); Frequency = new Dictionary <decimal, int>(); int m = (int)Math.Log(N) + 1; decimal min = Randvariables.First(); decimal max = Randvariables.Last(); Interval = (max - min) / m; int k = 0; for (decimal i = min; i <= max; i += Interval) { var x = i; Frequency[x] = 0; while (k < Randvariables.Length && Randvariables[k] <= i + Interval / 2) { Frequency[x] += 1; k++; } } Probabilities = new Dictionary <decimal, decimal>(); for (decimal i = min; i <= max; i += Interval) { Probabilities[i] = (decimal)Frequency[i] / N; } }
public void TheoreticalProbs(decimal mean, decimal variance, int N) { var sigma = Math.Sqrt((double)variance); decimal min = Randvariables.First(); decimal max = Randvariables.Last(); TProbabilities = new Dictionary <decimal, decimal>(); for (decimal i = min; i <= max; i += 0.1M) { var y = 1 / (decimal)(sigma * Math.Sqrt(2 * Math.PI)) * (decimal)Math.Exp((double)(-(i - mean) * (i - mean) / (2 * variance))); TProbabilities.Add(i, y); } }