def train_model(layers, inputs, prices, pop_size=150, data_rotation=0, w_mutation_rate = 0.05, b_mutation_rate = 0.0, mutation_scale = 0.3, mutation_decay = 1., reporter=None): # network parameters network_params = { 'network': 'feedforward', 'input': inputs.shape[1], 'hidden': layers, 'output': 2 } # build initial population pop = Population(network_params, pop_size, mutation_scale, w_mutation_rate, b_mutation_rate, mutation_decay, socket_reporter=reporter) g = 1 ########### sample_size = 500 # request.json["sampleSize"] while True: if not g % data_rotation: ########### ohlc, ta = data.get_rand_segment(sample_size) ########## inputs, prices = data.get_training_segment() ########## pop.evolve() gen_best = pop.run((inputs, prices), fitness_callback=calc_overperformance) g += 1
def train_model(layers, inputs, prices, pop_size=150, data_rotation=0, w_mutation_rate=0.05, b_mutation_rate=0.0, mutation_scale=0.3, mutation_decay=1., reporter=None): # network parameters network_params = { 'network': 'feedforward', 'input': inputs.shape[1], 'hidden': layers, 'output': 2 } # build initial population pop = Population(network_params, pop_size, mutation_scale, w_mutation_rate, b_mutation_rate, mutation_decay, socket_reporter=reporter) g = 0 while True: if g % data_rotation: # need to rotate data here pass pop.evolve() gen_best = pop.run((inputs, prices), fitness_callback=calculate_profit) g += 1
# genetic parameters pop_size = 4 w_mutation_rate = 0.05 b_mutation_rate = 0.0 mutation_scale = 0.3 mutation_decay = 0.995 generations = 500 # network parameters network_params = { 'network': 'recurrent', 'timesteps': 4, 'input': inputs_train.shape[1], 'hidden': [16, 16, 16], 'output': 2 } # build initial population pop = Population(network_params, pop_size, mutation_scale, w_mutation_rate, b_mutation_rate, mutation_decay) # run for set number of generations for g in range(generations): pop.evolve(g) gen_best = pop.run(inputs_train, price_train, fitness_callback=calculate_profit) gen_best.save() pop.test(inputs_test, price_test, fitness_callback=calculate_profit)