本文整理汇总了Java中org.uncommons.maths.random.Probability类的典型用法代码示例。如果您正苦于以下问题:Java Probability类的具体用法?Java Probability怎么用?Java Probability使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Probability类属于org.uncommons.maths.random包,在下文中一共展示了Probability类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeEvolutionEngine
import org.uncommons.maths.random.Probability; //导入依赖的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, "************************************************************");
}
});
}
示例2: IntegerListMutator
import org.uncommons.maths.random.Probability; //导入依赖的package包/类
IntegerListMutator(Probability mutationProbability) {
probability = new ConstantGenerator<Probability>(mutationProbability);
}