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)
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)
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)
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)
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)
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()
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)
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)
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"
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)
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
def test_AddTwoNeuronsToNetwork(self): net = NeuralNet() net.add_neuron() net.add_neuron() self.assertTrue(len(net.Neurons) == 2)
def test_CreateNetwork(self): net = NeuralNet() self.assertTrue(net is not None)
def test_AddSubNetToNetwork(self): net = NeuralNet() net.add_subnet('test2', 'test2.pickle.xml') self.assertTrue(len(net.Neurons) == 1)
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