Esempio n. 1
0
    def fully_connected_nn(n_inputs, n_outputs):
        """Generate a genotype representing a fully connected neural network.

        Arguments:
            n_inputs: How many inputs the network should have.
            n_outputs: How many outputs the network should have.

        Returns: The generated genotype.
        """
        genome = Genome()

        sensors = [NodeGene(Sensor()) for _ in range(n_inputs)]
        outputs = [NodeGene(Output()) for _ in range(n_outputs)]

        connections = []

        for input_id in range(n_inputs):
            for output_id in range(n_inputs, n_inputs + n_outputs):
                connections.append(ConnectionGene(output_id, input_id))

        genome.add_genes(sensors)
        genome.add_genes(outputs)
        genome.add_genes(connections)

        return genome
Esempio n. 2
0
    def generate_genome():
        """Generate a test genome.

        Returns a genotype similar to one found in the origin NEAT paper.
        """
        ConnectionGene.pool = {}
        genome = Genome()

        nodes = [NodeGene(Sensor()) for _ in range(3)]
        nodes.append(NodeGene(Output()))
        nodes.append(NodeGene(Hidden()))

        connections = []

        for input_node_id in [0, 2, 4]:
            connections.append(ConnectionGene(3, input_node_id))

        for input_node_id in [0, 1, 3]:
            connections.append(ConnectionGene(4, input_node_id))

        genome.add_genes(nodes)
        genome.add_genes(connections)

        return genome