src/perceptron/NeuralNetwork/NeuralNetwork.py
def __backward(self, input_set: Union[list, np.ndarray],
                   predicted_output: Union[list, np.ndarray]) -> np.ndarray:
        """
        Calculates error and updates weights of all layers according to delta.
        """
        def set_delta(delta, start_index: int):
            layer = self.layers[start_index]
            layer.change_weights(delta, self.learning_rate)
            if start_index != 0:
                activation_func = self.layers[start_index - 1].activate
                error = np.dot(delta, layer.weights.T)
                next_delta = error * activation_func(layer.values, True)
                return set_delta(next_delta, start_index - 1)

        activation_func = self.layers[-1].activate
        output = self.forward(input_set)
        output_error = np.array(predicted_output) - output
        output_delta = output_error * activation_func(output, True)
        set_delta(output_delta, len(self.layers) - 1)
        return output_error

        Calculates error and updates weights of all layers according to delta.
        
Calculates error and updates weights of all layers according to delta.
Calculates error and updates weights of all layers according to delta .
def __backward(self, input_set: Union[list, np.ndarray],
                   predicted_output: Union[list, np.ndarray]) -> np.ndarray:
        def set_delta(delta, start_index: int):
            layer = self.layers[start_index]
            layer.change_weights(delta, self.learning_rate)
            if start_index != 0:
                activation_func = self.layers[start_index - 1].activate
                error = np.dot(delta, layer.weights.T)
                next_delta = error * activation_func(layer.values, True)
                return set_delta(next_delta, start_index - 1)
        activation_func = self.layers[-1].activate
        output = self.forward(input_set)
        output_error = np.array(predicted_output) - output
        output_delta = output_error * activation_func(output, True)
        set_delta(output_delta, len(self.layers) - 1)
        return output_error
def __backward ( self , input_set : Union [ list , np . ndarray ] , predicted_output : Union [ list , np . ndarray ] ) -> np . ndarray : def set_delta ( delta , start_index : int ) : layer = self . layers [ start_index ] layer . change_weights ( delta , self . learning_rate ) if start_index != 0 : activation_func = self . layers [ start_index - 1 ] . activate error = np . dot ( delta , layer . weights . T ) next_delta = error * activation_func ( layer . values , True ) return set_delta ( next_delta , start_index - 1 ) activation_func = self . layers [ - 1 ] . activate output = self . forward ( input_set ) output_error = np . array ( predicted_output ) - output output_delta = output_error * activation_func ( output , True ) set_delta ( output_delta , len ( self . layers ) - 1 ) return output_error
Calculates error and updates weights of all layers according to delta.
Calculates error and updates weights of all layers according to delta .
"""
        Calculates error and updates weights of all layers according to delta.
        """
self
input_set
Union[list, np.ndarray]
predicted_output
Union[list, np.ndarray]