Esempio n. 1
0
 def test_RemoveLink(self):
     net = NeuralNet()
     n1 = net.add_neuron()
     n2 = net.add_neuron()
     lnk = net.add_link(n1, n2)
     self.assertTrue(len(net.Neurons) == 2)
     self.assertTrue(len(n1.Incoming) == 0)
     self.assertTrue(len(n1.Outgoing) == 1)
     self.assertTrue(n1.Outgoing[0] == lnk)
     self.assertTrue(len(n2.Incoming) == 1)
     self.assertTrue(len(n2.Outgoing) == 0)
     self.assertTrue(n2.Incoming[0] == lnk)
     self.assertEqual(n1.is_connected_outgoing(n2), lnk)
     self.assertEqual(n1.is_connected_incoming(n2), None)
     self.assertEqual(n2.is_connected_outgoing(n1), None)
     self.assertEqual(n2.is_connected_incoming(n1), lnk)
     net.remove_link(lnk)
     self.assertTrue(len(net.Neurons) == 2)
     self.assertTrue(len(n1.Incoming) == 0)
     self.assertTrue(len(n1.Outgoing) == 0)
     self.assertTrue(len(n2.Incoming) == 0)
     self.assertTrue(len(n2.Outgoing) == 0)
     self.assertEqual(n1.is_connected_outgoing(n2), None)
     self.assertEqual(n1.is_connected_incoming(n2), None)
     self.assertEqual(n2.is_connected_outgoing(n1), None)
     self.assertEqual(n2.is_connected_incoming(n1), None)
Esempio n. 2
0
 def test_CanCreateTwoLinksInOppositeDirection(self):
     net = NeuralNet()
     n1 = net.add_neuron()
     n2 = net.add_neuron()
     lnk1 = net.add_link(n1, n2)
     lnk2 = net.add_link(n2, n1)
     self.assertNotEqual(lnk1, lnk2)
Esempio n. 3
0
 def test_CantCreateTwoLinksInSameDirection(self):
     net = NeuralNet()
     n1 = net.add_neuron()
     n2 = net.add_neuron()
     lnk1 = net.add_link(n1, n2)
     lnk2 = net.add_link(n1, n2)
     self.assertEqual(lnk1, lnk2)
Esempio n. 4
0
 def test_CreateTwoSeparateDifferentSizedNetworks(self):
     net1 = NeuralNet()
     net1.add_neuron()
     net1.add_neuron()
     net2 = NeuralNet()
     net2.add_neuron()
     net2.add_neuron()
     net2.add_neuron()
     self.assertTrue(len(net1.Neurons) == 2)
     self.assertTrue(len(net2.Neurons) == 3)
     self.assertFalse(net1 == net2)
Esempio n. 5
0
 def test_LinkTwoNeurons(self):
     net = NeuralNet()
     n1 = net.add_neuron()
     n2 = net.add_neuron()
     lnk = net.add_link(n1, n2)
     self.assertTrue(len(net.Neurons) == 2)
     self.assertTrue(len(n1.Incoming) == 0)
     self.assertTrue(len(n1.Outgoing) == 1)
     self.assertTrue(n1.Outgoing[0] == lnk)
     self.assertTrue(len(n2.Incoming) == 1)
     self.assertTrue(len(n2.Outgoing) == 0)
     self.assertTrue(n2.Incoming[0] == lnk)
     self.assertEqual(n1.is_connected_outgoing(n2), lnk)
     self.assertEqual(n1.is_connected_incoming(n2), None)
     self.assertEqual(n2.is_connected_outgoing(n1), None)
     self.assertEqual(n2.is_connected_incoming(n1), lnk)
Esempio n. 6
0
 def setUp(self):
     self.net = net = NeuralNet()
     # this should load a subnet, as a neuron
     self.sub = net.add_subnet('test2', 'test2.pickle.xml')
     # add neurons to our net to attach to the subnet's interface
     self.in1 = net.add_neuron()
     self.in2 = net.add_neuron()
     self.out1 = net.add_neuron()
     self.out2 = net.add_neuron()
