def __init__(self, model_cfg: dict, args: dict = {}): for key in args: if key not in HyperNeat.args: raise Exception("Unknown argument: {}".format(key)) self.model_cfg = deepcopy(model_cfg) tmp = nn.Model.from_config(model_cfg) self.base_model = tmp print("Creating HyperNEAT with {} inputs and {} outputs".format( util.shape_size(tmp.input_shape), util.shape_size(tmp.output_shape))) self.input_shape = util.shape_size(tmp.input_shape) self.output_shape = util.shape_size(tmp.output_shape) self.neat = neat.Neat(4, 2 * len(self.base_model.layers), args)
'clear_species': 100, 'prob_add_node': 0.01, 'prob_add_conn': 0.05, 'prob_replace_weight': 0.01, 'prob_mutate_weight': 0.5, 'prob_toggle_conn': 0.01, 'prob_replace_activation': 0.1, 'std_new': 1.0, 'std_mutate': 0.01, 'activations': ['sigmoid'], 'dist_weight': 0.5, 'dist_activation': 1.0, 'dist_disjoint': 1.0 } n = neat.Neat(128, 6, neat_args) # multiprocessing pool = mp.Pool() LENGTH = 1000 times = 0 best = -float('inf') try: for i in range(1000): scores = [] pop = n.ask() # eval population for ind in pop:
'clear_species': 15, 'prob_add_node': 0.01, 'prob_add_conn': 0.5, 'prob_replace_weight': 0.01, 'prob_mutate_weight': 0.5, 'prob_toggle_conn': 0.01, 'prob_replace_activation': 0.1, 'std_new': 1.0, 'std_mutate': 0.1, 'activations': ['sigmoid'], 'dist_weight': 0.4, 'dist_activation': 1.0, 'dist_disjoint': 1.0 } n = neat.Neat(4, 2, neat_args) # pool = mp.Pool() LENGTH = 10000 times = 0 try: for i in range(1000): scores = [] pop = n.ask() # eval population for ind in pop: scores.append(fitness_cartpole(ind, steps=LENGTH)) # scores.append(pool.apply_async(fitness_xor, ((ind,))))
'clear_species': 15, 'prob_add_node': 0.001, 'prob_add_conn': 0.01, 'prob_replace_weight': 0.01, 'prob_mutate_weight': 0.5, 'prob_toggle_conn': 0.01, 'prob_replace_activation': 0.1, 'std_new': 1.0, 'std_mutate': 1.0, 'activations': ['sigmoid'], 'dist_weight': 0.05, 'dist_activation': 1.0, 'dist_disjoint': 1.0 } n = neat.Neat(2, 1, neat_args) # multiprocessing pool = mp.Pool() try: for i in range(100): scores = [] pop = n.ask() # eval population for ind in pop: scores.append(pool.apply_async(fitness_xor, ((ind, )))) scores = [s.get() for s in scores]
from httpimport import remote_repo import httpimport httpimport.INSECURE = True with remote_repo(['hello', 'neat'], base_url='http://127.0.0.1:5002'): from hello import hi import neat neat.Neat().print_neat() print(dir(hi)) hi.HelloWorld().print_hello() import_list = ['hello', 'neat'] obj_dict = {} for item in import_list: obj_dict[item] = httpimport.load(item, 'http://127.0.0.1:5002') obj_dict['neat'].Neat().print_neat() print(dir(obj_dict['hello'].hi)) obj_dict['hello'].hi.HelloWorld().print_hello()
# Note that we have access to information inside the organism objects, we could, # for example, only terminate our search once the fitness reaches a certain threshold. def fitness_assessor(organism): return organism.fitness > 15 if __name__ == '__main__': # Configure NEAT parameters custom_config = {'population_size': 500, 'num_inputs': 2, 'num_outputs': 1} # Our subclassed organism type organism_type = XOR neat_solver = neat.Neat(organism_type, custom_config, assessor_function=score_assessor) # If we don't specify a number of generations, the search runs indefinitely neat_solver.run(generations=200) # Retrieve the solvers solvers = neat_solver.get_solvers() if solvers: # Test out the solver by providing inputs to the think method organism = solvers[0] print("Solver Fitness:", organism.fitness) print("Solver outputs for XOR data:") outputs = organism.think(X)[0]
'clear_species': 100, 'prob_add_node': 0.01, 'prob_add_conn': 0.05, 'prob_replace_weight': 0.01, 'prob_mutate_weight': 0.5, 'prob_toggle_conn': 0.01, 'prob_replace_activation': 0.1, 'std_new': 1.0, 'std_mutate': 0.01, 'activations': ['sigmoid'], 'dist_weight': 0.4, 'dist_activation': 1.0, 'dist_disjoint': 1.0 } n = neat.Neat(8, 2, neat_args) # multiprocessing pool = mp.Pool() LENGTH = 1000 times = 0 best = 0 #-float('inf') try: for i in range(1000): scores = [] pop = n.ask() # eval population for ind in pop:
'clear_species': 100, 'prob_add_node': 0.01, 'prob_add_conn': 0.05, 'prob_replace_weight': 0.01, 'prob_mutate_weight': 0.5, 'prob_toggle_conn': 0.01, 'prob_replace_activation': 0.1, 'std_new': 1.0, 'std_mutate': 0.01, 'activations': ['sigmoid'], 'dist_weight': 0.5, 'dist_activation': 1.0, 'dist_disjoint': 1.0 } n = neat.Neat(96//8*96//8*1, 3, neat_args) pool = mp.Pool() LENGTH = 1000 times = 0 best = -float('inf') try: for i in range(1000): scores = [] pop = n.ask() for ind in pop: # scores.append(fitness_car_race(ind, render=True, steps=LENGTH)) scores.append(pool.apply_async(fitness_car_race, ((ind, False, LENGTH))))
'clear_species': 100, 'prob_add_node': 0.01, 'prob_add_conn': 0.05, 'prob_replace_weight': 0.01, 'prob_mutate_weight': 0.5, 'prob_toggle_conn': 0.01, 'prob_replace_activation': 0.1, 'std_new': 1.0, 'std_mutate': 0.01, 'activations': ['sigmoid'], 'dist_weight': 0.5, 'dist_activation': 1.0, 'dist_disjoint': 1.0 } n = neat.Neat(24, 4, neat_args) # multiprocessing pool = mp.Pool() LENGTH = 1000 times = 0 best = 0 #-float('inf') try: for i in range(1000): scores = [] pop = n.ask() # eval population for ind in pop: