Popularity
0.9
Growing
Activity
9.5
Growing
75
1
5

Description

Easy way to create neural networks in Javascript. Train a neural network with your dataset & save it's trained state!

Programming language: JavaScript
License: MIT License
Tags: Machine Learning    
Latest version: v2.1.0

Dannjs alternatives and similar libraries

Based on the "Machine Learning" category.
Alternatively, view Dannjs alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Dannjs or a related project?

Add another 'Machine Learning' Library

README

Deep Neural Network Library for Javascript Train a neural network with your data & save it's trained state!

Demo • Installation • Getting started • Docs • Contribute • Discord • License

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

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 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);
}

Demo:

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

SandBox:

Try out the new Dannjs Sandbox! https://dannjs.org/sandbox

Contribute

Contributor docs

Report Bugs

Report an issue

Socials

Contact

[email protected]

License

MIT


*Note that all licence references and agreements mentioned in the Dannjs README section above are relevant to that project's source code only.