Esempio n. 7
0
 def setUp(self):
     self.net = net = NeuralNet()
     self.sub = sub = net.add_subnet('test2', 'test2.pickle.xml')
     self.in1 = net.add_neuron()
     self.in2 = net.add_neuron()
     self.out1 = net.add_neuron()
     self.out2 = net.add_neuron()
     net.add_link(self.in1, sub, 1.0)
     net.add_link(self.in2, sub, -1.0)
     net.add_link(sub, self.out1, 1.0)
     net.add_link(sub, self.out2, 1.0)
Esempio n. 8
0
 def test_RemoveNeuronNoLinks(self):
     net = NeuralNet()
     n1 = net.add_neuron()
     n2 = net.add_neuron()
     self.assertTrue(len(net.Neurons) == 2)
     net.remove_neuron(n2)
     self.assertTrue(len(net.Neurons) == 1)
     self.assertTrue(net.Neurons[0] == n1)
     n2 = net.add_neuron()
     self.assertTrue(len(net.Neurons) == 2)
     net.remove_neuron(n1)
     self.assertTrue(len(net.Neurons) == 1)
     self.assertTrue(net.Neurons[0] == n2)
Esempio n. 9
0
 def setUp(self):
     net = NeuralNet()
     self.in1 = net.add_neuron()
     self.in2 = net.add_neuron()
     self.mid1 = net.add_neuron()
     self.out1 = net.add_neuron()
     self.out2 = net.add_neuron()
     net.add_link(self.in1, self.mid1, 1.0)
     net.add_link(self.in2, self.mid1, 1.0)
     net.add_link(self.mid1, self.out1, 1.0)
     net.add_link(self.mid1, self.out2, 1.0)
     self.net = net
     self.in1.Name = "input-1"
     self.in2.Name = "input-2"
     self.mid1.Name = "mid-1"
     self.out1.Name = "output-1"
     self.out2.Name = "output-2"
Esempio n. 10
0
 def setUp(self):
     self.net = net = NeuralNet()
     self.sub = net.add_subnet('test2', 'test2.pickle.xml')
     # add neurons to our net to attach to the subnet's interface
     self.in1 = net.add_neuron()
     self.in2 = net.add_neuron()
     self.out1 = net.add_neuron()
     self.out2 = net.add_neuron()
     # attach outer net to inner net
     self.link1 = net.add_link(self.in1, self.sub)
     self.link2 = net.add_link(self.in2, self.sub)
     self.link3 = net.add_link(self.sub, self.out1)
     self.link4 = net.add_link(self.sub, self.out2)
Esempio n. 11
0
 def setUp(self):
     net = NeuralNet()
     n1 = net.add_neuron()
     n1.Name = "input"
     n2 = net.add_neuron()
     n2.Name = "output"
     net.add_link(n1, n2)
     self.net = net
Esempio n. 12
0
 def test_AddTwoNeuronsToNetwork(self):
     net = NeuralNet()
     net.add_neuron()
     net.add_neuron()
     self.assertTrue(len(net.Neurons) == 2)
Esempio n. 13
0
 def test_CreateNetwork(self):
     net = NeuralNet()
     self.assertTrue(net is not None)
Esempio n. 14
0
 def test_AddSubNetToNetwork(self):
     net = NeuralNet()
     net.add_subnet('test2', 'test2.pickle.xml')
     self.assertTrue(len(net.Neurons) == 1)
Esempio n. 15
0
 def setUp(self):
     net = NeuralNet()
     self.in1 = net.add_neuron()
     self.in2 = net.add_neuron()
     self.mid1 = net.add_neuron()
     self.out1 = net.add_neuron()
     self.out2 = net.add_neuron()
     net.add_link(self.in1, self.mid1, 1.0)
     net.add_link(self.in2, self.mid1, -1.0)
     net.add_link(self.mid1, self.out1, 1.0)
     net.add_link(self.mid1, self.out2, 1.0)
     self.net = net