Fast and simple Neural Network for node.js
nn is a Neural Network library built for performance and ease of use. It is easy to configure and has sane defaults. You can use it for tasks such as pattern recognition and function approximation.
npm install nn
var nn =var net =// this example shows how we could train it to approximate sin(x)// from a random set of input/output data.net// send it a new input to see its trained outputvar output = net // => 0.48031129953896595
var net = nn(opts)
Creates a Neural Network instance. Pass in an optional
opts object to configure the instance. Any values specified in
opts will override the corresponding defaults.
The default configuration is shown below:
// hidden layers eg. [ 4, 3 ] => 2 hidden layers, with 4 neurons in the first, and 3 in the second.layers: 3// maximum training epochs to perform on the training dataiterations: 20000// maximum acceptable error thresholderrorThresh: 00005// activation function ('logistic' and 'hyperbolic' supported)activation: 'logistic'// learning ratelearningRate: 04// learning momentummomentum: 05// logging frequency to show training progress. 0 = never, 10 = every 10 iterations.log: 0
Train your neural network instance, using
trainingData. You can pass in a single training entry as an object with
output keys, or an array of training entries. The network will train itself from the supplied training data, until the error threshold has been reached, or the max number of iterations has been reached.
Sends your neural network the input data and returns its output.
input is an array of numbers. Typically you'll call this function after training your network.
Runs your neural network against
testData and returns an object with statistics about the performance of the network against the test data.
testData can be a single object with
output keys, or an array of those objects. Typically you'll call this function after training your network.
Returns a JSON string representing the state of the neural network. You can later use
nn.fromJson() to get back the neural network from the JSON string.
Load a neural network instance from the JSON representation. Pass in
jsonString as a string.
(The MIT License)
Copyright (c) by Tolga Tezel firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.