示例#1
0
 /**
  * Mutates the lower real value.
  *
  * @param lowerValue is the current lower value of this classifier position
  * @param upperValue is the current upper value of this classifier position.
  * @param currentState is the current State of the environment for this allele of the classifier.
  * @return a double with the mutated value
  */
 public double mutateLower(double lowerValue, double upperValue, double currentState) {
   double des = 0.0;
   if (Config.rand() < Config.pM) {
     des = (Config.rand() - 0.5) * 2 * Config.m_0; // We obtain a number between -1 and 1.
     lowerValue += des;
   }
   if (lowerValue <= currentState || currentState == -1.) {
     return lowerValue;
   }
   return currentState;
 } // end mutateLower
示例#2
0
 /**
  * Mutates the action of the classifier. return a boolean indicating if the action has been
  * mutated.
  */
 public boolean mutateAction() {
   int act = 0;
   if (Config.rand() < Config.pM) {
     do {
       act = (int) (Config.rand() * (double) Config.numberOfActions);
     } while (action == act);
     action = act;
     return true;
   }
   return false;
 } // end mutateAction
示例#3
0
 /**
  * It crosses a real allele within two parents. If the representation is a ternary representation,
  * a crossover within intervals is not possible because there is only one gene in each position.
  * So, in this case, the gene of the second parent will be copied. In case of being a real
  * representation, a random number is generated to decide where to cross the interval. It it is
  * crossed within the interval, the crossAllele method will make it.
  *
  * @param i is the allele that has to be crossed.
  * @param parent1 is the attribute object of the first parent.
  * @param parent2 is the attribute object of the second parent.
  */
 public void crossAllele(int i, Representation parent1, Representation parent2) {
   if (Config.ternaryRep) {
     rep[i].setAllele(parent2.rep[i]);
   } else {
     if (Config.typeOfAttributes[i].equals("character")) {
       rep[i].setAllele(parent2.rep[i]);
     } else {
       if (Config.rand() < 0.5) rep[i].setAllele(parent2.rep[i]);
       else { // The alleles has to be crossed
         rep[i].setAllele(parent1.rep[i].getLowerAllele(), parent2.rep[i].getUpperAllele());
         rep[i].verifyInterval();
       }
     }
   }
 }
示例#4
0
  /**
   * It creates a new representation with the specified condition and a random action.
   *
   * @param envState is the environtment state.
   */
  public Representation(double[] envState) {
    int i = 0;
    rep = new Attribute[Config.clLength];

    if (Config.ternaryRep) {
      for (i = 0; i < rep.length; i++) rep[i] = new TernaryRep(envState[i]);
    } else {
      for (i = 0; i < rep.length; i++) {
        if (Config.typeOfAttributes[i].equals("character")) rep[i] = new TernaryRep(envState[i]);
        else if (Config.typeOfAttributes[i].equals("integer"))
          rep[i] = new IntegerRep(envState[i], i);
        else rep[i] = new RealRep(envState[i]);
      }
    }
    action = (int) (Config.rand() * (double) Config.numberOfActions);
    if (action == Config.numberOfActions) action--;
  } // end Representation
示例#5
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