Esempio n. 1
0
    def spawn(self):
        """Spawn Individual instances"""
        # Construction of the neural network
        neural_network = NeuralNetwork(
            nb_inter_neuron=self.nb_inter_neuron(),
            memory_size=self.memory_size(),
        )
        nb_neuron_type = neural_network.nb_neuron_type
        random.nid = lambda: (random.randint(NeuralNetwork.MINIMAL_NEURON_ID,
                                             neural_network.nb_neuron))
        random.eid = lambda: (random.nid(), random.nid())
        neural_network.build(
            edges=(random.eid() for _ in range(self.nb_edges())),
            neuron_types=(self.random_neuron_type() for _ in range(nb_neuron_type))
        )

        # Spawn of the individual itself
        return Individual(
            neural_network=neural_network,
            energy=10,
        )
Esempio n. 2
0
    def spawn(self):
        """Spawn Individual instances"""
        # Construction of the neural network
        neural_network = NeuralNetwork(
            nb_inter_neuron=self.nb_inter_neuron(),
            memory_size=self.memory_size(),
        )
        nb_neuron_type = neural_network.nb_neuron_type
        random.nid = lambda: (random.randint(NeuralNetwork.MINIMAL_NEURON_ID,
                                             neural_network.nb_neuron))
        random.eid = lambda: (random.nid(), random.nid())
        neural_network.build(edges=(random.eid()
                                    for _ in range(self.nb_edges())),
                             neuron_types=(self.random_neuron_type()
                                           for _ in range(nb_neuron_type)))

        # Spawn of the individual itself
        return Individual(
            neural_network=neural_network,
            energy=10,
        )
 def test_nothing_to_clean(self):
     nn = 'neuron(1,i). neuron(2,o). edge(1,2). output(2).'
     self.assert_cleaning(nn, NeuralNetwork.cleaned(nn))
     self.assert_cleaning(nn, 'neuron(1,i) neuron(2,o) edge(1,2) output(2)')
 def test_simple_clean(self):
     nn = 'neuron(1,i). neuron(2,i). neuron(3,o). output(3). edge(1,3). edge(1,2).'
     self.assert_cleaning(nn, NeuralNetwork.cleaned(nn))
     self.assert_cleaning(nn, 'neuron(1,i) neuron(3,o) edge(1,3) output(3)')
 def test_no_atoms(self):
     nn = ''
     self.assert_cleaning(nn, NeuralNetwork.cleaned(nn))
     self.assert_cleaning(nn, '')
 def test_nothing_to_clean(self):
     nn = 'neuron(1,i). neuron(2,o). edge(1,2). output(2).'
     self.assert_cleaning(nn, NeuralNetwork.cleaned(nn))
     self.assert_cleaning(nn, 'neuron(1,i) neuron(2,o) edge(1,2) output(2)')
 def test_simple_clean(self):
     nn = 'neuron(1,i). neuron(2,i). neuron(3,o). output(3). edge(1,3). edge(1,2).'
     self.assert_cleaning(nn, NeuralNetwork.cleaned(nn))
     self.assert_cleaning(nn, 'neuron(1,i) neuron(3,o) edge(1,3) output(3)')
 def test_no_atoms(self):
     nn = ''
     self.assert_cleaning(nn, NeuralNetwork.cleaned(nn))
     self.assert_cleaning(nn, '')