コード例 #1
0
    for i, k in enumerate(params):
      if i<self.n_cross or random.random() < self.cr:
        # cfg = x1 + use_f*(x2 - x3)
        cfg_params[k].set_linear(1.0, x1, use_f, x2, -use_f, x3)

    pp.touch() # move to back of the line for next replacement
    pp.candidate_replacement = self.driver.get_configuration(cfg)
    self.limit = self.driver.objective.limit_from_config(pp.config)
    return pp.candidate_replacement

  def handle_requested_result(self, result):
    '''called when new results are added'''
    for p in self.population:
      if p.candidate_replacement == result.configuration:
        if self.objective.lt(p.candidate_replacement, p.config):
          # candidate replacement was better, replace it!
          p.config = p.candidate_replacement
          log.info("better point")
        p.candidate_replacement = None

class DifferentialEvolutionAlt(DifferentialEvolution):
  def __init__(self, cr=0.2, **kwargs):
    kwargs['cr'] = cr
    super(DifferentialEvolutionAlt, self).__init__(**kwargs)


register(DifferentialEvolution(name='de'))
register(DifferentialEvolutionAlt())


コード例 #2
0
        for i, k in enumerate(params):
            if i < self.n_cross or random.random() < self.cr:
                # cfg = x1 + use_f*(x2 - x3)
                cfg_params[k].set_linear(1.0, x1, use_f, x2, -use_f, x3)

        return cfg

    def handle_requested_result(self, result):
        """called when new results are added"""
        for p in self.population:
            if p.candidate_replacement == result.configuration:
                if self.objective.lt(p.candidate_replacement, p.config):
                    # candidate replacement was better, replace it!
                    p.config = p.candidate_replacement
                    log.info('better point')
                p.candidate_replacement = None


class DifferentialEvolutionAlt(DifferentialEvolution):
    def __init__(self, cr=0.2, **kwargs):
        kwargs['cr'] = cr
        super(DifferentialEvolutionAlt, self).__init__(**kwargs)


register(DifferentialEvolution())
register(DifferentialEvolutionAlt())
register(
    DifferentialEvolution(population_size=100,
                          cr=0.2,
                          name='DifferentialEvolution_20_100'))
コード例 #3
0
        return population

    def select_parameters(self, params):
        random.shuffle(params)
        ret_list = params[:self.must_mutate_count]
        for param in params[self.must_mutate_count:]:
            if random.random() < self.mutation_rate:
                ret_list.append(param)
        return ret_list

    def get_default_operator(self, param_type):
        return {'op_name': 'op1_randomize', 'args': [], 'kwargs': {}}


register(
    RandomThreeParentsComposableTechnique(name='ComposableDiffEvolution',
                                          population_size=30))
register_generator(RandomThreeParentsComposableTechnique)
register_generator(GreedyComposableTechnique)

op_map = {}
ComposableEvolutionaryTechnique.add_to_map(op_map,
                                           PermutationParameter,
                                           "op3_cross",
                                           xchoice='op3_cross_CX')
ComposableEvolutionaryTechnique.add_to_map(op_map,
                                           "FloatArray",
                                           "op3_cross",
                                           strength=0.4)
register(
    RandomThreeParentsComposableTechnique(name='ComposableDiffEvolutionCX',
コード例 #4
0
    params = self.manipulator.param_names(cfg, x1, x2, x3)
    random.shuffle(params)
    for i, k in enumerate(params):
      if i < self.n_cross or random.random() < self.cr:
        # cfg = x1 + use_f*(x2 - x3)
        cfg_params[k].set_linear(1.0, x1, use_f, x2, -use_f, x3)

    return cfg

  def handle_requested_result(self, result):
    """called when new results are added"""
    for p in self.population:
      if p.candidate_replacement == result.configuration:
        if self.objective.lt(p.candidate_replacement, p.config):
          # candidate replacement was better, replace it!
          p.config = p.candidate_replacement
          log.info('better point')
        p.candidate_replacement = None


class DifferentialEvolutionAlt(DifferentialEvolution):
  def __init__(self, cr=0.2, **kwargs):
    kwargs['cr'] = cr
    super(DifferentialEvolutionAlt, self).__init__(**kwargs)


register(DifferentialEvolution())
register(DifferentialEvolutionAlt())


コード例 #5
0
    params = self.manipulator.param_names(cfg, x1, x2, x3)
    random.shuffle(params)
    for i, k in enumerate(params):
      if i < self.n_cross or random.random() < self.cr:
        # cfg = x1 + use_f*(x2 - x3)
        cfg_params[k].set_linear(1.0, x1, use_f, x2, -use_f, x3)

    return cfg

  def handle_requested_result(self, result):
    """called when new results are added"""
    for p in self.population:
      if p.candidate_replacement == result.configuration:
        if self.objective.lt(p.candidate_replacement, p.config):
          # candidate replacement was better, replace it!
          p.config = p.candidate_replacement
          log.info('better point')
        p.candidate_replacement = None


class DifferentialEvolutionAlt(DifferentialEvolution):
  def __init__(self, cr=0.2, **kwargs):
    kwargs['cr'] = cr
    super(DifferentialEvolutionAlt, self).__init__(**kwargs)


register(DifferentialEvolution())
register(DifferentialEvolutionAlt())


コード例 #6
0
    for i, k in enumerate(params):
      if i < self.n_cross or random.random() < self.cr:
        # cfg = x1 + use_f*(x2 - x3)
        cfg_params[k].set_linear(1.0, x1, use_f, x2, -use_f, x3)

    return cfg

  def handle_requested_result(self, result):
    """called when new results are added"""
    for p in self.population:
      if p.candidate_replacement == result.configuration:
        if self.objective.lt(p.candidate_replacement, p.config):
          # candidate replacement was better, replace it!
          p.config = p.candidate_replacement
          log.info('better point')
        p.candidate_replacement = None


class DifferentialEvolutionAlt(DifferentialEvolution):
  def __init__(self, cr=0.2, **kwargs):
    kwargs['cr'] = cr
    super(DifferentialEvolutionAlt, self).__init__(**kwargs)


register(DifferentialEvolution())
register(DifferentialEvolutionAlt())
register(DifferentialEvolution(population_size=100, cr=0.2,
                               name='DifferentialEvolution_20_100'))


コード例 #7
0
    return population

  def select_parameters(self, params):
    random.shuffle(params)
    ret_list = params[:self.must_mutate_count]
    for param in params[self.must_mutate_count:]:
      if random.random() < self.mutation_rate:
        ret_list.append(param)
    return ret_list

  def get_default_operator(self, param_type):
    return {'op_name': 'op1_randomize', 'args': [], 'kwargs':{}}


register(RandomThreeParentsComposableTechnique(name='ComposableDiffEvolution',
                                                 population_size=30))
register_generator(RandomThreeParentsComposableTechnique)
register_generator(GreedyComposableTechnique)


op_map = {}
ComposableEvolutionaryTechnique.add_to_map(op_map,
                                      PermutationParameter,
                                      "op3_cross", xchoice='op3_cross_CX')
ComposableEvolutionaryTechnique.add_to_map(op_map,
                                      "FloatArray",
                                      "op3_cross", strength=0.4)
register(RandomThreeParentsComposableTechnique(name='ComposableDiffEvolutionCX',
                                                 operator_map=op_map,
                                                 population_size=30))