Beispiel #1
0
  /**
   * Method to test this class
   *
   * @param args the commandline arguments
   */
  public static void main(String args[]) {

    int n1 = 50;
    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));
  }
  /**
   * Method to test this class
   *
   * @param args the commandline arguments - ignored
   */
  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));
  }