X Tutup
The Wayback Machine - https://web.archive.org/web/20201009030450/https://github.com/shiffman/Neural-Network-p5
Skip to content
This repository has been archived by the owner. It is now read-only.
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time

README.md

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');
You can’t perform that action at this time.
X Tutup