public void updateParentsWithProposals() { double scoreParent; double scoreProposal; int nModelEvals = evalResults.getNumberOfEvalResults(); double logOfUnifRandDraw; double[] parameterCombination; double objScore; double[][] sim = null; for (int iPop = 0; iPop < nPop; iPop++) { scoreParent = parents.getObjScore(iPop); scoreProposal = proposals.getObjScore(iPop); logOfUnifRandDraw = Math.log(generator.nextDouble()); int sampleIdentifier = nModelEvals + iPop; int firstOccurrence = -1; if (scoreProposal - scoreParent >= logOfUnifRandDraw) { // accept proposal parameterCombination = proposals.getParameterCombination(iPop); objScore = proposals.getObjScore(iPop); if (modelIsDynamic) { sim = proposals.getModelResult(iPop); } firstOccurrence = nModelEvals + iPop; } else { // reject proposal parameterCombination = parents.getParameterCombination(iPop); objScore = parents.getObjScore(iPop); if (modelIsDynamic) { sim = parents.getModelResult(iPop); } firstOccurrence = parents.getFirstOccurrence(iPop); } parents.setParameterCombination(iPop, parameterCombination); parents.setObjScore(iPop, objScore); parents.setFirstOccurrence(iPop, firstOccurrence); if (modelIsDynamic) { parents.setModelResults(iPop, sim); } // add most recent sample to the record array evalResults: EvalResult evalResult; if (modelIsDynamic) { evalResult = new EvalResult( sampleIdentifier, firstOccurrence, parameterCombination.clone(), objScore, sim.clone()); } else { evalResult = new EvalResult( sampleIdentifier, firstOccurrence, parameterCombination.clone(), objScore); } evalResults.add(evalResult); } }
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); } }