Beispiel #1
0
  /**
   * Deletes a classifier from this population. It chooses the classifier to be deleted.
   *
   * @return the deleted classifier.
   */
  public Classifier deleteClassifier() {
    double avFitness = 0;
    int i = 0;
    for (i = 0; i < macroClSum; i++) {
      avFitness += set[i].getFitness();
    }
    avFitness /= (double) microClSum;

    double voteSum = 0;
    Roulette rul = new Roulette(macroClSum);

    for (i = 0; i < macroClSum; i++) {
      rul.add(set[i].deletionVote(avFitness));
    }

    i = rul.selectRoulette();

    // Now we have to remove the selected classifier.
    microClSum--;
    set[i].increaseNumerosity(-1);
    Classifier deleted = set[i];
    if (set[i].getNumerosity() == 0) {
      macroClSum--;
      set[i] = set[macroClSum];
      set[macroClSum] = null;
    }

    return deleted;
  } // end deleteClassifier
Beispiel #2
0
  public static void main(String[] args) {
    int i;
    int win = 0, N = 0;

    Roulette x = new Roulette();

    System.out.println("Test3: value method in class Roulette\n");

    N = 1000;
    for (i = 1; i <= N; i++) {
      x.spin();
      System.out.print("Bet on 13, spin = " + x.value() + " ");

      if ("13".equals(x.value())) {
        win++;
        System.out.println("WIN");
      } else System.out.println("lose");
    }

    System.out.println();
    System.out.println("Total spins = " + N + "  Total wins = " + win);
    System.out.println("*** Should be approximately equal to " + N / 38);
    System.out.println();
  }