• Stars
    star
    6,914
  • Rank 5,682 (Top 0.2 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 10 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

architecture-free neural network library for node.js and the browser

Synaptic Build Status Join the chat at https://synapticjs.slack.com

Important: Synaptic 2.x is in stage of discussion now! Feel free to participate

Synaptic is a javascript neural network library for node.js and the browser, its generalized algorithm is architecture-free, so you can build and train basically any type of first order or even second order neural network architectures.

This library includes a few built-in architectures like multilayer perceptrons, multilayer long-short term memory networks (LSTM), liquid state machines or Hopfield networks, and a trainer capable of training any given network, which includes built-in training tasks/tests like solving an XOR, completing a Distracted Sequence Recall task or an Embedded Reber Grammar test, so you can easily test and compare the performance of different architectures.

The algorithm implemented by this library has been taken from Derek D. Monner's paper:

A generalized LSTM-like training algorithm for second-order recurrent neural networks

There are references to the equations in that paper commented through the source code.

Introduction

If you have no prior knowledge about Neural Networks, you should start by reading this guide.

If you want a practical example on how to feed data to a neural network, then take a look at this article.

You may also want to take a look at this article.

Demos

The source code of these demos can be found in this branch.

Getting started

To try out the examples, checkout the gh-pages branch.

git checkout gh-pages

Other languages

This README is also available in other languages.

Overview

Installation

In node

You can install synaptic with npm:

npm install synaptic --save
In the browser

You can install synaptic with bower:

bower install synaptic

Or you can simply use the CDN link, kindly provided by CDNjs

<script src="https://cdnjs.cloudflare.com/ajax/libs/synaptic/1.1.4/synaptic.js"></script>

Usage

var synaptic = require('synaptic'); // this line is not needed in the browser
var Neuron = synaptic.Neuron,
	Layer = synaptic.Layer,
	Network = synaptic.Network,
	Trainer = synaptic.Trainer,
	Architect = synaptic.Architect;

Now you can start to create networks, train them, or use built-in networks from the Architect.

Examples

Perceptron

This is how you can create a simple perceptron:

perceptron.

function Perceptron(input, hidden, output)
{
	// create the layers
	var inputLayer = new Layer(input);
	var hiddenLayer = new Layer(hidden);
	var outputLayer = new Layer(output);

	// connect the layers
	inputLayer.project(hiddenLayer);
	hiddenLayer.project(outputLayer);

	// set the layers
	this.set({
		input: inputLayer,
		hidden: [hiddenLayer],
		output: outputLayer
	});
}

// extend the prototype chain
Perceptron.prototype = new Network();
Perceptron.prototype.constructor = Perceptron;

Now you can test your new network by creating a trainer and teaching the perceptron to learn an XOR

var myPerceptron = new Perceptron(2,3,1);
var myTrainer = new Trainer(myPerceptron);

myTrainer.XOR(); // { error: 0.004998819355993572, iterations: 21871, time: 356 }

myPerceptron.activate([0,0]); // 0.0268581547421616
myPerceptron.activate([1,0]); // 0.9829673642853368
myPerceptron.activate([0,1]); // 0.9831714267395621
myPerceptron.activate([1,1]); // 0.02128894618097928
Long Short-Term Memory

This is how you can create a simple long short-term memory network with input gate, forget gate, output gate, and peephole connections:

long short-term memory

function LSTM(input, blocks, output)
{
	// create the layers
	var inputLayer = new Layer(input);
	var inputGate = new Layer(blocks);
	var forgetGate = new Layer(blocks);
	var memoryCell = new Layer(blocks);
	var outputGate = new Layer(blocks);
	var outputLayer = new Layer(output);

	// connections from input layer
	var input = inputLayer.project(memoryCell);
	inputLayer.project(inputGate);
	inputLayer.project(forgetGate);
	inputLayer.project(outputGate);

	// connections from memory cell
	var output = memoryCell.project(outputLayer);

	// self-connection
	var self = memoryCell.project(memoryCell);

	// peepholes
	memoryCell.project(inputGate);
	memoryCell.project(forgetGate);
	memoryCell.project(outputGate);

	// gates
	inputGate.gate(input, Layer.gateType.INPUT);
	forgetGate.gate(self, Layer.gateType.ONE_TO_ONE);
	outputGate.gate(output, Layer.gateType.OUTPUT);

	// input to output direct connection
	inputLayer.project(outputLayer);

	// set the layers of the neural network
	this.set({
		input: inputLayer,
		hidden: [inputGate, forgetGate, memoryCell, outputGate],
		output: outputLayer
	});
}

// extend the prototype chain
LSTM.prototype = new Network();
LSTM.prototype.constructor = LSTM;

These are examples for explanatory purposes, the Architect already includes Multilayer Perceptrons and Multilayer LSTM network architectures.

Contribute

Synaptic is an Open Source project that started in Buenos Aires, Argentina. Anybody in the world is welcome to contribute to the development of the project.

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

Support

If you like this project and you want to show your support, you can buy me a beer with magic internet money:

BTC: 16ePagGBbHfm2d6esjMXcUBTNgqpnLWNeK
ETH: 0xa423bfe9db2dc125dd3b56f215e09658491cc556
LTC: LeeemeZj6YL6pkTTtEGHFD6idDxHBF2HXa
XMR: 46WNbmwXpYxiBpkbHjAgjC65cyzAxtaaBQjcGpAZquhBKw2r8NtPQniEgMJcwFMCZzSBrEJtmPsTR54MoGBDbjTi2W1XmgM

<3

More Repositories

1

coin-hive

CoinHive cryptocurrency miner for node.js
JavaScript
1,982
star
2

coin-hive-stratum

use CoinHive's JavaScript miner on any stratum pool
TypeScript
416
star
3

shoal

autonomous agents + genetic algorithms
JavaScript
242
star
4

mnist

mnist digits in javascript
JavaScript
191
star
5

react-coin-hive

Mine cryptocurrency while your users haven't engaged with your content lately
JavaScript
158
star
6

eth-pictures

🎨 Draw your own NFTs
TypeScript
44
star
7

coin-hive-proxy

Deprecated. Use CoinHive Stratum instead.
35
star
8

donger

npm package to generate dongers ヽ༼ຈل͜ຈ༽ノ
JavaScript
29
star
9

minero

a bunch of APIs mashed together
24
star
10

haha

humorous javascript obfuscation tool
JavaScript
16
star
11

nftmarketcap

top non-fungible tokens by (avg) market capitalization
JavaScript
13
star
12

react-redux-perf

Performance Engineering with React + Redux
JavaScript
12
star
13

synaptic-wikipedia

This is the source code for Synaptic's Wikipedia example
JavaScript
11
star
14

cheapbase

like Firebase, but for free (thanks to Heroku).
JavaScript
10
star
15

synaptic-workshop

Synaptic workshop for MuleSoft's MeetUp 2017
JavaScript
8
star
16

decentraland-shoal-scene

Decentraland Shoal Scene
TypeScript
7
star
17

react-storybook-typescript-template

🤸🏻‍♀️Template for a UI library using React + Storybook with TypeScript
JavaScript
7
star
18

earthquakes

just an experiment mixing Firebase open datasets + Google's WebGL Globe
JavaScript
5
star
19

hamster-scene

🐹 A hamster trying to escape from a pipe maze
TypeScript
4
star
20

lysergic

javascript neural network compiler
TypeScript
4
star
21

oliver

⚽️ Bot de Telegram para armar equipos de futbol
JavaScript
3
star
22

cazala.github.io

this is the source of my website
JavaScript
3
star
23

q-cache

simple tool to cache promises
JavaScript
2
star
24

query-to-json

just and endpoint that receives a query and returns a json of it
TypeScript
2
star
25

universal-app

2
star
26

point-e

Text to 3D mesh using OpenAI's Point-E
Python
2
star
27

builder-bot

Twitter bot that tweets every time new content is deployed via Decentraland's Builder
TypeScript
2
star
28

powerhour

tiny app for playing Power Hour (drinking game)
HTML
2
star
29

mana-altar

🔥 Burn MANA collected from Decentraland's Marketplace and light the Altar's flame
TypeScript
1
star
30

screenshots

TypeScript
1
star
31

eth-pictures-bot

✍Twitter bot that tweets new images submitted to https://eth.pictures
JavaScript
1
star
32

react-redux-seed

React + Redux + Router boilterplate
JavaScript
1
star
33

cra-bug-repro

TypeScript
1
star
34

rodo

🐘 HTTP mocking service
JavaScript
1
star
35

log

stdout
CSS
1
star
36

sabe

NodeJS meets ElBananero
JavaScript
1
star
37

universal-gitbook

1
star