Example #1
0
 public void playCard(CardType card) {
   // if (cards.contains(card)) {
   cards.removeFirstOccurrence(card);
   used.push(card);
   // } else {
   // throw new RuntimeException();
   // }
 }
  // 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;
  }
Example #3
0
  public static Tuple pivot(Tuple t, int l, int e) { // Tuple contains all values N B A b c v
    LinkedList<Integer> N = t.getN(); // Initialize N from the tuple
    LinkedList<Integer> B = t.getB(); // Initialize B from the tuple
    double[][] A = t.getA(); // Initialize A from the tuple
    double[] b = t.getb(); // Initialize b from the tuple
    double[] c = t.getc(); // Initialize c from the tuple
    double v = t.getv(); // Initialize v from the tuple

    double[] bhat = new double[b.length];
    double[] chat = new double[c.length];
    for (int i = 0; i < b.length; i++) {
      bhat[i] = 0;
    }
    for (int i = 0; i < c.length; i++) {
      chat[i] = 0;
    }

    System.out.println("Starting A:");
    for (int i = 0; i < A.length; i++) {
      for (int j = 0; j < A[0].length; j++) {
        System.out.print(A[i][j] + " ");
      }
      System.out.print("\n");
    }
    /*System.out.println("Start b:");
    for(int i=0; i<b.length;i++){
    	System.out.println(b[i]);
    }
    System.out.println("Start c:");
    for(int i=0; i<c.length;i++){
    	System.out.println(c[i]);
    }*/

    /*System.out.println("Ending N:");
    for(int i=0; i<N.size();i++){
    	System.out.println(N.get(i));
    }
    System.out.println("Ending B:");
    for(int i=0; i<B.size();i++){
    	System.out.println(B.get(i));
    }*/

    int dim = N.size() + B.size();
    double[][] Ahat = new double[dim][dim]; // initialize Ahat dim * dim matrix
    for (int i = 0; i < dim; i++) { // initialize all Ahat to be 0
      for (int j = 0; j < dim; j++) {
        Ahat[i][j] = 0;
      }
    }

    /*
     * Compute the coefficient of the equation for the new basic variable xe
     */

    bhat[e] = b[l] / A[l][e]; // Line 3 code

    for (int i = 0; i < dim; i++) {
      if (N.contains(i) && i != e) {
        // System.out.println("Iterating for j = "+i);
        Ahat[e][i] = A[l][i] / A[l][e];
      }
    }
    Ahat[e][l] = 1 / A[l][e];

    /*
     * Compute the coefficient of the equation for the remaining constants
     */

    for (int i = 0; i < dim; i++) {
      if (B.contains(i) && i != l) {
        System.out.println("2Iterating for i = " + i);
        bhat[i] = b[i] - A[i][e] * bhat[e];
        for (int j = 0; j < dim; j++) {
          if (N.contains(j) && j != e) Ahat[i][j] = A[i][j] - A[i][e] * Ahat[e][j];
          Ahat[i][l] = -A[i][e] * Ahat[e][l];
        }
      }
    }

    /*
     * Compute the objective function
     */

    v = v + c[e] * bhat[e]; // Line 14
    for (int j = 0; j < dim; j++) {
      if (N.contains(j) && j != e) {
        chat[j] = c[j] - c[e] * Ahat[e][j];
      }
    }
    chat[l] = -c[e] * Ahat[e][l];

    /*
     * Compute the new sets of basic and non-basic variables
     */

    N.removeFirstOccurrence(e);
    N.add(l);
    B.removeFirstOccurrence(l);
    B.add(e);

    /*
     * Print check
     */

    /*System.out.println("Ending A:");
    for(int i=0; i<Ahat.length;i++){
    	for(int j=0; j<Ahat[0].length;j++){
    		System.out.print(Ahat[i][j]+" ");
    	}
    	System.out.print("\n");
    }

    System.out.println("Ending N:");
    for(int i=0; i<N.size();i++){
    	System.out.println(N.get(i));
    }
    System.out.println("Ending B:");
    for(int i=0; i<B.size();i++){
    	System.out.println(B.get(i));
    }
    /*System.out.println("Ending b:");
    for(int i=0; i<b.length;i++){
    	System.out.println(bhat[i]);
    }
    System.out.println("Ending c:");
    for(int i=0; i<c.length;i++){
    	System.out.println(chat[i]);
    }*/

    System.out.println("Final value v: " + v);

    Tuple t2 = new Tuple(N, B, Ahat, bhat, chat, v);
    return t2;
  }