Esempio n. 1
0
    def errors(self, output, labels):
        """ Calcultes the errors for the output and hidden layers"""
        labels = Matrix.from_array(labels)
        output_errors = labels.add(output.negative)
        hidden_errors = Matrix.matmul(self.ho_weights.T, output_errors)

        return hidden_errors, output_errors
Esempio n. 2
0
 def train(self, inputs, labels, stocastic=True):
     """ Trains the neural net, with the option of stocastic
         or batch training
     """
     # Converting inputs to matrix object
     inputs = Matrix.from_array(inputs)
     hidden, output = self.feed_forward(inputs)
     if stocastic:
         hidden_gradient, delta_w_ih, output_gradient, delta_w_ho = \
             self.back_propogate(inputs, hidden, output, labels)
         self.output_bias.add(output_gradient, inplace=True)
         self.ho_weights.add(delta_w_ho, inplace=True)
         self.hidden_bias.add(hidden_gradient, inplace=True)
         self.ih_weights.add(delta_w_ih, inplace=True)
     else:
         return self.back_propogate(inputs, hidden, output, labels)
Esempio n. 3
0
 def predict(self, inputs):
     """ Method to test the neural net for a given input"""
     inputs = Matrix.from_array(inputs)
     return self.feed_forward(inputs)[1].data[0][0]