Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Dann Object

Matias Vazquez-Levi edited this page Feb 1, 2021 · 30 revisions

Back to Home

Import

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

Contructor( inputSize , outputSize )

When you create a neural network, you need to specify the size of the input & output layers.

const nn = new Dann(2,2);

Object Properties

  • arch

    This value represents the architecture of the model in the form of an array.

  • lr

    This defines the learning rate of the model. This value is set to 0.001 by default.

  • epoch

    This is an empty value. This is meant for you to increase whenever you have completed one epoch. This serves as a way to save the number of epochs along with the weights in the dannData.json file.

  • loss

    This is the most recent loss value of the model. If the model has never been trained before, this value will be set to 0.




Function properties

Model Creation

Model Interaction

Weight Mutations

Saving & Loading

Debug


Example

Here is a neural network training to solve XOR:

const Dann = require('dannjs').dann;  //nodejs only

// XOR neural network
const nn =  new Dann(2,1);
nn.addHiddenLayer(4,'tanH');
nn.outputActivation('sigmoid');
nn.makeWeights();
nn.lr = 0.1;

// feeding data to the model before training
nn.feedForward([0,0],{log:true});
nn.feedForward([1,1],{log:true});
nn.feedForward([0,1],{log:true});
nn.feedForward([1,0],{log:true});

// training the model
const epoch = 10000;
for (let e = 0; e < epoch; e++) {
    nn.backpropagate([0,0],[0]);
    nn.backpropagate([1,1],[0]);
    nn.backpropagate([0,1],[1]);
    nn.backpropagate([1,0],[1]);
}

// feeding data to the model after training
nn.feedForward([0,0],{log:true});
nn.feedForward([1,1],{log:true});
nn.feedForward([0,1],{log:true});
nn.feedForward([1,0],{log:true});
Clone this wiki locally