Beispiel #1
0
  /**
   * Make sure that the parameter sets of each population are updated (reinitialized) if a
   * population is reinitialized.
   *
   * @see InterfacePopulationChangedEventListener
   */
  @Override
  public void registerPopulationStateChanged(Object source, String name) {
    if (name.equals(Population.POPULATION_INITIALIZED)) {
      Population pop = (Population) source;

      CMAParamSet params = (CMAParamSet) (pop.getData(MutateESRankMuCMA.cmaParamsKey));
      int mu;
      if (pop.hasData(EvolutionStrategies.esMuParam)) {
        mu = (Integer) pop.getData(EvolutionStrategies.esMuParam);
      } else {
        System.err.println("Unknown mu in reinit! using lambda/2...");
        mu = pop.size() / 2;
      }
      pop.putData(
          MutateESRankMuCMA.cmaParamsKey,
          CMAParamSet.initCMAParams(params, mu, pop.size(), pop, params.firstSigma));
    }
  }
Beispiel #2
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.
   *
   * @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,
      double[] center,
      double[][] range,
      double initialSigma) {
    // those are from initialize:
    params.firstAdaptionDone = false;
    params.range = range;

    int dim = params.range.length;
    params.eigenvalues = new double[dim];
    Arrays.fill(params.eigenvalues, 1.);
    params.meanX = new double[dim];
    params.pathC = new double[dim];
    params.pathS = new double[dim];

    params.mC = Matrix.identity(dim, dim);
    params.mB = Matrix.identity(dim, dim);

    // from adaptAfterSel
    params.weights = initWeights(mu, lambda);
    double muEff = getMuEff(params.weights, mu);
    params.c_sig = (muEff + 2) / (muEff + dim + 3);
    //		c_u_sig = Math.sqrt(c_sig * (2.-c_sig));
    params.d_sig = params.c_sig + 1 + 2 * Math.max(0, Math.sqrt((muEff - 1) / (dim + 1)) - 1);

    if (initialSigma < 0) { // this means we scale the average range
      if (initialSigma != -0.25 && (initialSigma != -0.5)) {
        EVAERROR.errorMsgOnce("Warning, unexpected initial sigma in CMAParamSet!");
      }
      initialSigma = -initialSigma * Mathematics.getAvgRange(params.range);
    }
    if (initialSigma <= 0) {
      EVAERROR.errorMsgOnce("warning: initial sigma <= zero! Working with converged population?");
      initialSigma = 10e-10;
    }
    params.sigma = initialSigma;
    //		System.out.println("INitial sigma: "+sigma);
    params.firstSigma = params.sigma;
    //		System.out.println("new center is " + BeanInspector.toString(center));
    params.meanX = center; // this might be ok?
    return params;
  }