public static void main(String args[]) {
int n1 = 50;
int n2 = 50;
double mu1 = 0;
double mu2 = 5;
DoubleVector a = Maths.rnorm( n1, mu1, 1, new Random() );
a = a.cat( Maths.rnorm( n2, mu2, 1, new Random() ) );
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 unit variance normal\n" +
"distributions. The example mixture used is of the form: \n\n" +
" 0.5 * N(mu1, 1) + 0.5 * N(mu2, 1)\n" );
System.out.println("It also tests three estimators: the subset\n" +
"selector, the nested model selector, and the empirical Bayes\n" +
"estimator. Quadratic losses of the estimators are given, \n" +
"and are taken as the measure of their performance.");
System.out.println("==========================================================");
System.out.println( "mu1 = " + mu1 + " mu2 = " + mu2 +"\n" );
System.out.println( a.size() + " observations are: \n\n" + a );
System.out.println( "\nQuadratic loss of the raw data (i.e., the MLE) = " +
a.sum2( means ) );
System.out.println("==========================================================");
// find the mixing distribution
NormalMixture d = new NormalMixture();
d.fit( a, NNMMethod );
System.out.println( "The estimated mixing distribution is:\n" + d );
DoubleVector pred = d.nestedEstimate( a.rev() ).rev();
System.out.println( "\nThe Nested Estimate = \n" + pred );
System.out.println( "Quadratic loss = " + pred.sum2( means ) );
pred = d.subsetEstimate( a );
System.out.println( "\nThe Subset Estimate = \n" + pred );
System.out.println( "Quadratic loss = " + pred.sum2( means ) );
pred = d.empiricalBayesEstimate( a );
System.out.println( "\nThe Empirical Bayes Estimate = \n" + pred );
System.out.println( "Quadratic loss = " + pred.sum2( means ) );
}