Exemple #1
0
  /**
   * evaluates an entire population. Population members are looked up in a hash table and if they
   * are not found then they are evaluated using ASEvaluator.
   *
   * @param ASEvaluator the subset evaluator to use for evaluating population members
   * @throws Exception if something goes wrong during evaluation
   */
  private void evaluatePopulation(SubsetEvaluator ASEvaluator) throws Exception {
    int i;
    double merit;

    for (i = 0; i < m_popSize; i++) {
      // if its not in the lookup table then evaluate and insert
      if (m_lookupTable.containsKey(m_population[i].getChromosome()) == false) {
        merit = ASEvaluator.evaluateSubset(m_population[i].getChromosome());
        m_population[i].setObjective(merit);
        m_lookupTable.put(m_population[i].getChromosome(), m_population[i]);
      } else {
        GABitSet temp = m_lookupTable.get(m_population[i].getChromosome());
        m_population[i].setObjective(temp.getObjective());
      }
    }
  }
Exemple #2
0
  /**
   * checks to see if any population members in the current population are better than the best
   * found so far. Also checks to see if the search has converged---that is there is no difference
   * in fitness between the best and worse population member
   *
   * @return true is the search has converged
   * @throws Exception if something goes wrong
   */
  private boolean checkBest() throws Exception {
    int i, count, lowestCount = m_numAttribs;
    double b = -Double.MAX_VALUE;
    GABitSet localbest = null;
    BitSet temp;
    boolean converged = false;
    int oldcount = Integer.MAX_VALUE;

    if (m_maxFitness - m_minFitness > 0) {
      // find the best in this population
      for (i = 0; i < m_popSize; i++) {
        if (m_population[i].getObjective() > b) {
          b = m_population[i].getObjective();
          localbest = m_population[i];
          oldcount = countFeatures(localbest.getChromosome());
        } else if (Utils.eq(m_population[i].getObjective(), b)) {
          // see if it contains fewer features
          count = countFeatures(m_population[i].getChromosome());
          if (count < oldcount) {
            b = m_population[i].getObjective();
            localbest = m_population[i];
            oldcount = count;
          }
        }
      }
    } else {
      // look for the smallest subset
      for (i = 0; i < m_popSize; i++) {
        temp = m_population[i].getChromosome();
        count = countFeatures(temp);
        ;

        if (count < lowestCount) {
          lowestCount = count;
          localbest = m_population[i];
          b = localbest.getObjective();
        }
      }
      converged = true;
    }

    // count the number of features in localbest
    count = 0;
    temp = localbest.getChromosome();
    count = countFeatures(temp);

    // compare to the best found so far
    if (m_best == null) {
      m_best = (GABitSet) localbest.clone();
      m_bestFeatureCount = count;
    } else if (b > m_best.getObjective()) {
      m_best = (GABitSet) localbest.clone();
      m_bestFeatureCount = count;
    } else if (Utils.eq(m_best.getObjective(), b)) {
      // see if the localbest has fewer features than the best so far
      if (count < m_bestFeatureCount) {
        m_best = (GABitSet) localbest.clone();
        m_bestFeatureCount = count;
      }
    }
    return converged;
  }