Example #1
0
  /**
   * Inserts the classifier into the population. Before, it looks if there is a classifier in the
   * population that can subsume the new one (in this case, increments its numerosity). After, it
   * checks that the number of micro classifiers is less than the maximum population size. If it
   * isn't, it deletes one classifier of the population calling the deleteClassifier function. It
   * inserts the classifier in the population and in the action set if it's not null.
   *
   * @param cl is the classifier that has to be inserted in the population.
   * @param ASet Population where the classifier will be inserted.
   */
  public void insertInPSubsumingCl(Classifier cl, Population ASet) {
    int i = 0;
    Classifier bestSubsumer = null;
    Classifier equalClassifier = null;

    // We look for the best subsumer or for an equal classifier.
    while (i < macroClSum) {
      if (set[i].couldSubsume() && set[i].isMoreGeneral(cl)) {
        if (bestSubsumer == null) bestSubsumer = set[i];
        else if (set[i].isMoreGeneral(bestSubsumer)) bestSubsumer = set[i];
      }
      if (set[i].equals(cl)) equalClassifier = set[i];
      i++;
    }

    // If there is a subsumer, its numerosity is increased.
    if (bestSubsumer != null) {
      bestSubsumer.increaseNumerosity(cl.getNumerosity());
      microClSum += cl.getNumerosity();
    } else if (equalClassifier != null) {
      equalClassifier.increaseNumerosity(cl.getNumerosity());
      microClSum += cl.getNumerosity();
    } else {
      addClassifier(cl);
    }
    // There's no classifier deletion, independent of if the maximum size
    // has been overcomen
  } // end insertInPSubsumingCl
Example #2
0
  /** This method applies the action set subsumption */
  public void doActionSetSubsumption() {
    int i, pos = 0;
    Classifier cl = null;

    for (i = 0; i < macroClSum; i++) {
      if (set[i].couldSubsume()) {
        if (cl == null
            || set[i].numberOfDontCareSymbols() > cl.numberOfDontCareSymbols()
            || (set[i].numberOfDontCareSymbols() == cl.numberOfDontCareSymbols()
                && Config.rand() < 0.5)) {
          cl = set[i];
          pos = i;
        }
      }
    }
    if (cl != null) {
      for (i = 0; i < macroClSum; i++) {
        if (cl != set[i] && cl.isMoreGeneral(set[i])) {
          cl.increaseNumerosity(set[i].getNumerosity());
          // Now, the classifier has to be removed from the actionSet and the population.
          // It's deleted from the action set.
          Classifier clDeleted = set[i];
          deleteClassifier(i);

          // And now, it's deleted from the population
          Population p = parentRef;
          while (p.parentRef != null) {
            p = p.parentRef;
          }

          pos =
              p.isThereClassifier(
                  clDeleted); // The classifier is searched in the initial population.

          if (pos >= 0) p.deleteClassifier(pos);
        }
      }
    }
  } // end doActionSetSubsumption