예제 #1
0
  public void proposeOffSpring() {

    final int nDraws = 3;
    final double diffEvoParF = 0.6;
    final double diffEvoParK = 0.4;
    int[] availables = new int[nDraws];
    boolean drawAgain = true;
    int index;
    double[] dist1;
    double[] dist2;
    double[] proposal;
    double[] parent;

    // draw 3 random integer indices from [0,nPop], but not your own index and no recurrent samples
    for (int iPop = 0; iPop < nPop; iPop++) {
      availables[0] = -1;
      availables[1] = -1;
      availables[2] = -1;
      for (int iDraw = 0; iDraw < nDraws; iDraw++) {
        drawAgain = true;
        index = -1;
        while (drawAgain) {
          index = generator.nextInt(nPop);
          drawAgain =
              index == iPop
                  | index == availables[0]
                  | index == availables[1]
                  | index == availables[2];
        }
        availables[iDraw] = index;
      }

      dist1 = calcDistance(iPop, availables, 1);
      dist2 = calcDistance(iPop, availables, 2);

      parent = parents.getParameterCombination(iPop);

      proposal = new double[nPars];
      for (int iPar = 0; iPar < nPars; iPar++) {
        proposal[iPar] = parent[iPar] + diffEvoParF * dist1[iPar] + diffEvoParK * dist2[iPar];
      }
      proposals.setParameterCombination(iPop, proposal);
    }
    proposals = parSpace.reflectIfOutOfBounds(proposals);

    if (modelIsDynamic) {
      // if the model in question is dynamic, generate the model prediction by running the model.
      // Then feed the list of model
      // predictions into a function that runs the likelihoodfunction on the prediction, yielding a
      // list of objective scores
      proposals.calcModelResults();
      proposals.calcObjScores(obs);
    } else {
      // if the model in question is not dynamic, use the likelihood function directly to calculate
      // an objective score for each entry in parents.
      proposals.calcObjScores();
    }
  }
예제 #2
0
 // constructor:
 DiffEvo(
     int nGens,
     int nPop,
     ParSpace parSpace,
     LikelihoodFunctionFactory likelihoodFunctionFactory,
     long seed) {
   this.nGens = nGens;
   this.nPop = nPop;
   this.nPars = parSpace.getNumberOfPars();
   this.parSpace = parSpace;
   this.parents = new ListOfParameterCombinations(nPop, nPars, likelihoodFunctionFactory);
   this.proposals = new ListOfParameterCombinations(nPop, nPars, likelihoodFunctionFactory);
   this.generator = new Random();
   this.generator.setSeed(seed);
   //		this.likelihoodFunctionFactory = likelihoodFunctionFactory;
   this.evalResults = new EvalResults(nGens, nPop, parSpace, likelihoodFunctionFactory, generator);
   this.modelIsDynamic = false;
 }
예제 #3
0
  public void initializeParents() {

    // take uniform random samples of the parameter space and add them to the parents array:
    for (int iPop = 0; iPop < nPop; iPop++) {
      double[] parameterCombination = parSpace.takeUniformRandomSample(generator);
      parents.setParameterCombination(iPop, parameterCombination);
    }

    if (modelIsDynamic) {
      // if the model in question is dynamic, generate the model prediction by running the model.
      // Then feed the list of model
      // predictions into a function that runs the likelihoodfunction on the prediction, yielding a
      // list of objective scores
      parents.calcModelResults();
      parents.calcObjScores(obs);
    } else {
      // if the model in question is not dynamic, use the likelihood function directly to calculate
      // an objective score for each entry in parents.
      parents.calcObjScores();
    }

    // now add the initial values of parents to the record, i.e. evalResults
    for (int iPop = 0; iPop < nPop; iPop++) {
      int sampleIdentifier = iPop;
      double[] parameterCombination = parents.getParameterCombination(iPop).clone();
      double objScore = parents.getObjScore(iPop);
      EvalResult evalResult = null;
      if (modelIsDynamic) {
        evalResult =
            new EvalResult(
                sampleIdentifier,
                iPop,
                parameterCombination,
                objScore,
                parents.getModelResult(iPop));
      } else {
        evalResult = new EvalResult(sampleIdentifier, iPop, parameterCombination, objScore);
      }
      evalResults.add(evalResult);
    }
  }