Constructor
new Network(layers, errorFnopt)
Creates a Network of Layers consisting of Neurons. Each array element indicates a layer.
The first element represents the input Layer. The last element represents the output Layer. Each element in between represents a hidden Layer with n Neurons.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
layers |
Array.<Layer> | An array of Layers. |
||
errorFn |
function |
<optional> |
ERROR.meanSquared | The cost function to be minimized. |
- Source:
Example
// 2 inputs
// 1 output
const net = new Network([
new Layer(2, ACTIVATION.tanh),
new Layer(1, ACTIVATION.softmax)
])
Members
allLayers :Layer
An array of all Layers in the Network.
An array of all Layers in the Network. It is a single dimension array
containing the inputLayer
, hiddenLayers
, and the outputLayer
.
Type:
- Source:
error :Number
The result of the errorFn
.
The result of the errorFn
.
Type:
- Number
- Source:
errorFn :function
The cost function.
The cost function. The function used to calculate Network error
.
In other words, to what degree was the Network's output wrong.
Type:
- function
- Source:
hiddenLayers :Array.<Layer>
An array of all layers between the inputLayer
and outputLayer
.
An array of all layers between the inputLayer
and outputLayer
.
Type:
- Array.<Layer>
- Source:
inputLayer :Layer
The first Layer of the Network.
The first Layer of the Network. This Layer receives input during activation.
Type:
- Source:
output :Array
The output values of the Neurons in the last layer.
The output values of the Neurons in the last layer.
This is identical to the Network's outputLayer
output.
Type:
- Array
- Source:
outputLayer :Layer
The last Layer of the Network.
The last Layer of the Network. The output of this Layer is the "prediction" the Network has made for some given input.
Type:
- Source:
Methods
accumulateGradients()
Calculate and accumulate Neuron Connection weight gradients.
Calculate and accumulate Neuron Connection weight gradients. Does not update weights. Useful during batch/mini-batch training.
- Source:
activate(inputsopt) → {Array.<number>}
Activate the Network with a given set of input
values.
Activate the Network with a given set of input
values.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
inputs |
Array.<number> |
<optional> |
Values to activate the Network's input Neurons with. |
- Source:
Returns:
output - The output values of each Neuron in the output Layer.
- Type
- Array.<number>
backprop(targetOutputopt)
Set Network error
and output Layer delta
s and propagate them backward
through the Network.
Set Network error
and output Layer delta
s and propagate them backward
through the Network. The input Layer has no use for deltas, so it is skipped.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
targetOutput |
Array.<number> |
<optional> |
The expected Network output vector. |
- Source:
updateWeights()
Update Neuron Connection weights and reset their accumulated gradients.
Update Neuron Connection weights and reset their accumulated gradients.
- Source: