def generate_genome_with_hidden_units(n_input, n_output, n_hidden=3): # nodes node_genes = {} for i in range(n_output + n_hidden): node_genes = add_node(node_genes, key=i) # connections # input to hidden connection_genes = {} input_hidden_tuples = list( product(list(range(-1, -n_input - 1, -1)), list(range(n_output, n_output + n_hidden)))) for tuple_ in input_hidden_tuples: connection_genes = add_connection(connection_genes, key=tuple_) # hidden to output hidden_output_tuples = list( product(list(range(n_output, n_output + n_hidden)), list(range(0, n_output)))) for tuple_ in hidden_output_tuples: connection_genes = add_connection(connection_genes, key=tuple_) # initialize genome genome = Genome(key=1) genome.node_genes = node_genes genome.connection_genes = connection_genes return genome
def generate_genome_given_graph(graph, connection_weights): genome = Genome(key='foo') unique_node_keys = [] input_nodes = [] for connection in graph: for node_key in connection: if node_key not in unique_node_keys: unique_node_keys.append(node_key) if node_key < 0: input_nodes.append(node_key) input_nodes = set(input_nodes) unique_node_keys = list( set(unique_node_keys + genome.get_output_nodes_keys()) - input_nodes) nodes = {} for node_key in unique_node_keys: node = NodeGene(key=node_key).random_initialization() node.set_mean(0) node.set_std(STD) nodes[node_key] = node connections = {} for connection_key, weight in zip(graph, connection_weights): connection = ConnectionGene(key=connection_key) connection.set_mean(weight) connection.set_std(STD) connections[connection_key] = connection genome.connection_genes = connections genome.node_genes = nodes return genome
def generate_genome_without_hidden_units(): # output nodes node_genes = {} node_genes = add_node(node_genes, key=0) connection_genes = {} connection_genes = add_connection(connection_genes, key=(-1, 0)) connection_genes = add_connection(connection_genes, key=(-2, 0)) genome = Genome(key=1) genome.node_genes = node_genes genome.connection_genes = connection_genes return genome