本文整理汇总了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, "************************************************************");
}
});
}