本文整理匯總了Java中org.uncommons.watchmaker.framework.CandidateFactory類的典型用法代碼示例。如果您正苦於以下問題:Java CandidateFactory類的具體用法?Java CandidateFactory怎麽用?Java CandidateFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CandidateFactory類屬於org.uncommons.watchmaker.framework包,在下文中一共展示了CandidateFactory類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: IncrementalEvolutionEngine
import org.uncommons.watchmaker.framework.CandidateFactory; //導入依賴的package包/類
public IncrementalEvolutionEngine(
CandidateFactory<T> candidateFactory,
EvolutionaryOperator<T> evolutionScheme,
FitnessEvaluator<? super T> fitnessEvaluator,
SelectionStrategy<? super T> selectionStrategy,
Random rng,
int populationSize,
int eliteCount,
TerminationCondition... conditions) {
this(
candidateFactory,
evolutionScheme,
fitnessEvaluator,
selectionStrategy,
rng,
populationSize,
eliteCount,
new SystemClock(),
conditions);
}
示例2: initializeEvolutionEngine
import org.uncommons.watchmaker.framework.CandidateFactory; //導入依賴的package包/類
private void initializeEvolutionEngine(Experiment lastExperiment) {
if (gaEngine != null) {
logger.severe("First Hypothesizer invocation already has GA engine initialized.");
throw new IllegalStateException(
"First Hypothesizer invocation already has GA engine initialized.");
}
// Create a candidate factory that the GA framework will call to create the initial population.
CandidateFactory<List<Integer>> candidateFactory =
new CommandLineArgumentFactory(lastExperiment);
// Set up the crossover and mutation operators.
List<EvolutionaryOperator<List<Integer>>> operators = Lists.newArrayList();
operators.add(new ListCrossover<Integer>(config.getParamBlock().getNumCrossovers()));
operators.add(
new IntegerListMutator(new Probability(config.getParamBlock().getMutationProb())));
// Add the operators to the pipeline.
EvolutionaryOperator<List<Integer>> pipeline = new EvolutionPipeline<List<Integer>>(operators);
// Set up the fitness evaluator.
FitnessEvaluator<List<Integer>> evaluator =
new ListFitnessEvaluator((int) populationSize.get());
// We use simple stagnation condition for terminating the GA. If the population doesn't improve
// over a certain number of evolutions, the GA stops.
TerminationCondition condition = null;
// Our only termination condition is stagnation and when that is defaulting
// to 0 we ignore it
if (config.getParamBlock().getStagnantGens() > 0) {
condition = new Stagnation(config.getParamBlock().getStagnantGens(), evaluator.isNatural());
}
// Create an evolution engine with the above parameters.
gaEngine =
new IncrementalEvolutionEngine<List<Integer>>(candidateFactory, pipeline, evaluator,
new TournamentSelection(new Probability(0.75)), new MersenneTwisterRNG(),
(int) populationSize.get(), config.getParamBlock().getEliteCount(), condition);
gaEngine.addEvolutionObserver(new EvolutionObserver<List<Integer>>() {
@Override
public void populationUpdate(PopulationData<List<Integer>> data,
List<EvaluatedCandidate<List<Integer>>> population) {
logger.info("************************************************************");
logger.info(String.format("Generation %s: Best fitness %s",
data.getGenerationNumber() + 1, data.getBestCandidateFitness()));
logger.info(String.format("Best candidate: %s", data.getBestCandidate()));
logger.info(String.format("Standard deviation: %s; Mean: %s",
data.getFitnessStandardDeviation(), data.getMeanFitness()));
logger.info("------------------------------------------------------------");
for (int i = 0; i < population.size(); ++i) {
EvaluatedCandidate<List<Integer>> candidate = population.get(i);
logger.info(String.format("Candidate %s: %s; Fitness %s",
i, candidate.getCandidate(), candidate.getFitness()));
}
logger.log(Level.INFO, "************************************************************");
}
});
}