当前位置: 首页>>代码示例>>Java>>正文


Java CandidateFactory类代码示例

本文整理汇总了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);
}
 
开发者ID:matttproud,项目名称:groningen,代码行数:21,代码来源:IncrementalEvolutionEngine.java

示例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, "************************************************************");
    }
  });
}
 
开发者ID:matttproud,项目名称:groningen,代码行数:62,代码来源:Hypothesizer.java


注:本文中的org.uncommons.watchmaker.framework.CandidateFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。