Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
fcacc8d
Added link to pull request 62
Maik1999 Feb 25, 2018
01784f9
Merge pull request #87 from Maik1999/patch-2
shiffman Feb 25, 2018
d641c86
adding new doodle classifier example
shiffman Mar 2, 2018
7615757
Create README.md
shiffman Mar 6, 2018
c8ae50a
adding new neuro-evolution example
shiffman Mar 9, 2018
846a259
Adding code from March 9 live stream
shiffman Mar 9, 2018
03718ae
Add Matrix copy() test
enginefeeder101 Mar 10, 2018
e713dff
Merge pull request #99 from enginefeeder101/copytest
shiffman Mar 10, 2018
1bbf0ca
Examples added doodleclassifier and Youtube links
enginefeeder101 Mar 15, 2018
3622343
Create a README in the xor example
jonathan-richer Mar 21, 2018
20bc3db
Update the structure of the README file
jonathan-richer Mar 22, 2018
4dd37fa
Merge pull request #103 from codeMeHtm/patch-2
shiffman Mar 24, 2018
24540b8
attempting flappy neuro-evolution first pass
shiffman Apr 9, 2018
5017841
flappy bird attempts
shiffman Apr 9, 2018
00dcb4b
neuroevolution flappy example
shiffman Apr 15, 2018
187ae7a
Merge pull request #109 from CodingTrain/neuroevolution
shiffman Apr 15, 2018
545cc15
added community contributions
kim-marcel Apr 17, 2018
067bbef
Merge pull request #113 from kim-marcel/patch-1
shiffman Apr 18, 2018
c961aaa
New neuroevolution steering example
shiffman Apr 19, 2018
8d1f077
oops, reference this repo's library files
shiffman Apr 19, 2018
6476919
Merge pull request #114 from CodingTrain/neurosteering
shiffman Apr 19, 2018
d5e0461
Merge branch 'master' into patch-1
shiffman Apr 21, 2018
4766a5b
Merge pull request #101 from enginefeeder101/patch-1
shiffman Apr 21, 2018
1ce9f5a
Missing semi-colon in matrix.js
Thomas-Smyth Apr 25, 2018
cc41638
Merge pull request #117 from Thomas-Smyth/master
shiffman Apr 25, 2018
46d2371
Added another Library reference
theKayani May 26, 2018
8786538
Merge pull request #120 from Fir3will/master
Versatilus May 26, 2018
8a96a38
mod constructor args to be self documented
michezio Jun 5, 2018
e961042
Merge pull request #121 from michezio/patch-1
Versatilus Jun 6, 2018
19115f1
Update README.md
GypsyDangerous Mar 15, 2019
567f59d
Merge pull request #129 from GypsyDangerous/master
shiffman Mar 15, 2019
3bac6a4
Update README.md
notshekhar Jun 27, 2019
997bff9
Merge pull request #136 from notshekhar/patch-3
shiffman Jun 27, 2019
fcd7459
Update README.md
jackroi Jul 11, 2019
7b629b6
Merge pull request #137 from jackroi/master
shiffman Jul 11, 2019
c6c5d8f
Update README.md
anirudhgiri Jul 26, 2019
7305892
Merge pull request #138 from anirudhgiri/master
shiffman Jul 26, 2019
667aefc
Update README.md
savvysiddharth Oct 4, 2019
f12105f
Merge pull request #141 from savvysiddharth/master
GypsyDangerous Oct 4, 2019
08df543
Added my implementation of CNN
therealyubraj Feb 23, 2022
10091b0
Merge pull request #160 from therealyubraj/master
shiffman Feb 23, 2022
95b7b56
fixes small typos in README.md
Esser50K Jun 20, 2022
79951ea
Merge pull request #162 from Esser50K/master
shiffman Jun 22, 2022
05f68ae
Create node.js.yml
mrdcvlsc Jul 23, 2022
8729326
migrate ci to github actions
mrdcvlsc Jul 23, 2022
91aca06
removed node version 9.x in ci.yml
mrdcvlsc Jul 23, 2022
3766a5c
added node version 18 in ci
mrdcvlsc Jul 23, 2022
8c48c83
Merge pull request #164 from mrdcvlsc/migrate-ci-to-gh-actions
shiffman Aug 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions .circleci/config.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci

on:
push:
branches: [ "master", "main" ]
pull_request:
branches: [ "master", "main" ]

