pylearn.neural_network package¶
Submodules¶
pylearn.neural_network.activation module¶
- class pylearn.neural_network.activation.Activation(function: classmethod, derivative: classmethod)[source]¶
Bases:
LayerDefines the activation functions for a layer. Inherits from Layer to compute forward pass and backpropagation with the activation function.
- Attributes:
- function (function):
Activation function
- derivative (function):
Derivative of the activation function
pylearn.neural_network.activation_functions module¶
- class pylearn.neural_network.activation_functions.ReLU[source]¶
Bases:
ActivationDefines the ReLU activation function for a layer. Inherits from Activation and passes the function and derivative.
- class pylearn.neural_network.activation_functions.Sigmoid[source]¶
Bases:
ActivationDefines the Sigmoid activation function for a layer. Inherits from Activation and passes the function and derivative.
- class pylearn.neural_network.activation_functions.Softmax[source]¶
Bases:
ActivationDefines the Softmax activation function for a layer. Inherits from Activation and passes the function and derivative.
- class pylearn.neural_network.activation_functions.Tanh[source]¶
Bases:
ActivationDefines the Tanh activation function for a layer. Inherits from Activation and passes the function and derivative.
pylearn.neural_network.dense_layer module¶
- class pylearn.neural_network.dense_layer.Dense_layer(input_size: int, output_size: int)[source]¶
Bases:
LayerDefines the dense layer structure (fully connected layer) to use the forward pass and backpropagation.
- Attributes:
- weights (numpy.ndarray):
Weight matrix of the layer
- bias (numpy.array):
Bias vector of the layer
- backpropagation(output_gradient: ndarray, learning_rate=0.1) ndarray[source]¶
Updates the parameters depending on the derivatives.
- Parameters:
- output_gradient (numpy.array):
input of the next layer (output = ∂E/∂Y)
- learning_rate (numpy.array, optional):
hyperparameter to determine the step size of updates, default: 0.01
- Returns:
Derivative of the function as array
pylearn.neural_network.layer module¶
pylearn.neural_network.loss_functions module¶
- pylearn.neural_network.loss_functions.cross_entropy_loss(y_true: ndarray, y_pred: ndarray) float[source]¶
Calculates the Cross Entropy Loss between the estimated values and the actual value.
- Parameters:
- y_true (numpy.ndarray):
Correct output
- y_pred (numpy.ndarray):
Predicted output
- Returns:
Error as float
- pylearn.neural_network.loss_functions.cross_entropy_loss_derivative(y_true: ndarray, y_pred: ndarray) ndarray[source]¶
Calculates the derivative (∂E/∂Y) of the Cross Entropy Loss between the estimated values and the actual value.
- Parameters:
- y_true (numpy.ndarray):
Correct output
- y_pred (numpy.ndarray):
Predicted output
- Returns:
Derivative of CE as array
- pylearn.neural_network.loss_functions.mse(y_true: ndarray, y_pred: ndarray) float[source]¶
Calculates the Mean Squared Error between the estimated values and the actual value.
- Parameters:
y_true (numpy.ndarray): Correct output y_pred (numpy.ndarray): Predicted output
- Returns:
Error as float
- pylearn.neural_network.loss_functions.mse_derivative(y_true: ndarray, y_pred: ndarray) ndarray[source]¶
Calculates the derivative (∂E/∂Y) of the Mean Squared Error (MSE) between the estimated values and the actual value.
- Parameters:
- y_true (numpy.ndarray):
Correct output
- y_pred (numpy.ndarray):
Predicted output
- Returns:
Derivative of MSE as array
pylearn.neural_network.network module¶
- class pylearn.neural_network.network.NeuralNetwork[source]¶
Bases:
object- static fit(X: ndarray, Y: ndarray, network: list, loss_function: classmethod, loss_derivative: classmethod, epochs=1000, learning_rate=0.1, log_error=False, log_details=False, log_duration=True) None[source]¶
Trains the neural network by performing forward pass and back propagation and also computes the error for every epoch.
To log: log_details, log_error
- Parameters:
- X (numpy.array):
Training input
- Y (numpy.array):
Training output
- network (list[Layer]):
List of network layers
- loss_function (classmethod):
Loss function to compute the error
- loss_derivative (classmethod):
Derivative of the loss function to perform backpropagation
- epochs (int, optional):
Hyperparameter, number of learning iterations, default: 1000
- learning_rate (int, optional):
Hyperparameter, default: 0.01
- log_error (bool, optional):
Logs the error of each iteration, default: False
- log_details (bool, optional):
Logs the parameters of each layer, default: False
- log_duration (bool, optional):
Logs the duration of the training, default: True
- Returns:
None