Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def predict(self):
     weightDict, biasDict = self.getWeightBiasDictionaries()
     model = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
     input_data, mood_data = self.transformUserData(1)
     output = model.feedforward(input_data[0])
     mood = model.roundClass(output)
     return mood
Ejemplo n.º 3
0
 def test_feedforward(self):
     weightDict, biasDict = {}, {}
     for i in range(208):
         weightDict['weight' + str(i)] = i / 8
         if i < 21:
             biasDict['bias' + str(i)] = i / 8
     network = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
     sample_data = [2, 1, 4, 5, 6, 2, 6, 7, 3, 6, 6]
     self.assertEqual(1, int(network.feedforward(sample_data)[0]))
     weightDict, biasDict = {}, {}
     for i in range(208):
         weightDict['weight' + str(i)] = i / 208
         if i < 21:
             biasDict['bias' + str(i)] = i / 208
     network = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
     sample_data = list(range(11))
     self.assertEqual(0, int(network.feedforward(sample_data)[0]))
Ejemplo n.º 4
0
    def test_feedforward(self):
        weightDict, biasDict = {}, {}
        for i in range(208):
            weightDict['weight' + str(i)] = i/8
            if i < 21:
                biasDict['bias' + str(i)] = i/8
        network = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
        sample_data = [2,1,4,5,6,2,6,7,3,6,6]
        self.assertEqual(41, network.roundClass(network.feedforward(sample_data)))
        weightDict, biasDict = {}, {}
        for i in range(208):
            weightDict['weight' + str(i)] = i/208
            if i < 21:
                biasDict['bias' + str(i)] = i/208
        network = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
        sample_data = list(range(11))
        self.assertEqual(39, network.roundClass(network.feedforward(sample_data)))

        network = MoodNeuralNetwork()
        sample_data = [4.51,0,0,0,0,0,0,0,-1,8,35]
        self.assertEqual(25, network.roundClass(network.feedforward(sample_data)))
        sample_data = [15,25,50,0,0,0,0,0,-1,-100,0]
        self.assertEqual(33, network.roundClass(network.feedforward(sample_data)))
Ejemplo n.º 5
0
 def predict(self):
     weightDict, biasDict = self.getWeightBiasDictionaries()
     model = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
     input_data, mood_data = self.transformUserData(1)
     try:
         output = model.feedforward(input_data[0])
     except:
         return -1, 0
     mood = model.roundClass(output)
     self.updateMoodPrediction(mood)
     profile = self.user.profile
     obs = Observation.objects.filter(
         user__user__username=profile.user.username)
     print("\n\n\n\n", obs, "\n\n\n\n")
     return mood, len(obs)