dart_nn 2.0.0+2

Dart native js
Flutter Android iOS web

A simple neural network library. You can create a simple fully connected neural network brain with any number of inputs, hidden layers and outputs.

dart_nn #

Run on Repl.it Pub Version

A Simple Neural Network library written in dart.

Inspired from Toy Neural Network library by Coding Train.

Usage #

Create a neural network brain with any number of inputs, hidden layers and output nodes.

// Use Layer to create a layer with x nodes and activation function
var brain = NeuralNetwork(2, [Layer(3, 'LeakyRelu'), Layer(2, 'LeakyRelu')], Layer(1, 'Sigmoid'));

You can also set the learning rate.

brain.setLearningRate(learning_rate: 0.01);

Pass in training data with inputs and outputs to the train function. And run the loop for any arbitrary number of epochs.

// XOR training data
var train_data = [
  {
    'inputs': [1.0, 1.0],
    'outputs': [0.0],
  },
  {
    'inputs': [0.0, 0.0],
    'outputs': [0.0],
  },
  {
    'inputs': [0.0, 1.0],
    'outputs': [1.0],
  },
  {
    'inputs': [1.0, 0.0],
    'outputs': [1.0],
  }
];
var epoch = 50000;

var rnd = Random();
for (var i = 0; i < epoch; i++) {
  var d = rnd.nextInt(4);
  brain.train(train_data[d]['inputs'], train_data[d]['outputs']);
}

You can then test the NeuralNetwork by passing in the test data to the predict function.

for (var i = 0; i < train_data.length; i++) {
  print("Test: In: ${train_data[i]['inputs']} Out: ${brain.predict(train_data[i]['inputs'])}");
}

You can clone the brain using the clone method.

var brain2 = brain.clone();

You can serialize the brain to save in a file. And later retrieve the brain using the deserialize method.

var brain2serialized = NeuralNetwork.serialize(brain2);
// You can save the `brain2serialized` string to any file.
var brain3 = NeuralNetwork.deserialize(brain2serialized);

License #

license.

7
likes
100
pub points
0%
popularity

Publisher

vickylance.com

A simple neural network library. You can create a simple fully connected neural network brain with any number of inputs, hidden layers and outputs.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

Dependencies

dart_numerics, path

More

Packages that depend on dart_nn