Example #1
0
  /**
   * Estimates the mean of array <code>y</code>. <code>robustMu</code> uses a Gaussian model to
   * remove outliers iteratively.
   *
   * @param y an array
   * @return the estimated mean of <code>y</code>
   */
  private double robustMu(double[] y) {

    ArrayList<Double> x = new ArrayList<Double>(y.length);

    for (int i = 0; i < y.length; i++) {
      x.add(y[i]);
    }

    double sigma = 0;
    NormalDist gaussian = new NormalDist();
    double cutoff = 0;
    double cutoff1 = 0;
    double cutoff2 = 0;

    int xSize = x.size();

    sigma = std(x);
    double areaRemoved = 0.5 / xSize;

    cutoff = abs(gaussian.inverseF(areaRemoved));

    cutoff1 = -cutoff * sigma + mean(x);
    cutoff2 = cutoff * sigma + mean(x);

    while (true) {

      Iterator<Double> iter = x.iterator();

      int numRemoved = 0;
      while (iter.hasNext()) {

        double cn = iter.next();
        if (cn < cutoff1 || cn > cutoff2) {
          numRemoved++;
          iter.remove();
        }
      }

      if (numRemoved == 0) {
        break;
      }

      sigma = std(x);
      sigma =
          sigma
              / sqrt(
                  (1 - 2 * areaRemoved - 2 * cutoff * exp(-pow(cutoff, 2) / 2) / sqrt(2 * PI))
                      / (1 - 2 * areaRemoved));

      xSize = x.size();
      areaRemoved = 0.5 / xSize;

      cutoff = abs(gaussian.inverseF(areaRemoved));

      cutoff1 = -cutoff * sigma + mean(x);
      cutoff2 = cutoff * sigma + mean(x);
    }

    return mean(x);
  }
  public FunctionalTest() throws IOException {
    Vector v = new Vector();
    for (Enumeration e = v.elements(); e.hasMoreElements(); ) {}
    IOException e = new IOException();

    // this is to test excluding literals
    String buz = "text/plain";

    // this is to test array handling
    ArrayList[] foo = new ArrayList[0];
    ArrayList bar = new ArrayList();
    bar.add(HashSet.class);
    bar.add(Integer.class);
    File[] files = (File[]) bar.toArray(new File[0]);

    // this is to test imports of inner classes
    HashMap biv = new HashMap();
    Set set = biv.entrySet();
    Iterator iter = set.iterator();
    bar.add((Entry) iter.next());

    // this is to test inclusion of classes from java.lang.reflect
    Modifier m = new Modifier();

    // This next one can't be picked up by importscrubber because the compiler inlines it
    // System.out.println("A JOptionPane thingy " + JOptionPane.CANCEL_OPTION);
    // bummer!

    // this is to test importing a class and only calling a static method on it
    // Buz.doSomething();

    // this is to test NOT importing classes which are fully qualified in the class body
    // java.sql.Date sqlDate = new java.sql.Date(20);
    // Date javaDate = new Date();

    throw new IllegalArgumentException();
  }