public void testIncrementalStatistics() { // Testing incremental statistics MersenneTwisterUniformRng mt = new MersenneTwisterUniformRng(42); IncrementalStatistics stat = new IncrementalStatistics(); for (int i = 0; i < 500000; ++i) { double x = 2.0 * (mt.nextReal() - 0.5) * 1234.0; double w = mt.nextReal(); stat.add(x, w); } if (stat.samples() != 500000) { QAssert.Fail("stat.samples() (" + stat.samples() + ") can not be reproduced against cached result (" + 500000 + ")"); } TEST_INC_STAT(stat.weightSum(), 2.5003623600676749e+05); TEST_INC_STAT(stat.mean(), 4.9122325964293845e-01); TEST_INC_STAT(stat.variance(), 5.0706503959683329e+05); TEST_INC_STAT(stat.standardDeviation(), 7.1208499464378076e+02); TEST_INC_STAT(stat.errorEstimate(), 1.0070402569876076e+00); TEST_INC_STAT(stat.skewness(), -1.7360169326720038e-03); TEST_INC_STAT(stat.kurtosis(), -1.1990742562085395e+00); TEST_INC_STAT(stat.min(), -1.2339945045639761e+03); TEST_INC_STAT(stat.max(), 1.2339958308008499e+03); TEST_INC_STAT(stat.downsideVariance(), 5.0786776146975247e+05); TEST_INC_STAT(stat.downsideDeviation(), 7.1264841364431061e+02); // This is a test for numerical stability, actual implementation fails //InverseCumulativeRng<MersenneTwisterUniformRng,InverseCumulativeNormal> normal_gen = // new InverseCumulativeRng<MersenneTwisterUniformRng, InverseCumulativeNormal>(mt); //IncrementalStatistics stat2 = new IncrementalStatistics(); //for (int i = 0; i < 500000; ++i) //{ // double x = normal_gen.next().value * 1E-1 + 1E8; // double w = 1.0; // stat2.add(x, w); //} //double tol = 1E-5; //if(Math.Abs( stat2.variance() - 1E-2 ) > tol) // QAssert.Fail("variance (" + stat2.variance() + ") out of expected range " + 1E-2 + " +- " + tol); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(IncrementalStatistics obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(IncrementalStatistics obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }