Exemple #1
0
 def test_loss(self):
     network = MoodNeuralNetwork()
     sample_data = np.array(list(range(100)))
     sample_real = [x + 0.1 for x in list(range(0,100))]
     sample_real = np.array(sample_real)
     self.assertEqual(0.009999999999999724, network.loss(sample_data, sample_real))
     sample_real = list(range(0,100))
     self.assertEqual(0, network.loss(sample_data, sample_real))
Exemple #2
0
 def test_train(self):
     weightDict, biasDict = {}, {}
     for i in range(208):
         weightDict['weight' + str(i)] = i
         if i < 21:
             biasDict['bias' + str(i)] = i
     network = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
     sample_data = np.array([[2,1,4,5,6,2,6,7,3,6,6]])
     true = np.array([30])
     prediction = network.feedforward(sample_data[0])
     loss1 = network.loss(true, prediction)
     network.train(sample_data, true)
     prediction = network.feedforward(sample_data[0])
     loss2 = network.loss(true, network.roundClass(prediction))
     self.assertTrue(loss2 < loss1)