public void TestMeanAndVariacneConsistency() { const int numSamples = 100000; double mean, stdev; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Uniform uniform = new Uniform(); rs.Clear(); var a = Convert.ToDouble(uniform.UpperBound); var b = Convert.ToDouble(uniform.LowerBound); mean = (a + b) / 2; stdev = Math.Sqrt(0.25); for (int i = 0; i < numSamples; ++i) { rs.Push(uniform.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("uniform", mean, stdev * stdev, rs.Mean(), rs.Variance()); Assert.IsTrue(Math.Abs(mean - rs.Mean()) < 0.1); Assert.IsTrue(Math.Abs(stdev * stdev - rs.Variance()) < 0.1); }
public void TestMeanAndVariacneConsistency_Mean() { const int numSamples = 100000; double mean, variance; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Beta beta = new Beta(); rs.Clear(); //double a = 2, b = 70; //mean = a / (a + b); //variance = mean * (1 - mean) / (a + b + 1); mean = 0.1; variance = 0.1 * 0.1; for (int i = 0; i < numSamples; ++i) { beta.Mean = mean; beta.StandardDeviation = Math.Sqrt(variance); rs.Push(beta.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("Beta", mean, variance, rs.Mean(), rs.Variance()); }
public void TestMeanAndVariacneConsistency() { const int numSamples = 100000; double mean, stdev; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Uniform uniform = new Uniform(); rs.Clear(); var a = uniform.UpperBound; var b = uniform.LowerBound; mean = (a + b) / 2; stdev = Math.Sqrt((b - a) * (b - a) / 12); for (int i = 0; i < numSamples; ++i) { rs.Push(uniform.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("uniform", mean, stdev * stdev, rs.Mean(), rs.Variance()); }
public void TestMeanAndVariacneConsistency() { List <int> numList = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; const int numSamples = 100000; double mean, stdev; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Uniform <int> uniform = new Uniform <int>(); uniform.Candidates = numList; rs.Clear(); mean = 50; stdev = 0; for (int i = 0; i < numSamples; ++i) { rs.Push(uniform.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("uniform categorical", mean, stdev * stdev, rs.Mean(), rs.Variance()); }
public void TestMeanAndVariacneConsistency() { const int numSamples = 100000; double mean, stdev; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Triangular tri = new Triangular(); rs.Clear(); var a = tri.LowerBound; var b = tri.UpperBound; var c = tri.Mode; mean = (a + b + c) / 3; stdev = Math.Sqrt((a * a + b * b + c * c - a * b - a * c - b * c) / 18); for (int i = 0; i < numSamples; ++i) { rs.Push(tri.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("Triangular", mean, stdev * stdev, rs.Mean(), rs.Variance()); }
public void TestMeanAndVariacneConsistency_MuSigma() { const int numSamples = 100000; double mean, stdev; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); LogNormal logNormal = new LogNormal(); rs.Clear(); mean = 2; stdev = 5; var muTemp = Math.Log(mean) - 0.5 * Math.Log(1 + stdev * stdev / mean / mean); var sigmaTemp = Math.Sqrt(Math.Log(1 + stdev * stdev / mean / mean)); for (int i = 0; i < numSamples; ++i) { logNormal.Mu = muTemp; logNormal.Sigma = sigmaTemp; rs.Push(logNormal.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("logNormal", mean, stdev * stdev, rs.Mean(), rs.Variance()); }
public void TestMeanAndVariacneConsistency() { const int numSamples = 100000; double mean, stdev; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); LogNormal logNormal = new LogNormal(); rs.Clear(); mean = 2; stdev = 5; for (int i = 0; i < numSamples; ++i) { logNormal.Mean = mean; logNormal.StandardDeviation = stdev; rs.Push(logNormal.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("logNormal", mean, stdev * stdev, rs.Mean(), rs.Variance()); }
public void TestMeanAndVariacneConsistency_Shape() { const int numSamples = 100000; double mean, stdev; double alpha, beta; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Gamma gamma = new Gamma(); rs.Clear(); alpha = 4; beta = 4; mean = alpha / beta; stdev = Math.Sqrt(alpha / beta / beta); for (int i = 0; i < numSamples; ++i) { gamma.Mean = mean; gamma.StandardDeviation = stdev; rs.Push(gamma.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("gamma", mean, stdev * stdev, rs.Mean(), rs.Variance()); // TODO: result not consistent need to fix the bug }
public void TestMeanAndVariacneConsistency_CV() { const int numSamples = 100000; double mean, stdev, cv; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Normal normal = new Normal(); rs.Clear(); mean = 2; stdev = 5; cv = stdev / Math.Abs(mean); for (int i = 0; i < numSamples; ++i) { normal.Mean = mean; normal.CV = cv; rs.Push(normal.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("normal", mean, stdev * stdev, rs.Mean(), rs.Variance()); }
public double Slope() { double S_xx = x_stats.Variance() * (n - 1.0); return(S_xy / S_xx); }
public void TestMeanAndVariacneConsistency() { const int numSamples = 100000; double mean, stdev; RunningStat rs = new RunningStat(); Random defaultrs = new Random(); Poisson poisson = new Poisson(); rs.Clear(); mean = 2000; stdev = Math.Sqrt(2000); poisson.Lambda = 2000; for (int i = 0; i < numSamples; ++i) { rs.Push(poisson.Sample(defaultrs)); } PrintResult.CompareMeanAndVariance("Poisson Discrete", mean, stdev * stdev, rs.Mean(), rs.Variance()); }