npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

novabrain

v0.8.7

Published

Neural network library for NodeJS and browser

Downloads

94

Readme

Novabrain

Novabrain is a javascript neural network library for Node.js and browser. This library implements a multilayer perceptron network that you can train to learn XOR, OR, AND ... for example.

Perceptron

In Node.js

You can install Novabrain with npm

$ npm install novabrain --save
var Novabrain = require('novabrain');
var Neuron    = Novabrain.Neuron;
var Layer     = Novabrain.Layer;
var Network   = Novabrain.Network;
var Trainer   = Novabrain.Trainer;
var Transfer  = Novabrain.Transfer;
var Samples   = Novabrain.Samples;

In the browser

You can also use the minified version to increase your web page loading

<script type="text/javascript" src="novabrain.js"></script>
<script type="text/javascript">
	(function() {
	
		var network = new Novabrain.Network(2,1);
		
		network.import(Novabrain.Samples.XOR.config);
		
		network.transfer = Novabrain.Transfer.BOOLEAN;
		
		console.log([0,0], network.output([0,0])); // [false]
		console.log([0,1], network.output([0,1])); // [true]
		console.log([1,0], network.output([1,0])); // [true]
		console.log([1,1], network.output([1,1])); // [false]
		
	})();
</script>

Create a network

Constructor expected an intergers suite. The first value is the input size The last value is the output size Between this values you can set many hidden size (2, 3, ..., 1)

new Novabrain.Network(2,1);
new Novabrain.Network(2,3,1);
new Novabrain.Network(5,4,4,2);

Samples

Novabrain samples contains training and config for basics functions

Novabrain.Samples.XOR
Novabrain.Samples.AND
Novabrain.Samples.OR

Back Propagation Training

This example shows how the neural network is trained to learn XOR

var network = new Novabrain.Network(2,1);
var trainer = new Novabrain.Trainer(network);

trainer.train([
    { input: [0,0], output: [0] },
    { input: [0,1], output: [1] },
    { input: [1,0], output: [1] },
    { input: [1,1], output: [0] },
]);

console.log([0,0], network.output([0,0])); // [~0.05]
console.log([0,1], network.output([0,1])); // [~0.93]
console.log([1,0], network.output([1,0])); // [~0.93]
console.log([1,1], network.output([1,1])); // [~0.09]

network.transfer = Novabrain.Transfer.BOOLEAN;

console.log([0,0], network.output([0,0])); // [false]
console.log([0,1], network.output([0,1])); // [true]
console.log([1,0], network.output([1,0])); // [true]
console.log([1,1], network.output([1,1])); // [false]

Transfer functions

The transfer functions are used to change the value of the outputs. By default, neurons uses a Logistic Sigmoid transfer. You can change those properties the following way.

network.transfer = Novabrain.Transfer.BOOLEAN;

console.log([0,0], network.output([0,0])); // [false]
console.log([0,1], network.output([0,1])); // [true]
console.log([1,0], network.output([1,0])); // [true]
console.log([1,1], network.output([1,1])); // [false]

LOGISTIC
Return logistic sigmoid values

HARDLIMIT
Return 0 or 1 values

BOOLEAN
Return boolean values like HARDLIMIT

IDENTIFY
Return sum values without transfer

TANH
Return values between -1 and 1

Export and import data

var n1 = new Novabrain.Network(2,1);
var n2 = new Novabrain.Network(2,1);

n2.import(n1);
// or
n2.import(n1.export());

var results = n2.output([...]));

Create a standalone function

By default the transfer function used is LOGISITC but you can change this by two ways. Define your custom transfer before the standalone function export or set the transfer param when you use the standalone function.

var standalone = network.standalone();
var booleanResults = standalone([...], Novabrain.Transfer.BOOLEAN));
var standalone = network.standalone(Novabrain.Transfer.BOOLEAN);
var booleanResults = standalone([...]));
var tanhResults = standalone([...], Novabrain.Transfer.TANH));

Mocha is used for unit testing

$ npm test
$ make tests
$ npm install mocha -g
$ mocha

Contribute

Novabrain is an Open Source project started in France by François Mathey. Anybody is welcome to contribute to the development of this project.

If you want to contribute feel free to send PR's, just make sure to run the make before submiting it. This way you'll run all the test specs and build the web distribution files.

$ make

Thank you <3