Exemple #1
0
def specie_h(population, p, n, pset, direccion):  # heuristic applied by specie
    gpo_specie=specie_gpo(population)
    for specie in gpo_specie:
        eval_prob(specie[0])
    for ind in population:
        if ind.bestspecie_get()==1:
            if random.random()<=ind.get_LS_prob():
                strg=ind.__str__()
                args=[]
                if len(pset.arguments) > 0:
                    for arg in pset.arguments:
                        args.append(arg)
                l_strg=add_subt_cf(strg, args)
                c = tree2f()
                cd=c.convert(l_strg)
                xdata,ydata=get_address(p, n,direccion)
                beta_opt, beta_cov, success, nfev = curve_fit_2(eval_,cd , xdata, ydata, p0=ind.get_params(), method='trf', max_nfev=40)
                if not success:
                    ind.LS_applied_set(1)
                    ind.LS_story_set(1)
                else:
                    ind.LS_applied_set(1)
                    ind.LS_story_set(1)
                    ind.params_set(beta_opt)
                    funcEval.cont_evalp += nfev
Exemple #2
0
def best_pop_ls(population, p,  n, pset, direccion):  # best of the pop
    ind = best_pop(population)
    strg = ind.__str__()
    args = []
    if len(pset.arguments) > 1:
        for arg in pset.arguments:
            args.append(arg)
    l_strg = add_subt_cf(strg, args)
    c = tree2f()
    cd = c.convert(l_strg)
    xdata,ydata = get_address(p, n, direccion)
    beta_opt, beta_cov, success, nfev = curve_fit_2(eval_, cd, xdata, ydata, p0=ind.get_params(), method='trf', max_nfev=40)
    if not success:
        ind.LS_applied_set(1)
        ind.LS_story_set(1)
    else:
        ind.LS_applied_set(1)
        ind.LS_story_set(1)
        ind.params_set(beta_opt)
        funcEval.cont_evalp += nfev
Exemple #3
0
def ls_random(population, p, n, pset, direccion, problem):  # size heuristic
    random_set=random_set_pop(population)
    for ind in random_set:
        strg = ind.__str__()
        args = []
        if len(pset.arguments) > 1:
            for arg in pset.arguments:
                args.append(arg)
        l_strg = add_subt_cf(strg, args)
        c = tree2f()
        cd = c.convert(l_strg)
        xdata, ydata = get_address(p, n, problem,direccion)
        beta_opt, beta_cov, success, nfev = curve_fit_2(eval_,cd , xdata, ydata, p0=ind.get_params(), method='trf', max_nfev=40)
        if not success:
            ind.LS_applied_set(1)
            ind.LS_story_set(1)
        else:
            ind.LS_applied_set(1)
            ind.LS_story_set(1)
            funcEval.cont_evalp += nfev
            ind.params_set(beta_opt)