简单的神经网络JavaScript库
简单的神经网络JavaScript库,用于在JavaScript中创建简单 vanilla 3-layer ANNs。
JavaScript 其它杂项
共216Star
详细介绍
Deprecated!
Simple Artificial Neural Network JavaScript library
This repository is a library for creating simple vanilla 3-layer ANNs in JavaScript. I'm using it for the second edition of the Nature of Code book, as well as examples for my ITP course: Intelligence and Learning.
At the moment this library is depends on p5.js. However, it's my intention to remove this dependency for the library itself (while still making examples using p5): #10. I also intend to port this library to Java for Processing: #11.
Finally, this library has a terribly inefficient matrix implementation and should likely include options for using math.js and/or gpu.js.
The code is based on the book Make Your Own Neural Network by Tariq Rashid (book source code).
Example Demos
The neuro-evolution examples are inspired by the chrome experiment Flappy Learning by xviniette.
Use
// Creating a Neural Network with # of inputs, hidden neurons, and outputs
var inputs = 4;
var hidden = 16;
var outputs = 2;
var nn = new NeuralNetwork(inputs, hidden, outputs);
// Training the Neural Network with inputs and known outputs
var inputs = [-0.3, 0.5, 0.3, 0.2];
var targets = [0.99, 0.01];
nn.train(inputs, targets);
// Querying the Neural Network with inputs
var inputs = [-0.3, 0.5, 0.3, 0.2];
var prediction = nn.query(inputs);
By default, the library will use a sigmoid activation function. However, you can select other activation functions as follows (tanh only at the moment)):
var nn = new NeuralNetwork(inputs, hidden, outputs, 'sigmoid');
var nn = new NeuralNetwork(inputs, hidden, outputs, 'tanh');