Giter Club home page Giter Club logo

neuron's Introduction

neuron

neural network implemented in javascript.

overview

neuron is a javascript implementation of a multi layer perceptron network. The library allows one to quickly create fully connected feed forward networks and iteratively train them to approximate some desired output.

neuron was written to allow for fast, interactive training in the browser for small networks. The library is offered as is for anyone who finds it useful, educational or just interesting.

building the project

npm install typescript -g
npm install typescript-bundle -g
npm run build-test
node bin/test

approximate xor

the following code sets up a network and iteratively trains it to approximate xor. This network is using tanh activation per each layer, with each layer given an additional bias neuron with a value of 1.0.

//------------------------------------------------------
//  network topology
//
//    0 0     <--- input layer
//  / /|\ \
// 0 0 0 0 0  <--- hidden layer 0
//  \ \|/ /        
//   0 0 0    <--- hidden layer 1
//    \|/
//     0      <--- output layer
//
//------------------------------------------------------
const network = new neuron.Trainer(new neuron.Network([
  new neuron.Tensor(2),
  new neuron.Tensor(5, "tanh"),
  new neuron.Tensor(3, "tanh"),
  new neuron.Tensor(1, "tanh"),
]))

//------------------------------------------------------
// train the network and report every 10,000 iterations.
//------------------------------------------------------
let iteration = 0
while(iteration < 100000000) { // 100,000,000 iterations.

  // train network against xor truth table. store mean error.
  const error = (network.backward([0, 0], [0]) +
                 network.backward([0, 1], [1]) +
                 network.backward([1, 0], [1]) +
                 network.backward([1, 1], [0])) / 4

  // view approximation.
  if(iteration % 10000 === 0) {
    console.log("-", iteration, error)
    console.log(0, network.forward([0, 0]))
    console.log(1, network.forward([0, 1]))
    console.log(1, network.forward([1, 0]))
    console.log(0, network.forward([1, 1]))
  }
  iteration++
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.