Components

Here is a list of classes in the package.

Overview:

class neural_network.Network(num_features: int, num_hidden_layers: int, neuron_counts: List[int], num_classes: int = 2, regression: bool = False, leak: float = 0.01, learning_rate: float = 0.01, adaptive: bool = False, gamma: float = 0.9, he_weights: bool = False)[source]

Class to represent the whole network.

__init__(num_features: int, num_hidden_layers: int, neuron_counts: List[int], num_classes: int = 2, regression: bool = False, leak: float = 0.01, learning_rate: float = 0.01, adaptive: bool = False, gamma: float = 0.9, he_weights: bool = False)[source]

Constructor method

Parameters:
  • num_features (int) – The number of features for the network

  • num_hidden_layers (int) – The total number of hidden Layers in the Network

  • neuron_counts (List[int]) – A list of numbers of Neurons for each hidden Layer

  • num_classes (int) – The number of classes for the classification task

  • regression (bool) – Whether we are performing regression or not (if False we are performing classification)

  • leak (float) – The leak rate of LeakyReLU

  • learning_rate (float) – The learning rate of the network

  • adaptive (bool) – Whether we wish to have an adaptive learning rate or not

  • gamma (float) – The adaptive learning rate parameter

  • he_weights (bool) – Whether we wish to initialise the weights according to He or not

_activate_output_layer(z_list: List[float]) List[float][source]

Activates the values from the output_layer using the Softmax activation function.

Parameters:

z_list (List[float]) – The pre-activated values from the output layer in a classification problem

Returns:

The List of softmax probabilities

Return type:

List[float]

_calculate_pre_activated_value(left_layer: Layer, right_neuron: Neuron) float[source]

Given a left_layer and a right_neuron, this calculates the activation function and value from the left_layer and propagates this value to the right_neuron

Parameters:
  • left_layer (Layer) – The current left_layer in forward propagation

  • right_neuron (Neuron) – The current right_neuron in forward propagation

Return type:

The value returned by the TransferFunction before activation

back_propagate_bias(neuron: Neuron)[source]

Uses the bias gradients of all datapoints (for this specific neuron) to perform gradient descent and calculate a new bias for this neuron.

neuronNeuron

The Neuron whose bias we are interested in updating

back_propagate_weight(edge: Edge)[source]

Uses the loss gradients of all datapoints (for this specific edge) to perform gradient descent and calculate a new weight for this edge.

edgeEdge

The Edge whose weight we are interested in updating

forward_pass_one_datapoint(x: array) List[float][source]

Performs a forward pass for one datapoint, excluding the ground truth value. This method returns the predicted value in the final neuron in the output layer.

Parameters:

x (np.array) – The input value, with all features

Returns:

The softmax probabilities of each class (for classification) or the predicted regression value (for regression)

Return type:

List[float]

get_edges() List[List[List[Edge]]][source]

Getter method for edges

Returns:

A list of Edges

Return type:

List[List[List[Edge]]]

get_layers() List[Layer][source]

Getter method for layers

Returns:

A list of Layers

Return type:

List[Layer]

get_neuron_counts() List[int][source]

Getter method for neuron_counts.

Returns:

A list of numbers of neurons per layer

Return type:

List[int]

is_regressor() bool[source]

Getter method for regression.

Returns:

Whether we do regression or classification

Return type:

bool

store_gradient_of_loss(edge: Edge, target: float, first: bool)[source]

Calculates the gradient of the loss function with respect to one weight (assigned to the edge) based on the values at edges of future layers. One part of the back propagation process.

edgeEdge

The Edge containing the weight we are interested in

targetint

The target value for the final output neuron for this specific datapoint

firstbool

Determines whether we find the bias gradient or not

visualise_network(title: str = '')[source]

Uses the networkx package to visualise the network.

Parameters:

title (str [Optional, Default='']) – An optional title for the network.