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 retrain(self):
        weightDict, biasDict = self.getWeightBiasDictionaries()
        model = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
        input_data, mood_data = self.transformUserData(7)
        model.train(input_data, mood_data)
        weightDict = model.getWeights()
        weights = []
        for i in range(len(weightDict)):
            weights.append(weightDict["weight" + str(i)])
        self.setWeightsWeights(weights)

        biasDict = model.getBiases()
        biases = []
        for i in range(len(biasDict)):
            biases.append(biasDict["bias" + str(i)])
        self.setWeightsBias(biases)

        return True