GithubHelp home page GithubHelp logo

panzer / javascript-neuralnet Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 252 KB

A neural net written in Javascript. Makes use of the p5.js library for visualizing the net. The net is trained using a genetic algorithm.

License: MIT License

JavaScript 99.93% HTML 0.07%

javascript-neuralnet's Introduction

Javascript Neural Net

A neural net written in Javascript. The net is trained using a genetic algorithm.

New in the Latest Update

Nets

  • New property afunctions. Currently, four functions are in the list (linear, binary, sigmoid, and ReLU) but more are available in AFunctions.js. These are the activation functions available for each Node.

Nodes

  • Each Node can mutate to have an activation function. Any function that takes a number and returns a number is eligible, just add it to afunctions in Net.js.
  • In the getValue function, Node color is updated based on the activation function.

How it works

  1. A population of populationSize nets is created, with each net having n_inputs, n_layers, n_height and n_outputs.
  2. A scaled fitness is calculated for each net (the sum of all fitnesses in the population is 1)
    • The fitness of each net is determined by fit_tests provided in the sketch.js file.
    • The net with the least difference between desired output and actual output is the most fit.
  3. The best net of that generation is drawn on screen
  4. A new generation of Nets is created
    • The best Net is always included
    • The rest of the generation is made up by choosing the most fit Nets and applying slight mutations in the weights
  5. Steps 2 - 4 repeat

How to use it

Load up index.html and press the 'Start' button. If you'd like to make modifications to the net, or the training data, you may be able to find what you're looking for in the sketch.js file.

Current Training Data

Currently the nets are training on a 2x2 pixel image.

Inputs

  • Top Left pixel [-1, 1]
  • Top Right pixel [-1, 1]
  • Bottom Left pixel [-1, 1]
  • Bottom Right pixel [-1, 1]

Output

  • Solid? [0, 1]
  • Horizontal? [0, 1]
  • Vertical? [0, 1]
  • Diagonal? [0, 1]

Try it yourself!

I recommend using Chrome, right clicking, Inspect, and using the console. Use the command bestMember.output(input) where input is an array of your input. You must have at least as many inputs as your net requires!

If you'd like to try the 2x2 pixel image example, keep in mind the expect input range [-1, 1]. Your console input would look something like bestMember.output([1, 1, -0.5, -0.5, 1]). The input of 1 at the end is a constant input factor (which has been included in the training input).

Contributing

Contributions are welcome! If you have some better way of training, if you want to make the user interface better... go ahead! Check out the issues tab and see if you can help out with any of those.

Credits

Makes use of the p5.js library for visualizing the Net and some math functions.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

javascript-neuralnet's People

Contributors

panzer avatar

Stargazers

 avatar

Watchers

 avatar

javascript-neuralnet's Issues

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.