PercentileSelection.java [src/java/m/ann/selection/mechanism] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package m.ann.selection.mechanism;

import java.util.ArrayList;
import java.util.List;
import m.ann.selection.Selected;
import org.apache.commons.math3.stat.descriptive.rank.Percentile;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.encog.neural.neat.NEATNetwork;
import utils.MongoAccess;

/**
 *
 * @author sidereus
 */
public class PercentileSelection extends SelectionMechanism {

  public PercentileSelection(String varName, String errorName, double threshold, String ann) {
    super(varName, errorName, threshold, ann);
  }

  @Override
  public Selected select() {
    double tError = getThresholdError();
    List<ObjectId> id = new ArrayList<>();
    List<NEATNetwork> nn = new ArrayList<>();

    for (Document dd : D) {
      if (errorOutOfBounds(dd, tError)) {
        break;
      }
      addIdNN(dd, id, nn);
    }
    return new Selected(id, nn, tError);
  }

  private double getThresholdError() {
    double[] errors = MongoAccess.retrieveANNsErrors(ANN, VAR_NAME, ERROR_NAME);
    Percentile p = new Percentile();
    return p.evaluate(errors, THRESHOLD);
  }

}