Пример #1
0
  /**
   * Inserts the classifier in the population. Before that, it looks if there is a classifier in the
   * population with the same action and condition (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 from 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 insertInPopulation(Classifier cl, Population ASet) {
    boolean found = false;
    int i = 0;

    while (i < macroClSum && !found) {
      if (set[i].equals(cl)) {
        set[i].increaseNumerosity(cl.getNumerosity());
        microClSum += cl.getNumerosity();
        if (ASet != null) {
          if (ASet.isThereClassifier(set[i]) >= 0) ASet.microClSum += cl.getNumerosity();
        }
        found = true;
      }
      i++;
    }
    if (!found) {
      addClassifier(cl);
    }

    // Here, the classifier has been added to the population
    if (microClSum
        > Config.popSize) { // If we have inserted to many classifiers, we have to delete one.
      deleteClFromPopulation(ASet);
    }
  } // end insertInPopulation
Пример #2
0
  /** It's the new reduction algorithm. (Experimental phase) */
  private void reductInTrain() {
    double averageUseful = 0.0, stdUseful = 0.0;
    int i = 0;
    int numSum = 0;
    // A reference to the population is gotten.
    Population pop = this.getParentRef().getParentRef();

    while (i < macroClSum) {
      if (!set[i].couldComp()) {
        numSum += set[i].getNumerosity();
        set[i].setNumerosity(0);
        // The classifier is removed from the [A]
        set[i] = set[macroClSum - 1];
        macroClSum--;
        /////
        numAplicacions++;
      } else {
        averageUseful += set[i].getUsefulTimes();
        stdUseful += (set[i].getUsefulTimes() * set[i].getUsefulTimes());
        i++;
      }
    }

    if (macroClSum > 0) {
      if (macroClSum > 1)
        stdUseful =
            Math.sqrt(
                (stdUseful - ((averageUseful * averageUseful) / macroClSum)) / (macroClSum - 1));
      averageUseful = averageUseful / (double) macroClSum;

      // With the "thres" parameter you can control the compactation pressure (add or substract the
      // stdUseful)
      int thres = (int) (averageUseful - stdUseful);
      i = 0;
      averageUseful = 0;
      while (i < macroClSum) {
        if (set[i].getUsefulTimes() < thres && set[i].getPrediction() > Config.Preduct) {
          numSum += set[i].getNumerosity();
          set[i].setNumerosity(0);
          set[i] = set[macroClSum - 1];
          macroClSum--;
          /////
          numAplicacions++;
        } else {
          // We add the contribuion of each classifier to distribute the numerosity at the end
          averageUseful += set[i].getUsefulTimes();
          i++;
        }
      }

      // The numerosity of classifiers deleted are set to other classifiers in the population.
      int addNum = 0;
      int discount = 0;
      for (i = 0; i < macroClSum - 1; i++) {
        addNum = (int) (((double) set[i].getUsefulTimes() / averageUseful) * (double) numSum);
        set[i].increaseNumerosity(addNum);
        discount += addNum;
      }

      if (macroClSum > 0) set[macroClSum - 1].increaseNumerosity(numSum - discount);

    } else {
      microClSum -= numSum;
      pop.microClSum -= numSum;
    }

    pop.deleteClWithZeroNum();
  }