Ejemplo n.º 1
0
 def test_build_layer_inputs_and_outputs(self):
     listCLayer = [random.randint(2, 4) for _ in xrange(4)]
     net = build_net(listCLayer)
     listDblInput = randlist(-1.0, 1.0, net.cInputs)
     listIn, listOut = nn.build_layer_inputs_and_outputs(net, listDblInput)
     self.assertEqual(len(listIn), len(listOut))
     listZip = zip(listIn, listOut, listCLayer, listCLayer[1:], net.listLayer)
     for listDblIn, listDblOut, cSizeIn, cSizeOut, layer in listZip:
         self.assertEqual(cSizeIn, len(listDblIn))
         self.assertEqual(cSizeOut, len(listDblOut))
         self.assertEqual(listDblOut, nn.feed_forward_layer(layer, listDblIn))
Ejemplo n.º 2
0
 def test_build_layer_inputs_and_outputs(self):
     listCLayer = [random.randint(2,4) for _ in xrange(4)]
     net = build_net(listCLayer)
     listDblInput = randlist(-1.0,1.0,net.cInputs)
     listIn,listOut = nn.build_layer_inputs_and_outputs(net, listDblInput)
     self.assertEqual(len(listIn),len(listOut))
     listZip = zip(listIn,listOut,listCLayer,listCLayer[1:],net.listLayer)
     for listDblIn,listDblOut,cSizeIn,cSizeOut,layer in listZip:
         self.assertEqual(cSizeIn, len(listDblIn))
         self.assertEqual(cSizeOut, len(listDblOut))
         self.assertEqual(listDblOut,nn.feed_forward_layer(layer,listDblIn))
Ejemplo n.º 3
0
 def test_feed_forward_layer(self):
     listPcpt = []
     cInput = random.randint(5, 10)
     cPcpt = random.randint(5, 10)
     listDblTarget = randlist(-0.75, 0.75, cPcpt)
     listDblInput = randlist(-1.0, 1.0, cInput)
     for ix, dblTarget in enumerate(listDblTarget):
         listDblProduct = randlist_for_sum(dblTarget, cInput + 1, 0.5)
         listDblW = []
         for dblProduct, dblInput in zip(listDblProduct, listDblInput):
             listDblW.append(dblProduct / dblInput)
         listPcpt.append(nn.Perceptron(listDblW, listDblProduct[-1], ix))
     layer = nn.NeuralNetLayer(cInput, listPcpt)
     listDblOutput = nn.feed_forward_layer(layer, listDblInput)
     listDblLogit = [logit(dbl) for dbl in listDblOutput]
     for dblTarget, dblLogit in zip(listDblTarget, listDblLogit):
         self.assertAlmostEqual(dblTarget, dblLogit, 4)
Ejemplo n.º 4
0
 def test_feed_forward_layer(self):
     listPcpt = []
     cInput = random.randint(5,10)
     cPcpt = random.randint(5,10)
     listDblTarget = randlist(-0.75, 0.75, cPcpt)
     listDblInput = randlist(-1.0,1.0,cInput)
     for ix,dblTarget in enumerate(listDblTarget):
         listDblProduct = randlist_for_sum(dblTarget, cInput+1, 0.5)
         listDblW = []
         for dblProduct,dblInput in zip(listDblProduct,listDblInput):
             listDblW.append(dblProduct/dblInput)
         listPcpt.append(nn.Perceptron(listDblW, listDblProduct[-1] ,ix))
     layer = nn.NeuralNetLayer(cInput, listPcpt)
     listDblOutput = nn.feed_forward_layer(layer, listDblInput)
     listDblLogit = [logit(dbl) for dbl in listDblOutput]
     for dblTarget,dblLogit in zip(listDblTarget,listDblLogit):
         self.assertAlmostEqual(dblTarget,dblLogit, 4)