sus.js
v1.1.0
Published
A simple and easy to use neural network library. Do not use for serious projects that need high preformance. I'm too lazy to learn to use the gpu for neural networks.
Downloads
3
Readme
About
sus.js is a neural network modules for nodejs. You can create, run, and train networks. See the example for more information on how to do this.
Limitations
sus.js does not use the GPU at all, making it less efficient than the main ml libararies like tensorflow. I would recommend you use one of those libararies because not only are they more efficient but they have more features. I created this because I was interested in how neural nets worked, not to replace tensorflow.
Example
Here we will create a network that approximates the xor function:
To create a network you will need to specify an array for the structure. The structure for this network is [2, 3, 5, 1]. The number of inputs is the first item in your array and the number of outputs is the last. Each item between represent a hidden layer. In our case we need 2 inputs and 1 output. The amount of hidden layers and neurons in each hidden layer is arbitrary for our network.
const { Network } = require("sus.js");
const struct = [2, 3, 5, 1];
const net = new Network(struct);
We now need to train our network. For the example I will do 500000 iterations. Our data needs to be the input to the xor function. We will just generate to random bits for this. The data that you are entering need to a list with the same length as the amount of inputs you have. The target values need to be a list of the same length as the outputs. The targets should be the correct answer for the neural network. The third paramater for the Train function is the learning rate. This should be a number from 0.001-0.1.
for (let i = 0; i < 500000; i++) {
let data = [Math.round(Math.random()), Math.round(Math.random())];
net.Train(data, [data[0]^data[1]], 0.01);
}
We have succsessfully trained our network now. Time to test the results. This step is not needed.
console.log(net.run([0, 0])); // Output should be close to 0
console.log(net.run([0, 1])); // Output should be close to 1
console.log(net.run([1, 0])); // Output should be close to 1
console.log(net.run([1, 1])); // Output should be close to 0