예제 #1
0
def test_evolve():
    class TestIndividual(Individual):
        def __init__(self, *args, **kwargs):
            super(TestIndividual, self).__init__(*args, **kwargs)
            for x in range(5):
                self.append(random.random())

    evolve(lambda x: ((sum(x), sum(x), sum(x))), TestIndividual)
def create_network(p_connect=None, p_break=None):
    population = 1000
    n = Network(population, 200)
    plot = False
    if plot:
        test_plot(n)
    return evolution.evolve(n, p_connect, p_break)
예제 #3
0
def main(instrument, days, popsize, strategy='trend_ema'):
    print(colored("Starting evolution....", 'blue'))
    evaluate = partial(evaluate_zen, days=days)
    print(
        blue("Evaluating ") + green(popsize) + blue(" individuals over ") +
        green(days) + blue(' days in ') + green(partitions) +
        blue(' partitions.'))
    try:
        Andividual.instruments = selectors[instrument]
    except:
        # if not in the list, assume it is one usable instrument
        Andividual.instruments = [instrument]
    Andividual.mate = cxTwoPoint
    Andividual.mutate = partial(mutGaussian, mu=0, sigma=sigma, indpb=indpb)
    # Andividual.strategy = strategy
    strategies = parsing.strategies()
    Andividual.strategies = [st for st in strategies if 'forex' not in st]
    print('using strategies:', Andividual.strategies)
    print(
        colored(f"Mating function is ", 'blue') +
        colored(Andividual.mate, 'green'))
    print(
        colored(f"Mutating function is ", 'blue') +
        colored(Andividual.mutate, 'green'))
    res = evolve(evaluate, Andividual, popsize)
    return res
예제 #4
0
def main(instrument, days, popsize, strategy='trend_ema'):
    print(colored("Starting evolution....", 'blue'))
    evaluate = partial(evaluate_zen, days=days)
    print(blue("Evaluating ")+green(popsize)+blue(" individuals over ") + green(days) + blue(' days in ') + green(partitions) + blue(' partitions.'))
    Andividual.instruments = selectors[instrument]
    Andividual.mate = cxTwoPoint
    Andividual.mutate = partial(mutGaussian, mu=0, sigma=sigma, indpb=indpb)
    Andividual.strategy = strategy
    print(colored(f"Mating function is ", 'blue') + colored(Andividual.mate, 'green'))
    print(colored(f"Mutating function is ", 'blue') + colored(Andividual.mutate, 'green'))
    res = evolve(evaluate, Andividual, popsize)
    return res
예제 #5
0
def main(instrument, days, popsize, strategy='trend_ema', nobf=None):
    print(term.blue("Starting evolution...."))
    evaluate = partial(evaluate_zen, days=days)
    print(
        term.blue("Evaluating ") + term.green(str(popsize)) +
        term.blue(" individuals over ") + term.green(str(days)) +
        term.blue(" days in ") + term.green(str(partitions)) +
        term.blue(" partitions."))
    Andividual.path = path
    Andividual.instruments = selectors[instrument]
    Andividual.mate = cxTwoPoint
    Andividual.mutate = partial(mutGaussian, mu=0, sigma=sigma, indpb=indpb)
    Andividual.strategy = strategy
    print(term.blue("Mating function is ") + term.green(str(Andividual.mate)))
    print(
        term.blue("Mutating function is ") +
        term.green(str(Andividual.mutate)))
    res = evolve(evaluate, Andividual, popsize)
    return res
예제 #6
0
def main():
    populationSize = 200  # total size of popultion, maybe in the future reduce over time
    threshold = 0.10  # number of top population that will be used for reproduction
    mutationRateBest = 0.001  # chance to mutate de best solution
    numberOfEvolution = 100001  # max number o time steps

    functionType = input("Function ('kappa' or 'maxwellian'): "
                         )  ## only works with kappa and maxwellian

    ev_ins = str(input("Event Instant ('yyyymmdd hr:min:sec'): "))

    year = int(ev_ins[0:4])
    month = int(ev_ins[4:6])
    day = int(ev_ins[6:8])
    hour = int(ev_ins[9:11])
    minute = int(ev_ins[12:14])
    second = int(ev_ins[15:17])

    event_instant = datetime.datetime(year, month, day, hour, minute,
                                      second)  ## instant for data selection

    #13 42 40
    #10 00 00
    xt, yt = data.flux_values(event_instant)
    index = []
    #removing nan from arrays
    for i in xrange(len(xt)):
        if np.isnan(xt[i]) or np.isnan(yt[i]) or yt[i] < 1.0:
            index.append(i)

        x = np.delete(xt, index)
        y = np.delete(yt, index)

    # x = x[0:-1]
    # y = y[0:-1]
    #x = np.asarray(x)
    #y = np.asarray(y)
    #print x,y
    #
    #  creates data for test
    #
    # kappa is defined here as
    # y = A x ( 1 + B x )^-C
    #
    # and maxwellian as
    # y = A x exp(-B x)
    #
    # Use three coeficients for kappa and two for maxwellian
    # if vector of y is given ignore this
    if len(y) == 0:
        if functionType == "kappa":
            coefs = [100, 0.001, 12]
            y, mean = evo.kappa(x, coefs)
        elif functionType == "maxwellian":
            coefs = [100, 0.001]
            print "aqui"
            y, mean = evo.function(x, coefs)

    else:
        mean = sum(y) / len(y)

    ####
    # main evolution of the code
    evo.evolve(functionType, populationSize, threshold, mutationRateBest,
               numberOfEvolution, x, y, mean, event_instant)
예제 #7
0
파일: main.py 프로젝트: gtdrakeley/Genetic
import population
import fitness
import evolution

fitness.set_solution('{}{}{}{}'.format('11', '0000', '0' * (8 * 63), '11'))

pop = population.Population.initial(100)
gen_count = 0
while pop.get_fittest().fitness() < fitness.max_fitness():
    gen_count += 1
    print('Generation #{}: Fittest - {}'.format(gen_count, pop.get_fittest().fitness()))
    pop = evolution.evolve(pop)
print('Solution found!')
print('Generation #{}'.format(gen_count))
print('Genes:\n\t{}'.format(''.join([format(byte, '0>8b') for byte in pop.get_fittest().genes])))

예제 #8
0
    #return best_validation_loss


#----<mockup model function>----

#-----<evolution>------------

from evolution import evolve

popsize = 20
generations = 10

parameter_ranges = {
    "alma": [1, 100],
    "korte": [0.0, 1.0],
    "barack": [-10.0, 0.0],
    "vadkorte": ["egy", "ketto", "harom"]
}
pop_memory = []
fitness_memory = []

solution, score = evolve(parameter_ranges, dummy_model, popsize, generations,
                         pop_memory, fitness_memory)

#-----</evolution>------------

print("Ground truth:")
print("alma: 13, korte: 0.2, barack: -8.0, vadkorte: ketto")
print(solution)
print(score)
예제 #9
0
from evolution import evolve

evolve()