Ejemplo n.º 1
0
 def test_setWeights(self):
     weightDict = {}
     for i in range(208):
         weightDict['weight' + str(i)] = np.random.normal()
     model = MoodNeuralNetwork()
     self.assertNotEqual(weightDict, model.getWeights())
     self.assertTrue(model.setWeights(weightDict))
     self.assertEqual(weightDict, model.getWeights())
Ejemplo n.º 2
0
 def test_getWeights(self):
     weightDict, biasDict = {}, {}
     for i in range(208):
         weightDict['weight' + str(i)] = np.random.normal()
         if i < 21:
             biasDict['weight' + str(i)] = np.random.normal()
     model = MoodNeuralNetwork(weights=weightDict, biases=biasDict)
     self.assertEqual(weightDict, model.getWeights())
     self.assertTrue(model.getWeights())
Ejemplo n.º 3
0
    def setWeightsWeights(self, weights_list=False):
        if weights_list:
            if len(weights_list) != 208:
                return False

            self.weights_int_list = ",".join(str(x) for x in weights_list)
        else:
            model = MoodNeuralNetwork()
            weightDict = model.getWeights()
            weights = []
            for i in range(len(weightDict)):
                weights.append(weightDict["weight" + str(i)])
            self.setWeightsWeights(weights)
        return True
Ejemplo n.º 4
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