Home Reference Source
public class | source

FullyConnected

Extends:

EstimatorClassifier → FullyConnected

Constructor Summary

Public Constructor
public

constructor(optionsUser: Object)

Constructor.

Member Summary

Public Members
public

Boolean matrix of connectivity between each pair of nodes in subsequent layers.

public
public

Number of nodes (including bias nodes) in each layer of the network.

public
public
public
public
public

Weights between each pair of nodes in subsequent layers.

Method Summary

Public Methods
public

Get the activation function value for the specified input.

public

Get the function value for the derivative of the activation function for the specified input.

public

Calculate the squared error between the network outputs for a sample and the specified outputs.

public

Calculate root-mean-square error of the network on some data set.

public

deltaRule(activations: Array<Array<number>>, outputs: Array<Array<number>>, targets: Array<number>): Array<Array<number>>

Apply the delta rule to the result of a forward pass through the network, expressed by the specified activations and outputs.

public

Pass a sample through the network, calculating the activations and outputs for all nodes in the network.

public

Randomly initialize the weights for the neural network.

public

predict(X: *): *

public

setWeights(weights: *)

Manually set the weights matrices of the network.

public

train(X: *, y: *)

public

trainEpoch(X: Array<Array<number>>, y: Array<mixed>)

Train the network for one epoch.

public

Train the network on a single sample

Inherited Summary

From class Estimator
public abstract

predict(X: Array<Array<number>>): Array<mixed>

Make a prediction for a data set.

public abstract

train(X: Array<Array<number>>, y: Array<mixed>)

Train the supervised learning algorithm on a dataset.

Public Constructors

public constructor(optionsUser: Object) source

Constructor. Initialize class members and store user-defined options.

Params:

NameTypeAttributeDescription
optionsUser Object
  • optional

User-defined options

optionsUser.numInputs number
  • optional
  • default: 'auto'

Number of features each input sample has. The first layer of the network has this (plus one bias node) as the number of nodes. Defaults to 'auto', which determines the number of input nodes on the dimensionality of the training data upon the training call

optionsUser.numOutputs number
  • optional
  • default: 'auto'

Number of possible outputs for the network. The final layer of the network has this as the number of nodes. Defaults to 'auto', which determines the number of input nodes on the number of unique labels in the data upon the training call

optionsUser.hiddenLayers Array<number>
  • optional
  • default: []

Number of nodes in the hidden layers. Each entry in this array corresponds to a single hidden layer

optionsUser.numEpochs number
  • optional
  • default: 20

Number of epochs (i.e., passes over all training data) to train the network for

optionsUser.learningRate number
  • optional
  • default: 0.01

Learning rate for training

Public Members

public connectivity: Array<Array<Array<boolean>>> source

Boolean matrix of connectivity between each pair of nodes in subsequent layers. For format, see FullyConnected#weights.

public hiddenLayers: * source

public layers: Array<number> source

Number of nodes (including bias nodes) in each layer of the network. Filled at the start of training.

public learningRate: * source

public numEpochs: * source

public numInputs: * source

public numOutputs: * source

public weights: Array<Array<Array<number>>> source

Weights between each pair of nodes in subsequent layers. Each entry in the main array contains a matrix of weights between the nodes in that layer and the nodes in the next layer. This includes entries for weights between unconnected (e.g., where the output node is a bias node) nodes

Public Methods

public activationFunction(a: number): number source

Get the activation function value for the specified input.

Params:

NameTypeAttributeDescription
a number

Input value

Return:

number

Return value of activation function applied to input value

public activationFunctionDerivative(a: number): number source

Get the function value for the derivative of the activation function for the specified input.

Params:

NameTypeAttributeDescription
a number

Input value

Return:

number

Return value of derivative of activation function applied to input value

public calculateError(x: Array<number>, y: number): number source

Calculate the squared error between the network outputs for a sample and the specified outputs.

Params:

NameTypeAttributeDescription
x Array<number>

Input sample

y number

Sample label

Return:

number

Sum of squared errors between the outputs corresponding to the sample label and the outputs obtained passing the sample through the network

public calculateRMSE(X: Array<Array<number>>, y: Array<mixed>): number source

Calculate root-mean-square error of the network on some data set.

Params:

NameTypeAttributeDescription
X Array<Array<number>>

Features of samples to calculate RMSE for

y Array<mixed>

Labels of samples

Return:

number

Root-mean-squared error

public deltaRule(activations: Array<Array<number>>, outputs: Array<Array<number>>, targets: Array<number>): Array<Array<number>> source

Apply the delta rule to the result of a forward pass through the network, expressed by the specified activations and outputs. The network targets corresponding to the forward pass need to be specified too.

Params:

NameTypeAttributeDescription
activations Array<Array<number>>

Network activations for each node in each layer

outputs Array<Array<number>>

Network outputs (i.e., the activations passed through the activation function) for each node in each layer

targets Array<number>

Network targets for the final layer

Return:

Array<Array<number>>

Deltas calculated for each node in each layer. The deltas for the bias nodes are not calculated, and set to 0

public forwardPass(x: Array<number>): Array source

Pass a sample through the network, calculating the activations and outputs for all nodes in the network.

Params:

NameTypeAttributeDescription
x Array<number>

Data point features

Return:

Array

Array with two elements: containing the activations and outputs, respectively, for each node in the network

public initializeWeights() source

Randomly initialize the weights for the neural network. For each subsequent pair of layers, where the first has n nodes and the second n' nodes, initialize an matrix with n rows and n' columns. Each cell in the matrix is assigned a random value in the range [-1, 1]. Furthermore, the connectivity of each pair of nodes in subsequent layers is stored (where all nodes in each layer are connected to all non-bias nodes in the next layer).

The weights between layer k and layer k + 1 are stored in element k (starting at k = 0) of the weights array.

public predict(X: *): * source

Make a prediction for a data set.

Override:

Estimator#predict

Params:

NameTypeAttributeDescription
X *

Return:

*

See:

public setWeights(weights: *) source

Manually set the weights matrices of the network.

Params:

NameTypeAttributeDescription
weights *

public train(X: *, y: *) source

Train the supervised learning algorithm on a dataset.

Override:

Estimator#train

Params:

NameTypeAttributeDescription
X *
y *

See:

public trainEpoch(X: Array<Array<number>>, y: Array<mixed>) source

Train the network for one epoch. Samples will be shuffled inside this function before training.

Params:

NameTypeAttributeDescription
X Array<Array<number>>

Features of samples to train with

y Array<mixed>

Labels of samples

public trainSample(x: Array<number>, y: number) source

Train the network on a single sample

Params:

NameTypeAttributeDescription
x Array<number>

Input sample

y number

Sample label