Code Monkey home page Code Monkey logo

dann's Introduction

Dannjs

versionNpmStat repoSize downloadNpmStat downloadNpmStat GitHub

Deep Neural Network Library for Javascript

Train a neural network with your data & save its trained state!

DemoInstallationDocumentationContributeDiscordLicense


Installation

CDN :

<script src="https://cdn.jsdelivr.net/gh/matiasvlevi/[email protected]/build/dann.min.js"></script>

Node :

npm i dannjs

dannjs on npmjs.com

Getting started

Require package

Components from the library can be imported like this

const { Dann } = require('dannjs');

Basic model construction

Setting up a small (4,6,6,2) neural network.

const nn = new Dann(4, 2);
nn.addHiddenLayer(6, 'leakyReLU');
nn.addHiddenLayer(6, 'leakyReLU');
nn.outputActivation('tanH');
nn.makeWeights();
nn.lr = 0.0001;
nn.log({details:true});

Train by backpropagation

Training with a dataset.

//XOR 2 inputs, 1 output
const dataset = [
    {
        input: [0, 0],
        output: [0]
    },
    {
        input: [1, 0],
        output: [1]
    },
    {
        input: [0, 1],
        output: [1]
    },
    {
        input: [1, 1],
        output: [0]
    }
];

//train 1 epoch
for (data of dataset) {
    nn.backpropagate(data.input, data.output);
    console.log(nn.loss);
}

Train by mutation

For neuroevolution simulations. Works best with small models & large population size.

const populationSize = 1000;
let newGeneration = [];

for (let i = 0; i < populationSize; i++) {

    // parentNN would be the best nn from past generation.
    const childNN = parentNN;
    childNN.mutateRandom(0.01, 0.65);

    newGeneration.push(childNN);
}

Standalone function

Convert a Neural Network to a JS function that can output predictions without the library.

let strfunc = nn.toFunction();
console.log(strfunc);

Save JSON

let json = nn.toJSON();
console.log(json);


Demo:

AI predicts San-francisco Housing prices.
more examples & demos here

Online editor:

https://dannjs.org/sandbox


Socials


Graph Dann models with this library

Dann-p5


Stickers

Get Dannjs stickers!



Contributors


Matias Vazquez-Levi

💻 📖 ⚠️

Francesco Ciulla

📢

Labnan

🐛 💻 ⚠️

sharkAce

💻

Hasnain Iqbal

💻 ⚠️

EL Ramos

🐛 ⚠️ 💻

viabhinav


and1can

💻 ⚠️

Any contributions are welcome! See CONTRIBUTING.md.






License

MIT

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.