コード例 #1
0
def mutate(individual, pset, expr):
    rand = np.random.rand()
    if rand <= 0.25:
        return gp.mutShrink(individual),
    elif rand <= 0.5:
        return gp.mutInsert(individual, pset)
    elif rand <= 0.75:
        return gp.mutNodeReplacement(individual, pset)
    return gp.mutUniform(individual, expr, pset)
コード例 #2
0
def multi_mutate(individual, expr, pset):
    '''定义变异函数'''
    rand = np.random.uniform(0)
    if rand <= 0.33:
        return gp.mutUniform(individual, expr, pset)
    elif rand <= 0.66:
        return gp.mutShrink(individual)
    else:
        return gp.mutNodeReplacement(individual, pset)
コード例 #3
0
def multi_mutate(individual, expr, pset):
    '''
    apply multiple kinds of mutation in a funciton
    '''
    rand = np.random.uniform(0)
    if rand <= 0.4:
        return gp.mutUniform(individual, expr, pset)
    elif rand <= 0.75:
        return gp.mutShrink(individual)
    else:
        return gp.mutNodeReplacement(individual, pset)
コード例 #4
0
def multiple_mutator(individual, pset):
    weight_sum = gencome.config.mut_uniform_weight + gencome.config.mut_replacement_weight \
        + gencome.config.mut_insert_weight + gencome.config.mut_shrink_weight
    cur_weight = gencome.config.mut_uniform_weight
    rng = random.random() * weight_sum
    if rng < cur_weight:
        logger.debug(
            f"Starting mutation: Uniform {str_individual_with_real_feature_names(individual)}"
        )
        new_ind = gp.mutUniform(individual,
                                expr=gencome.config.toolbox.expr_mut,
                                pset=pset)
        logger.debug(
            f"Successful mutation: Uniform {str_individual_with_real_feature_names(new_ind[0])}"
        )
        return new_ind
    cur_weight += gencome.config.mut_replacement_weight
    if rng < cur_weight:
        logger.debug(
            f"Starting mutation: Node Replace {str_individual_with_real_feature_names(individual)}"
        )
        new_ind = gp.mutNodeReplacement(individual, pset=pset)
        logger.debug(
            f"Successful mutation: Node Replace {str_individual_with_real_feature_names(new_ind[0])}"
        )
        return new_ind
    cur_weight += gencome.config.mut_insert_weight
    if rng < cur_weight:
        logger.debug(
            f"Starting mutation Insert {str_individual_with_real_feature_names(individual)}"
        )
        new_ind = gp.mutInsert(individual, pset=pset)
        logger.debug(
            f"Successful mutation Insert {str_individual_with_real_feature_names(new_ind[0])}"
        )
        return new_ind
    logger.debug(
        f"Starting mutation Shrink {str_individual_with_real_feature_names(individual)}"
    )
    new_ind = gp.mutShrink(individual)
    logger.debug(
        f"Successful mutation Shrink {str_individual_with_real_feature_names(new_ind[0])}"
    )
    return new_ind
コード例 #5
0
def random_mutation(individual, expr, pset):
    return random.choice([gp.mutShrink(individual), gp.mutNodeReplacement(individual, pset), gp.mutUniform(individual, expr, pset), gp.mutEphemeral(individual, "all")])
コード例 #6
0
ファイル: coevolution.py プロジェクト: dwgoon/sgpNet
 def _mutate(individual, expr, pset):
     r = random.random()
     if r < 0.9:
         return gp.mutUniform(individual, expr, pset)
     else:
         return gp.mutNodeReplacement(individual, pset)