Exemple #1
0
 def compare_champs(self):
     self.epoch_len = self.hs.hist_full_size - (self.hd + 1)
     r_start = self.epoch_len
     champ_current = open("./champ_data/binance/latest_greatest.pkl", 'rb')
     g = pickle.load(champ_current)
     champ_current.close()
     [cppn] = create_cppn(g, self.config, self.leaf_names, ["cppn_out"])
     net_builder = ESNetwork(self.substrate, cppn, self.params)
     champ_fit = self.evaluate_champ(net_builder, r_start, g, 0)
     for ix, f in enumerate(os.listdir("./champ_data/binance")):
         if (f != "lastest_greatest.pkl"):
             champ_file = open("./champ_data/binance/" + f, 'rb')
             g = pickle.load(champ_file)
             champ_file.close()
             [cppn] = create_cppn(g, self.config, self.leaf_names,
                                  ["cppn_out"])
             net_builder = ESNetwork(self.substrate, cppn, self.params)
             g.fitness = self.evaluate_champ(net_builder,
                                             r_start,
                                             g,
                                             champ_num=ix)
             if (g.fitness > champ_fit):
                 with open("./champ_data/binance/latest_greatest.pkl",
                           'wb') as output:
                     pickle.dump(g, output)
     return
def make_net(genome, config, bs):
    #start by setting up a substrate for this bad cartpole boi
    params = {
        "initial_depth": 2,
        "max_depth": 4,
        "variance_threshold": 0.8,
        "band_threshold": 0.05,
        "iteration_level": 3,
        "division_threshold": 0.3,
        "max_weight": 34.0,
        "activation": "sigmoid"
    }
    input_cords = []
    output_cords = [(0.0, -1.0, -1.0)]
    sign = 1
    # we will use a 3 dimensional substrate, coords laid out here
    for i in range(4):
        input_cords.append((0.0 - i / 10 * sign, 0.0, 0.0))
        sign *= -1
    leaf_names = []
    for i in range(len(output_cords[0])):
        leaf_names.append(str(i) + "_in")
        leaf_names.append(str(i) + "_out")

    [cppn] = create_cppn(genome, config, leaf_names, ['cppn_out'])
    net_builder = ESNetwork(Substrate(input_cords, output_cords), cppn, params)
    net = net_builder.create_phenotype_network_nd()

    return net
Exemple #3
0
 def eval_fitness(self, genomes, config):
     self.epoch_len = 16
     r_start = randint(0 + self.epoch_len, self.hs.hist_full_size - self.hd)
     best_g_fit = 0.0
     champ_counter = self.gen_count % 10
     #img_count = 0
     for idx, g in genomes:
         [cppn] = create_cppn(g, config, self.leaf_names, ["cppn_out"])
         net_builder = ESNetwork(self.substrate, cppn, self.params)
         #cppn = neat.nn.FeedForwardNetwork.create(g, config)
         #network = ESNetwork(self.subStrate, cppn, self.params, self.hd)
         #net = network.create_phenotype_network_nd()
         train_ft = self.evaluate(net_builder, r_start, g)
         g.fitness = train_ft
         if (g.fitness > best_g_fit):
             best_g_fit = g.fitness
             with open(
                     "./champ_data/kraken/latest_greatest" +
                     str(champ_counter) + ".pkl", 'wb') as output:
                 pickle.dump(g, output)
         #img_count += 1
     '''
     if(champ_counter == 0):
         self.refresh()
         self.compare_champs()
     '''
     self.gen_count += 1
     return
def make_net(genome, config, bs):
    #start by setting up a substrate for this bad cartpole boi
    params = {"initial_depth": 2,
              "max_depth": 4,
              "variance_threshold": 0.00013,
              "band_threshold": 0.00013,
              "iteration_level": 3,
              "division_threshold": 0.00013,
              "max_weight": 3.0,
              "activation": "tanh"}
    input_cords = []
    output_cords = [(0.0, -1.0, 0.0)]
    sign = 1
    for i in range(4):
        input_cords.append((0.0 - i/10*sign, 1.0, 0.0))
        sign *= -1
    leaf_names = []
    for i in range(3):
        leaf_names.append('leaf_one_'+str(i))
        leaf_names.append('leaf_two_'+str(i))

    [cppn] = create_cppn(genome, config, leaf_names, ['cppn_out'])
    # print(cppn)
    print(leaf_names)
    print(config.genome_config.input_keys)
    net_builder = ESNetwork(Substrate(input_cords, output_cords), cppn, params)
    net = net_builder.create_phenotype_network_nd()
    return net
 def eval_fitness(self, genomes, config):
     self.epoch_len = randint(21, 255)
     r_start = randint(0 + self.hd, self.hs.hist_full_size - self.epoch_len)
     for idx, g in genomes:
         [cppn] = create_cppn(g, config, self.leaf_names, ['cppn_out'])
         network = ESNetwork(self.subStrate, cppn, self.params)
         net = network.create_phenotype_network_nd('training_net.png')
         g.fitness = self.evaluate(net, network, r_start, g)
     return
