Ejemplo n.º 1
0
 /**
  * Initializes the CMA parameter set for given mu, lambda and a population. The initialSigma
  * parameter is used as initial sigma directly unless it is <0, in that case the average range is
  * used as initial sigma. The parameter instance is also added as listener to the population.
  *
  * @param params the CMA parameter set to be used - its data are overwritten
  * @param mu ES mu parameter
  * @param lambda ES lambda parameter
  * @param pop associated Population
  * @param initialSigma initial sigma or -1 to indicate the usage of average range
  * @return
  */
 public static CMAParamSet initCMAParams(
     CMAParamSet params, int mu, int lambda, Population pop, double initialSigma) {
   initCMAParams(
       params,
       mu,
       lambda,
       pop.getBestEAIndividual().getDoublePosition(),
       ((InterfaceDataTypeDouble) pop.getEAIndividual(0)).getDoubleRange(),
       initialSigma);
   pop.addPopulationChangedEventListener(params);
   return params;
 }
 public boolean isConverged(Population pop) {
   Vector<Double> bests = (Vector<Double>) pop.getEAIndividual(0).getData(NichePSO.fitArchiveKey);
   if (bests.size() < haltingWindow) {
     return false;
   } else {
     List<Double> lst = bests.subList(bests.size() - haltingWindow, bests.size());
     bests = new Vector<>(haltingWindow);
     bests.addAll(lst);
     for (int i = 1; i < pop.size(); i++) {
       for (int k = 0; k < haltingWindow; k++) {
         Vector<Double> fitArch =
             (Vector<Double>) pop.getEAIndividual(i).getData(NichePSO.fitArchiveKey);
         int archIndex =
             fitArch.size()
                 - haltingWindow
                 + k; // index within the fitness archive of the current particle, which may be
                      // larger than the bests list - the tail is important
         if (archIndex >= 0 && (fitArch.get(archIndex) < bests.get(k))) {
           bests.set(k, fitArch.get(archIndex));
         }
       }
     }
   }
   // bests contains now the sequence of best fitness values across the last generations
   Double historicHWAgo = bests.get(0);
   boolean res = true;
   for (int i = 1; i < haltingWindow; i++) {
     // if historic[-hW] is worse than historic[-hW+i] return false
     Double historicIter = bests.get(i);
     // if the iterated value (the later one in history) has improved, there is no convergence.
     boolean improvementHappened =
         (historicIter < historicHWAgo); // testSecondForImprovement(historicHWAgo, historicIter));
     if (improvementHappened) {
       res = false;
       break;
     }
   }
   return res;
 }
  /**
   * The subswarm is deactivated and the particles indices are returned. They are to be
   * reinitialized into the mainswarm.
   */
  @Override
  public int[] deactivateSubswarm(
      ParticleSubSwarmOptimization subswarm, ParticleSubSwarmOptimization mainswarm) {
    if (!subswarm.isActive()) {
      System.out.println("deactivateSubSwarm: try to deactivate inactive subswarm");
      return null;
    }

    // use the indizes of the deactivated particles for the reinitialized particles (important for
    // ANPSO)
    Population pop = subswarm.getPopulation();
    int[] particleIndices = new int[pop.size()];
    for (int i = 0; i < pop.size(); ++i) {
      AbstractEAIndividual indy = pop.getEAIndividual(i);
      // Integer index = (Integer)indy.getData("particleIndex");
      particleIndices[i] = indy.getIndividualIndex(); // index.intValue();
    }
    subswarm.SetActive(false);
    return particleIndices;
  }