jobs:
ci:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [8.x, 12.x, 14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Toy-Neural-Network-JS [![Build Status](https://circleci.com/gh/CodingTrain/Toy-Neural-Network-JS.png?&style=shield&circle-token=:circle-token)](https://circleci.com/gh/CodingTrain/Toy-Neural-Network-JS)
# Toy-Neural-Network-JS

![ci](https://github.com/CodingTrain/Toy-Neural-Network-JS/actions/workflows/ci.yml/badge.svg)

Neural Network JavaScript library for Coding Train tutorials

## Examples / Demos
Here are some demos running directly in the browser:
* [XOR problem](https://codingtrain.github.io/Toy-Neural-Network-JS/examples/xor/)
* [XOR problem](https://codingtrain.github.io/Toy-Neural-Network-JS/examples/xor/), [Coding Challenge on YouTube](https://www.youtube.com/watch?v=188B6k_F9jU)
* [Handwritten digit recognition](https://codingtrain.github.io/Toy-Neural-Network-JS/examples/mnist/)
* [Doodle classifier](https://codingtrain.github.io/Toy-Neural-Network-JS/examples/doodle_classification/), [Coding Challenge on YouTube](https://www.youtube.com/watch?v=pqY_Tn2SIVA&list=PLRqwX-V7Uu6Zs14zKVuTuit6jApJgoYZQ)

## To-Do List

Expand All @@ -20,9 +23,9 @@ Here are some demos running directly in the browser:
* only use testing data
* [ ] Support for saving / restoring network (see [#50](https://github.com/CodingTrain/Toy-Neural-Network-JS/pull/50))
* [ ] Support for different activation functions (see [#45](https://github.com/CodingTrain/Toy-Neural-Network-JS/pull/45), [#62](https://github.com/CodingTrain/Toy-Neural-Network-JS/pull/62))
* [ ] Support for multiple hidden layers (see #61)
* [ ] Support for multiple hidden layers (see [#61](https://github.com/CodingTrain/Toy-Neural-Network-JS/pull/61))
* [ ] Support for neuro-evolution
* [ ] play flappy bird (many players at once).
* [ ] play flappy bird (many players at once).
* [ ] play pong (many game simulations at once)
* [ ] steering sensors (a la Jabril's forrest project!)
* [ ] Combine with ml5 / deeplearnjs
Expand Down Expand Up @@ -55,7 +58,7 @@ This Project doesn't require any additional Installing steps

## Running the tests

The Tests can either be checked via the automaticly running CircleCI Tests or you can also run `npm test` on your PC after you have done the Step "Prerequisites"
The Tests can either be checked via the automatically running CircleCI Tests or you can also run `npm test` on your PC after you have done the Step "Prerequisites"

## Built With

Expand All @@ -67,6 +70,22 @@ The Tests can either be checked via the automaticly running CircleCI Tests or yo

Please send PullRequests. These need to pass a automated Test first and after it will get reviewed and on that review either denied or accepted.

## Libraries built by the community

Here are some libraries with the same or similar functionality to this one built by the community:

- [Java Neural Network Library](https://github.com/kim-marcel/basic_neural_network) by [kim-marcel](https://github.com/kim-marcel)
- [Library-less Java Neural Network](https://github.com/Fir3will/Java-Neural-Network) by [Fir3will](https://github.com/Fir3will)
- [Python Neural Network Library](https://github.com/Gabriel-Teston/Machine-Learning) by [Gabriel-Teston](https://github.com/Gabriel-Teston)
- [Python Neural Network Library](https://github.com/GypsyDangerous/simple-deep-neural-network/blob/master/README.md) by [David Snyder](https://github.com/GypsyDangerous)
- [JavaScript Multi-Layer Neural Network Library](https://github.com/notshekhar/neuralnet) by [Shekhar Tyagi](https://github.com/notshekhar)
- [F# Neural Network Library](https://github.com/jackroi/NeuralNetwork-fsharp) by [jackroi](https://github.com/jackroi)
- [TinyNeuralNetwork4Java](https://github.com/anirudhgiri/TinyNN4J) by [Anirudh Giri](https://github.com/anirudhgiri)
- [miniANN Neural Network Library JavaScript](https://github.com/savvysiddharth/mini-ANN-js) by [Siddharth Maurya](https://github.com/savvysiddharth)
- [Convolutional Neural Network Library JavaScript](https://github.com/therealyubraj/CNN_JS) by [Yubraj Sharma](https://github.com/therealyubraj)

Feel free to add your own libraries.

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/CodingTrain/Toy-Neural-Network-JS/tags).
Expand All @@ -80,3 +99,4 @@ See also the list of [contributors](https://github.com/CodingTrain/Toy-Neural-Ne
## License

This project is licensed under the terms of the MIT license, see LICENSE.

1 change: 1 addition & 0 deletions examples/doodle_classification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://codingtrain.github.io/Toy-Neural-Network-JS/examples/doodle_classification/
Binary file added examples/doodle_classification/data/cats1000.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions examples/doodle_classification/dataprep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function prepareData(category, data, label) {
category.training = [];
category.testing = [];
for (let i = 0; i < totalData; i++) {
let offset = i * len;
let threshold = floor(0.8 * totalData);
if (i < threshold) {
category.training[i] = data.bytes.subarray(offset, offset + len);
category.training[i].label = label;
} else {
category.testing[i - threshold] = data.bytes.subarray(offset, offset + len);
category.testing[i - threshold].label = label;
}
}
}
34 changes: 34 additions & 0 deletions examples/doodle_classification/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>doodle classifier</title>

<script src="libraries/p5.min.js"></script>
<script src="libraries/p5.dom.min.js"></script>
<script src="loadbinary.js"></script>
<script src="traintest.js"></script>
<script src="dataprep.js"></script>
<script src="sketch.js"></script>
<script src="../../lib/nn.js"></script>
<script src="../../lib/matrix.js"></script>
<style>
body {
background-color: #AAA;
}
button {
font-size: 24pt;
margin: 10px;
}
</style>
</head>
<body>
<button id="train">train</button>
<button id="test">test</button>
<button id="guess">guess</button>
<button id="clear">clear</button>
</body>
</html>
1 change: 1 addition & 0 deletions examples/doodle_classification/libraries/p5.dom.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions examples/doodle_classification/libraries/p5.min.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions examples/doodle_classification/loadbinary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
p5.prototype.registerPreloadMethod('loadBytes');

p5.prototype.loadBytes = function(file, callback) {
var self = this;
var data = {};
var oReq = new XMLHttpRequest();
oReq.open("GET", file, true);
oReq.responseType = "arraybuffer";
oReq.onload = function(oEvent) {
var arrayBuffer = oReq.response;
if (arrayBuffer) {
data.bytes = new Uint8Array(arrayBuffer);
if (callback) {
callback(data);
}
self._decrementPreload();
}
}
oReq.send(null);
return data;
}
107 changes: 107 additions & 0 deletions examples/doodle_classification/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const len = 784;
const totalData = 1000;

const CAT = 0;
const RAINBOW = 1;
const TRAIN = 2;

let catsData;
let trainsData;
let rainbowsData;

let cats = {};
let trains = {};
let rainbows = {};

let nn;

function preload() {
catsData = loadBytes('data/cats1000.bin');
trainsData = loadBytes('data/trains1000.bin');
rainbowsData = loadBytes('data/rainbows1000.bin');
}


function setup() {
createCanvas(280, 280);
background(255);

// Preparing the data
prepareData(cats, catsData, CAT);
prepareData(rainbows, rainbowsData, RAINBOW);
prepareData(trains, trainsData, TRAIN);

// Making the neural network
nn = new NeuralNetwork(784, 64, 3);

// Randomizing the data
let training = [];
training = training.concat(cats.training);
training = training.concat(rainbows.training);
training = training.concat(trains.training);

let testing = [];
testing = testing.concat(cats.testing);
testing = testing.concat(rainbows.testing);
testing = testing.concat(trains.testing);

let trainButton = select('#train');
let epochCounter = 0;
trainButton.mousePressed(function() {
trainEpoch(training);
epochCounter++;
console.log("Epoch: " + epochCounter);
});

let testButton = select('#test');
testButton.mousePressed(function() {
let percent = testAll(testing);
console.log("Percent: " + nf(percent, 2, 2) + "%");
});

let guessButton = select('#guess');
guessButton.mousePressed(function() {
let inputs = [];
let img = get();
img.resize(28, 28);
img.loadPixels();
for (let i = 0; i < len; i++) {
let bright = img.pixels[i * 4];
inputs[i] = (255 - bright) / 255.0;
}

let guess = nn.predict(inputs);
// console.log(guess);
let m = max(guess);
let classification = guess.indexOf(m);
if (classification === CAT) {
console.log("cat");
} else if (classification === RAINBOW) {
console.log("rainbow");
} else if (classification === TRAIN) {
console.log("train");
}

//image(img, 0, 0);
});

let clearButton = select('#clear');
clearButton.mousePressed(function() {
background(255);
});
// for (let i = 1; i < 6; i++) {
// trainEpoch(training);
// console.log("Epoch: " + i);
// let percent = testAll(testing);
// console.log("% Correct: " + percent);
// }
}


function draw() {
strokeWeight(8);
stroke(0);
if (mouseIsPressed) {
line(pmouseX, pmouseY, mouseX, mouseY);
}
}
41 changes: 41 additions & 0 deletions examples/doodle_classification/traintest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function trainEpoch(training) {
shuffle(training, true);
//console.log(training);
// Train for one epoch
for (let i = 0; i < training.length; i++) {
let data = training[i];
let inputs = Array.from(data).map(x => x / 255);
let label = training[i].label;
let targets = [0, 0, 0];
targets[label] = 1;
// console.log(inputs);
// console.log(targets);
nn.train(inputs, targets);
}
}

function testAll(testing) {

let correct = 0;
// Train for one epoch
for (let i = 0; i < testing.length; i++) {
// for (let i = 0; i < 1; i++) {
let data = testing[i];
let inputs = Array.from(data).map(x => x / 255);
let label = testing[i].label;
let guess = nn.predict(inputs);

let m = max(guess);
let classification = guess.indexOf(m);
// console.log(guess);
// console.log(classification);
// console.log(label);

if (classification === label) {
correct++;
}
}
let percent = 100 * correct / testing.length;
return percent;

}
Loading