public void TestInverseKS() { KolmogorovDistribution d = new KolmogorovDistribution(); double x; Stopwatch s = Stopwatch.StartNew(); for (double Q = 0.00001; Q <= 0.5; Q += 0.00001) { x = InverseQ(Q); } s.Stop(); Console.WriteLine(s.ElapsedMilliseconds); s.Restart(); for (double Q = 0.00001; Q <= 0.5; Q += 0.00001) { x = d.InverseRightProbability(Q); } s.Stop(); Console.WriteLine(s.ElapsedMilliseconds); Console.WriteLine(InverseQ(0.5)); Console.WriteLine(d.InverseRightProbability(0.5)); }
public void SampleComparisonTest() { // create one set of samples from our distributions Sample[] aSamples = new Sample[distributions.Length]; for (int i = 0; i < distributions.Length; i++) { aSamples[i] = CreateSample(distributions[i], 40, 1); } // create another set Sample[] bSamples = new Sample[distributions.Length]; for (int i = 0; i < distributions.Length; i++) { bSamples[i] = CreateSample(distributions[i], 80, 2); } KolmogorovDistribution kd = new KolmogorovDistribution(); Console.WriteLine("P={0} => D={1}", 0.50, kd.InverseLeftProbability(0.50)); Console.WriteLine("P={0} => D={1}", 0.90, kd.InverseLeftProbability(0.90)); Console.WriteLine("P={0} => D={1}", 0.95, kd.InverseLeftProbability(0.95)); Console.WriteLine("P={0} => D={1}", 0.99, kd.InverseLeftProbability(0.99)); // cross-test using KS; like samples should agree and unlike samples should be distinguished for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { //aSamples[0] = new Sample(new double[] { 10, 19, 15, 20, 12, 8, 15, 21 }); //bSamples[0] = new Sample(new double[] { 15, 22, 17, 9, 12, 10, 29, 11, 25, 31 }); //foreach (double datum in aSamples[i]) Console.WriteLine("a={0}", datum); //foreach (double datum in bSamples[j]) Console.WriteLine("b={0}", datum); TestResult result = Sample.KolmogorovSmirnovTest(aSamples[i], bSamples[j]); Console.WriteLine("{0} v. {1}: D={2} P={3}", i, j, result.Statistic, result.LeftProbability); if (i == j) { Assert.IsTrue(result.LeftProbability < 0.90); } else { Assert.IsTrue(result.LeftProbability > 0.90); } // the order shouldn't matter TestResult reverse = Sample.KolmogorovSmirnovTest(bSamples[j], aSamples[i]); Assert.IsTrue(reverse.Statistic == result.Statistic); Assert.IsTrue(reverse.RightProbability == result.RightProbability); } } }