obengwilliam / Dann

Create Neural Networks in less than a few lines of code.

Home Page:https://dannjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dannjs

versionNpmStat repoSize downloadNpmStat GitHub

Easy way to create neural networks in Javascript

Train a neural network with your dataset & save it's trained state!

DemoInstallationGetting startedDocsLicense


Installation

CDN :

<script src="https://cdn.jsdelivr.net/gh/matiasvlevi/dann@v2.2.2d/build/dann.min.js"></script>

Node :

npm i dannjs

dannjs on npmjs.com

Getting started

Node Imports

Object types from the library can be imported like this

const dn = require('dannjs');
const Dann = dn.dann;
const Layer = dn.layer;
const Matrix = dn.matrix;

The objects containing functions can be imported this way

const dn = require('dannjs');
const lossfuncs = dn.lossfuncs;
const activations = dn.activations;
const poolfuncs = dn.poolfuncs;

Basic model construction

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

const dn = require('dannjs');
const Dann = dn.dann;

let 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.

//some example data... 4 inputs, 2 outputs
const dataset = [
    {
        input: [0,1,0,0],
        output: [0,1]
    },
    {
        input: [0,0,0,1],
        output: [0,1]
    },
    {
        input: [0,1,0,1],
        output: [1,0]
    },
    {
        input: [0,1,1,0],
        output: [1,1]
    },
    // ... more data
];

//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 population = 1000;
let newGeneration = [];

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

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

    newGeneration.push(childNN);
}


Documentation

https://dannjs.org#docs

Demo:

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

Contact

matias@dannjs.org

Report Bugs

Report an issue

Socials

Twitter Follow Patreon donate button



License

MIT

About

Create Neural Networks in less than a few lines of code.

https://dannjs.org

License:MIT License


Languages

Language:JavaScript 97.6%Language:Batchfile 2.4%