Exemple #6
0
def eval_genomes(genomes, config):
    for genome_id, genome in genomes:
        genome.fitness = 0
        net = create_cppn(genome, config, ["In1", "In2"], ["Out"])[0]
        #net = neat.nn.FeedForwardNetwork.create(genome, config)
        for xi, xo in zip(xor_inputs, xor_outputs):

            output = net.activate([xi[0], xi[1]], shape=(1, 1)).item()
            genome.fitness += (output - xo[0])**2
 def load_net(self):
     #file = open("./champ_gens/thot-checkpoint-13",'rb')
     g = neat.Checkpointer.restore_checkpoint("./champ_gens/thot-checkpoint-25")
     best_fit = 0.0
     for gx in g.population:
         if g.population[gx].fitness != None:
             if g.population[gx].fitness > best_fit:
                 bestg = g.population[gx]
     g = bestg
     #file.close()
     [the_cppn] = create_cppn(g, self.config, self.leaf_names, ['cppn_out'])
     self.cppn = the_cppn
Exemple #8
0
 def load_net(self, fname):
     f = open(fname, 'rb')
     g = neat.Checkpointer().restore_checkpoint(fname)
     bestFit = 0.0
     for gx in g.population:
         if g.population[gx].fitness != None:
             if g.population[gx].fitness > bestFit:
                 bestg = g.population[gx]
     g = bestg
     f.close()
     [the_cppn] = create_cppn(g, self.config, self.leaf_names, ['cppn_out'])
     self.cppn = the_cppn
 def eval_fitness(self, genomes, config):
     r_start = randint(0+self.hd, self.hs.hist_full_size - self.epoch_len)
     fitter = genomes[0]
     fitter_val = 0.0 
     for idx, g in genomes:
         [cppn] = create_cppn(g, config, self.leaf_names, ['cppn_out'])
         network = ESNetwork(self.subStrate, cppn, self.params)
         net = network.create_phenotype_network_nd()
         g.fitness = self.evaluate(net, network, r_start, g)
         if(g.fitness > fitter_val):
             fitter = g
             fitter_val = g.fitness
     with open('./champs/perpetual_champion_'+str(fitter.key)+'.pkl', 'wb') as output:
         pickle.dump(fitter, output)
     print("latest_saved")
 def evaluate(self, g, config):
     rand_start = self.rand_start
     [cppn] = create_cppn(g, config, self.leaf_names, ['cppn_out'])
     net = ESNetwork(self.subStrate, cppn, self.params)
     network = net.create_phenotype_network_nd()
     portfolio_start = 1.0
     key_list = list(self.hs.currentHists.keys())
     portfolio = CryptoFolio(portfolio_start, self.hs.coin_dict)
     end_prices = {}
     buys = 0
     sells = 0
     if (len(g.connections) > 0.0):
         for z in range(rand_start, rand_start + self.epoch_len):
             active = self.get_one_epoch_input(z)
             signals = []
             network.reset()
             for n in range(1, self.hd + 1):
                 out = network.activate(active[self.hd - n])
             for x in range(len(out)):
                 signals.append(out[x])
             #rng = iter(shuffle(rng))
             sorted_shit = np.argsort(signals)[::-1]
             for x in sorted_shit:
                 sym = self.hs.coin_dict[x]
                 #print(out[x])
                 #try:
                 if (out[x] < -.5):
                     #print("selling")
                     portfolio.sell_coin(
                         sym, self.hs.currentHists[sym]['close'][z])
                     #print("bought ", sym)
                 if (out[x] > .5):
                     #print("buying")
                     portfolio.target_amount = .1 + (out[x] * .1)
                     portfolio.buy_coin(
                         sym, self.hs.currentHists[sym]['close'][z])
                     #print("sold ", sym)
                 #skip the hold case because we just dont buy or sell hehe
                 if (z > self.epoch_len + rand_start - 2):
                     end_prices[sym] = self.hs.currentHists[sym]['close'][z]
         result_val = portfolio.get_total_btc_value(end_prices)
         print(result_val[0], "buys: ", result_val[1], "sells: ",
               result_val[2])
         ft = result_val[0]
     else:
         ft = 0.0
     return ft
Exemple #11
0
def make_net(genome,
             config,
             batch_size,
             state_space_dim=111,
             action_space_dim=8) -> RecurrentNet:
    #start by setting up a substrate for this bad ant boi
    params = {
        "initial_depth": 1,
        "max_depth": 5,
        "variance_threshold": 0.8,
        "band_threshold": 0.05,
        "iteration_level": 3,
        "division_threshold": 0.3,
        "max_weight": 10.0,
        "activation": "relu"
    }
    assert params[
        "activation"] in piecewise_linear_activations, f"for NAS without search, network activation needs to be piecewise linear"

    # FIXME this can just be list
    joint_name_dict = {
        0: "hip_4",
        1: "ankle_4",
        2: "hip_1",
        3: "ankle_1",
        4: "hip_2",
        5: "ankle_2",
        6: "hip_3",
        7: "ankle_3",
    }
    assert len(joint_name_dict) == len(output_coords)

    leaf_names = []
    for i in range(len(output_coords[0])):
        leaf_names.append(str(i) + "_in")
        leaf_names.append(str(i) + "_out")
    input_coords = get_in_coords()

    [cppn] = create_cppn(genome, config, leaf_names, ['cppn_out'])
    net_builder = ESNetwork(Substrate(input_coords, output_coords), cppn,
                            params)
    net = net_builder.create_phenotype_network_nd(batch_size=batch_size)
    return net  # RecurrentNet ((not necessarily actually recurrent))
def make_net(genome, config, _batch_size):
    params = {
        "initial_depth": 1,
        "max_depth": 2,
        "variance_threshold": 0.8,
        "band_threshold": 0.05,
        "iteration_level": 3,
        "division_threshold": 0.3,
        "max_weight": 30.0,
        "activation": "tanh"
    }
    input_cords = [(-1.0, 1.0, 0.0), (-.5, 1.0, 0.0), (.5, 1.0, 0.0),
                   (1.0, 1.0, 0.0)]
    output_cords = [(-1.0, -1.0, -1.0), (0.0, -1.0, -1.0), (1.0, -1.0, -1.0)]
    leaf_names = []
    for i in range(len(output_cords[0])):
        leaf_names.append(str(i) + "_in")
        leaf_names.append(str(i) + "_out")
    [cppn] = create_cppn(genome, config, leaf_names, ['cppn_out'])
    net_builder = ESNetwork(Substrate(input_cords, output_cords), cppn, params)
    #net = net_builder.create_phenotype_network_nd('./genome_vis')
    return net_builder
def make_net(genome, config, bs):
    #start by setting up a substrate for this bad cartpole boi
    params = {
        "initial_depth": 1,
        "max_depth": 2,
        "variance_threshold": 0.8,
        "band_threshold": 0.13,
        "iteration_level": 3,
        "division_threshold": 0.3,
        "max_weight": 3.0,
        "activation": "relu"
    }
    input_cords = [(0.1, 0.1, 0.1), (-0.1, -0.1, -0.1)]
    output_cords = [(0.0, 1.0, -1.0), (0.0, 0.0, -1.0), (0.0, -1.0, -1.0)]
    leaf_names = []
    for i in range(len(output_cords[0])):
        leaf_names.append(str(i) + "_in")
        leaf_names.append(str(i) + "_out")

    [cppn] = create_cppn(genome, config, leaf_names, ['cppn_out'])
    net_builder = ESNetwork(Substrate(input_cords, output_cords), cppn, params)
    net = net_builder.create_phenotype_network_nd('./genome_vis')
    return net
Exemple #14
0
 def load_net_easy(self, g):
     [the_cppn] = create_cppn(g, self.config, self.leaf_names, ['cppn_out'])
     self.cppn = the_cppn
Exemple #15
0
 def __init__(self, genome, config, inputs, threshold=0.5):
     self._cppn = create_cppn(genome, config, inputs.keys(), ['w'])[0]
     self._inputs = inputs
     self._threshold = threshold
Exemple #16
0
    winner = pop.run(task.eval_fitness, gens)
    print("es trade god summoned")
    return winner, stats


# If run as script.
if __name__ == '__main__':
    task = PurpleTrader(8)
    #print(task.trial_run())
    winner = run_pop(task, 89)[0]
    print('\nBest genome:\n{!s}'.format(winner))

    # Verify network output against training data.
    print('\nOutput:')
    [cppn] = create_cppn(winner, task.config, task.leaf_names, ['cppn_out'])
    network = ESNetwork(task.subStrate, cppn, task.params)
    with open('es_trade_god_cppn_3d.pkl', 'wb') as output:
        pickle.dump(winner, output)
    #draw_net(cppn, filename="es_trade_god")
    winner_net = network.create_phenotype_network_nd('dabestest.png')  # This will also draw winner_net.

    # Save CPPN if wished reused and draw it to file.
    #draw_net(cppn, filename="es_trade_god")


    '''
    for x in range(len(task.hs.hist_shaped[0])):
        print(task.hs.hist_shaped[1][x][3],task.hs.hist_shaped[0][x][3])
    '''
 def load_net(self, fname):
     f = open(fname,'rb')
     g = pickle.load(f)
     f.close()
     [the_cppn] = create_cppn(g, self.config, self.leaf_names, ['cppn_out'])
     self.cppn = the_cppn