int n2 = 50;
double ncp1 = 0;
double ncp2 = 10;
double mu1 = Math.sqrt( ncp1 );
double mu2 = Math.sqrt( ncp2 );
DoubleVector a = Maths.rnorm( n1, mu1, 1, new Random() );
a = a.cat( Maths.rnorm(n2, mu2, 1, new Random()) );
DoubleVector aNormal = a;
a = a.square();
a.sort();
DoubleVector means = (new DoubleVector( n1, mu1 )).cat(new DoubleVector(n2, mu2));
System.out.println("==========================================================");
System.out.println("This is to test the estimation of the mixing\n" +
"distribution of the mixture of non-central Chi-square\n" +
"distributions. The example mixture used is of the form: \n\n" +
" 0.5 * Chi^2_1(ncp1) + 0.5 * Chi^2_1(ncp2)\n" );
System.out.println("It also tests the PACE estimators. Quadratic losses of the\n" +
"estimators are given, measuring their performance.");
System.out.println("==========================================================");
System.out.println( "ncp1 = " + ncp1 + " ncp2 = " + ncp2 +"\n" );
System.out.println( a.size() + " observations are: \n\n" + a );
System.out.println( "\nQuadratic loss of the raw data (i.e., the MLE) = " +
aNormal.sum2( means ) );
System.out.println("==========================================================");
// find the mixing distribution
ChisqMixture d = new ChisqMixture();
d.fit( a, NNMMethod );
System.out.println( "The estimated mixing distribution is\n" + d );
DoubleVector pred = d.pace2( a.rev() ).rev();
System.out.println( "\nThe PACE2 Estimate = \n" + pred );
System.out.println( "Quadratic loss = " +
pred.sqrt().times(aNormal.sign()).sum2( means ) );
pred = d.pace4( a );
System.out.println( "\nThe PACE4 Estimate = \n" + pred );
System.out.println( "Quadratic loss = " +
pred.sqrt().times(aNormal.sign()).sum2( means ) );
pred = d.pace6( a );
System.out.println( "\nThe PACE6 Estimate = \n" + pred );
System.out.println( "Quadratic loss = " +
pred.sqrt().times(aNormal.sign()).sum2( means ) );
}