* Tests that the computation of sigmahat is correct.
*/
public static boolean test1() {
try {
int N = 1000;
MeanVariance mv = new MeanVariance();
Random rnd = new Random();
Belief b = new Belief(1);
for (int n = 0; n < N; n++) {
double data = rnd.nextGaussian();
b.Update(0, data);
mv.AddSample(data);
}
/*
* Now, SampleVarianceMSE(), which computes sigmahat^2, should be
* equal to sigmahat^2 as computed by Belief.
*/
double mv_val = mv.SampleVarianceMSE();
double b_val = b.sigmahat2(0);
int ulps = MathPF.FloatCmp(mv_val, b_val);
boolean ok = ulps < 30;
System.out.printf("test1: diff/ulp=%d (true)variance=1 "
+ "MeanVariance.sigmahat=%.3f belief.sigmahat=%.3f\n",
ulps, mv.SampleVarianceMSE(), b.sigmahat2(0));
if (ok)
System.out.println("test1: OK");
else
System.out.println("test1: FAILED");
return ok;