Layer Class for Neural Network¶
Author: Cole Howard
-
class
finnegan.layer.
Layer
(num_neurons, vector_size)¶ A matrix representation of the neurons in a layer Inspired by: I Am Trask http://iamtrask.github.io/2015/07/12/basic-python-network/
Parameters: - num_neurons (int) – The number of instances of the class Neuron in each layer.
- vector_size (int) – The number of inputs from the previous layer/original input. Also, equivalent to the length of incoming input vector.
-
weights
¶ numpy array
A matrix reprsentation of the weight space. Each column represents a neurnon in the layer. Each entry in those columns is the value of a weight in that neuron.
-
mr_output
¶ numpy array
Output of the layer
-
mr_input
¶ numpy array
Input vector from the layer below (or original input)
-
deltas
¶ numpy array
Calculated change in the weightspace for the backprop
-
l_rate
¶ float
The learning rate for the update weight method
-
reg_rate
¶ float
The factor by which the weights are adjusted for regularization to prevent overfitting.
-
_act_derivative
(vector)¶ Calculate the derivative of the activation function
Parameters: vector (numpy array) – A vector representing the most recent output of a given layer Returns: Return type: numpy array
-
_layer_level_backprop
(output, layer_ahead, target_vector, hidden=True)¶ Calculates the error at this level
Parameters: - layer_ahead (object) – The instance of Layer that this layer’s output is connected to
- target_vector (numpy array) – A representation of the expected output of the net for the original vector input on this particular pass
- hidden (bool) – Whether or not the current layer is hidden (default: True)
Returns: For acknoledgment of execution
Return type: True
-
_update_weights
()¶ Update the weights of each neuron based on the backprop calculation
-
_vector_pass
(vector, do_dropout=True)¶ Takes the vector through the neurons of the layer
Parameters: - vector (numpy array) – The input array to the layer
- do_dropout (bool) – Whether or not weight dropout should happen as the vector passes through the layer
Returns: The ouput of the layer
Return type: numpy array