Ejemplo n.º 1
0
  @Before
  public void setUp() throws Exception {
    List<SubproblemParameter> parameters = new LinkedList<SubproblemParameter>();
    SubproblemParameter subproblemParameter1 = new SubproblemParameter();
    // TODO Object or generics?
    subproblemParameter1.setParametertType(Integer.class);
    subproblemParameter1.setDefaultValue("10000");
    subproblemParameter1.setMinValue("1");
    subproblemParameter1.setMaxValue("10000");
    subproblemParameter1.setXenteredValue("10000");

    parameters.add(0, subproblemParameter1);

    treeDepth = new TreeDepth(parameters);
  }
  // private IOObject getValidations( WhiBoCentroidClusterModel
  // centroidClusterModel, ExampleSet exampleSet) {
  private IOObject getValidations(ClusterModel centroidClusterModel, ExampleSet exampleSet) {

    CentroidClusterModel centroidClusterModelRapid = null;
    WhiBoCentroidClusterModel centroidClusterModelWhiBo = null;

    if (centroidClusterModel.getClass().equals(CentroidClusterModel.class)) {

      centroidClusterModelRapid = (CentroidClusterModel) centroidClusterModel;
    } else {

      centroidClusterModelWhiBo = (WhiBoCentroidClusterModel) centroidClusterModel;
    }

    // Gets distance measure from the component repository on the basis of
    // selected parameter
    String className = getParameterType("Distance_Measure").toString(0);
    rs.fon.whibo.GC.component.DistanceMeasure.DistanceMeasure distance = null;
    Constructor c = null;
    try {
      c = Class.forName(className).getConstructor(new Class[] {List.class});

      distance =
          (rs.fon.whibo.GC.component.DistanceMeasure.DistanceMeasure)
              c.newInstance(new Object[] {new LinkedList<SubproblemParameter>()});
    } catch (Exception e) {
    }

    Evaluation e = null;
    double evaluation = 0;
    MyPerformanceCriterion mpc = new MyPerformanceCriterion();

    LinkedList<SubproblemParameter> ll = new LinkedList<SubproblemParameter>();
    // Instantiates sub-problem parameter class for validation measures that
    // need parameters
    SubproblemParameter sp = new SubproblemParameter();
    sp.setParametertType(Integer.class);
    sp.setMinValue("1");
    sp.setMaxValue("1000");

    // Gets and executes evaluation components from the component repository
    // on the basis of selected parameter
    if (getParameterAsBoolean("Intra_Cluster_Distance")) {
      e = new IntraClusterDistance(ll);
      if (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
        evaluation = e.Evaluate(distance, centroidClusterModelRapid, exampleSet);
      else evaluation = e.Evaluate(distance, centroidClusterModelWhiBo, exampleSet);

      mpc.addPerformance("Intra_Cluster_Distance", evaluation);
    }
    if (getParameterAsBoolean("Connectivity")) {

      try {
        sp.setXenteredValue(getParameter("NN_Connectivity").toString());
      } catch (UndefinedParameterError e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      } catch (IllegalArgumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

      ll.add(sp);
      e = new Connectivity(ll);
      if (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
        evaluation = e.Evaluate(distance, centroidClusterModelRapid, exampleSet);
      else evaluation = e.Evaluate(distance, centroidClusterModelWhiBo, exampleSet);
      mpc.addPerformance("Connectivity", evaluation);
    }
    if (getParameterAsBoolean("Global_Silhouette_Index")) {
      e = new GlobalSilhouetteIndex(ll);
      if (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
        evaluation = e.Evaluate(distance, centroidClusterModelRapid, exampleSet);
      else evaluation = e.Evaluate(distance, centroidClusterModelWhiBo, exampleSet);
      mpc.addPerformance("Global_Silhouette_Index", evaluation);
    }
    if (getParameterAsBoolean("XB_Index")) {
      e = new XBIndex(ll);
      if (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
        evaluation = e.Evaluate(distance, centroidClusterModelRapid, exampleSet);
      else evaluation = e.Evaluate(distance, centroidClusterModelWhiBo, exampleSet);
      mpc.addPerformance("XB_Index", evaluation);
    }
    if (getParameterAsBoolean("Min_Max_Cut")) {
      e = new MInMaxCut(ll);
      if (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
        evaluation = e.Evaluate(distance, centroidClusterModelRapid, exampleSet);
      else evaluation = e.Evaluate(distance, centroidClusterModelWhiBo, exampleSet);
      mpc.addPerformance("Min_Max_Cut", evaluation);
    }
    if (getParameterAsBoolean("Symmetry")) {
      try {
        sp.setXenteredValue(getParameter("NN_Symmetry").toString());
      } catch (UndefinedParameterError e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      } catch (IllegalArgumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      ll.removeFirstOccurrence(sp);
      ll.add(sp);
      // e=new Symmetry(ll);
      // if
      // (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
      // evaluation = e.Evaluate(distance, centroidClusterModelRapid,
      // exampleSet);
      // else
      // evaluation = e.Evaluate(distance, centroidClusterModelWhiBo,
      // exampleSet);
      // mpc.addPerformance("Symmetry", evaluation);
      // }
      // if(getParameterAsBoolean("BIC")){
      // e=new BIC(ll);
      // if
      // (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
      // evaluation = e.Evaluate(distance, centroidClusterModelRapid,
      // exampleSet);
      // else
      // evaluation = e.Evaluate(distance, centroidClusterModelWhiBo,
      // exampleSet);
      // mpc.addPerformance("BIC", evaluation);
    }

    if (getParameterAsBoolean("Fowlkes_Mallows_Index")) {
      e = new FowlkesMallowsIndex(ll);
      if (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
        evaluation = e.Evaluate(distance, centroidClusterModelRapid, exampleSet);
      else evaluation = e.Evaluate(distance, centroidClusterModelWhiBo, exampleSet);

      mpc.addPerformance("Fowlkes_Mallows_Index", evaluation);
    }
    if (getParameterAsBoolean("Jaccard_Index")) {
      e = new JaccardIndex(ll);
      if (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
        evaluation = e.Evaluate(distance, centroidClusterModelRapid, exampleSet);
      else evaluation = e.Evaluate(distance, centroidClusterModelWhiBo, exampleSet);

      mpc.addPerformance("Jaccard_Index", evaluation);
    }
    if (getParameterAsBoolean("Rand_Index")) {
      e = new RandIndex(ll);

      evaluation = e.Evaluate(distance, centroidClusterModel, exampleSet);

      mpc.addPerformance("Rand_Index", evaluation);
    }
    if (getParameterAsBoolean("Adjusted_Rand_Index")) {
      e = new AdjustedRandIndex(ll);
      if (centroidClusterModel.getClass().equals(CentroidClusterModel.class))
        evaluation = e.Evaluate(distance, centroidClusterModelRapid, exampleSet);
      else evaluation = e.Evaluate(distance, centroidClusterModelWhiBo, exampleSet);

      mpc.addPerformance("Adjusted_Rand_Index", evaluation);
    }

    return mpc;
  }