Generic neural network. Subclasses must implement a `_train` method
to adjust weights and biases based on training data and a learning rate.
- Source:
Methods
_backpropogate(input, target, learning_rate) → {array}
The dreaded backpropogation algorithm.
First, calculates output from each layer of the network.
Then, calculates error rates for each neuron of each layer.
Lastly, uses those outputs, deltas, and a specified learning rate to adjust the weights and biases of the network.
Parameters:
Name | Type | Description |
---|---|---|
input |
array | array of input bits to the network |
target |
array | array of desired output bits from the network for the given input |
learning_rate |
number | (optional) value between 0 and 1 representing how quickly the network learns. Defaults to 0.3. |
- Source:
Returns:
deltas for each neuron of each layer in the network, besides the input layer
- Type
- array
_calculate_deltas(outputs, target) → {array}
Given outputs for each layer and the desired network output,
the network calculates modifications for its weights and biases
that will ensure it yields the proper output for the given input.
Parameters:
Name | Type | Description |
---|---|---|
outputs |
array | [i][j] matrix of output bits for every jth neuron of every ith layer |
target |
array | array of bits representing desired network output |
- Source:
Returns:
[i][j] matrix of deltas for every jth neuron of every ith layer
- Type
- array
_feedforward(input) → {array}
Calculates the network's output at each layer
for the given array of input values.
Parameters:
Name | Type | Description |
---|---|---|
input |
array | array of input bits |
- Source:
Returns:
array of arrays of output bits for each layer
- Type
- array
layer(i, layer)
Getter / setter for the network's neural layers, individually.
Parameters:
Name | Type | Description |
---|---|---|
i |
number | Index of the layer to get or set. |
layer |
object | (optional) A single layer, which replaces the i'th layer. If undefined, returns the i'th layer. |
- Source:
layers(layers)
Getter / setter for the network's neural layers.
Parameters:
Name | Type | Description |
---|---|---|
layers |
array | (optional) A list of layers to replace the network's current layers. If undefined, returns the list of current layers. |
- Source:
process(input) → {array}
Applies an array of input bits to each layer,
feeding its output into the next layer,
and returning the final layer's output.
Parameters:
Name | Type | Description |
---|---|---|
input |
array | array of input bits. |
- Source:
Returns:
array of output bits
- Type
- array
train(training_data, options) → {array}
Given training data, a number of epochs, and a learning rate,
trains the network to more accurately predict
correct outputs for given inputs.
The second parameter accepts an object containing custom training settings, specifically:
epochs: number of rounds to train against the data. Defaults to 20,000.
learning_rate: value between 0 and 1 representing how quickly the network learns. Defaults to 0.3.
threshold: error threshold. if the network attains an error rate under this threshold, it stops training early. Defaults to 0.005.
Parameters:
Name | Type | Description |
---|---|---|
training_data |
array | array of [input, correct_output] pairs used to train the network |
options |
object | options object. |
- Source:
Returns:
[i, error] where i is the number of iterations it took to reach the returned error rate
- Type
- array