Beispiel #1
0
def make_net(genome, config, bs):
    #start by setting up a substrate for this bad cartpole boi
    input_cords, output_cords, leaf_names = set_initial_coords()
    [cppn] = create_cppn(genome, config, leaf_names, ['cppn_out'])
    net_builder = ESNetwork(Substrate(input_cords, output_cords), cppn, PARAMS)
    network = net_builder.create_phenotype_network_nd()
    return network
Beispiel #2
0
def reset_substrate(states):
    input_cords = []
    output_cords = [(0.0, -1.0, 0.0)]
    sign = -1
    for i in range(4):
        input_cords.append((0.0, 0.0, 0.0 + (states[i] / 10)))
    return Substrate(input_cords, output_cords)
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 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
Beispiel #5
0
def reset_substrate(states):
    input_cords = []
    output_cords = [(0.0, -1.0, -1.0)]
    sign = -1
    for i in range(4):
        input_cords.append((0.0 - i/10*sign, 0.0, states[i]/100.))
        sign *= -1
    return Substrate(input_cords, output_cords)
Beispiel #6
0
 def reset_substrate(self, input_row):
     current_inputs = self.substrate.input_coordinates
     new_input = []
     for ix,t in enumerate(current_inputs):
         t = list(t)
         offset = input_row[ix] * .5
         t[2] = t[2] + .5
         new_input.append(tuple(t))
     #self.in_shapes = new_input
     self.substrate = Substrate(new_input, self.out_shapes)
Beispiel #7
0
def execute_back_prop(genome_dict, champ_key, config):
    input_cords, output_cords, leaf_names = set_initial_coords()
    [cppn] = create_cppn(genome_dict[champ_key], config, leaf_names,
                         ['cppn_out'])
    net_builder = ESNetwork(Substrate(input_cords, output_cords), cppn, PARAMS)
    champ_output = net_builder.safe_baseline(False)
    for key in genome_dict:
        if key != champ_key:
            [cppn_2] = create_cppn(genome_dict[key], config, leaf_names,
                                   ['cppn_out'])
            es_net = ESNetwork(Substrate(input_cords, output_cords), cppn_2,
                               PARAMS)
            output = es_net.safe_baseline(True)
            es_net.optimizer.zero_grad()
            if output.requires_grad == True:
                loss_val = (champ_output - output).pow(2).mean()
                loss_val.backward()
                es_net.optimizer.step()
                es_net.map_back_to_genome(genome_dict[key], config, leaf_names,
                                          ['cppn_out'])
            else:
                print("error less fit has no grad attached")
    return
Beispiel #8
0
 def refresh(self):
     self.in_shapes = []
     self.out_shapes = [(0.0, -1.0, -1.0)]
     self.hs = HistWorker()
     self.hs.get_binance_train()
     print(self.hs.currentHists.keys())
     self.end_idx = len(self.hs.hist_shaped[0])
     self.but_target = .1
     print(self.hs.hist_shaped.shape)
     self.num_syms = self.hs.hist_shaped.shape[0]
     self.inputs = self.hs.hist_shaped[0].shape[1] + 1
     self.outputs = 1
     sign = 1
     for ix2 in range(1,self.inputs+1):
         sign *= -1
         self.in_shapes.append((0.0+(sign*.01*ix2), 0.0-(sign*.01*ix2), 0.0))
     self.substrate = Substrate(self.in_shapes, self.out_shapes)
     self.set_leaf_names()
Beispiel #9
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
def reset_substrate(states):
    input_coords = get_in_coords(states)
    return Substrate(input_coords, output_coords)