dart_nn 2.0.0+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

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.

1.0.0 #

  • Initial working version completed.
  • Added ability to create a simple neural network with 1 hidden layer and any number of input, hidden or output nodes.
  • Added json serialization and deserialization for Matrix and NeuralNetwork.
  • Added clone method to make multiple copies if NeuralNetwork brain.

1.0.1 #

  • Fixed file naming in example.

1.0.2 #

  • Added README to example folder.

1.0.3 #

  • Fixed package description.

1.0.3+1 #

  • Updated pubspec.yaml file.

1.0.3+2 #

  • Updated pubspec.yaml file.

1.0.3+3 #

  • Fixed Iris example.

1.0.4 #

  • Added ability to define different activation functions for hidden and output layer.

2.0.0 #

  • Added ability to define multilayered neural network

2.0.0+1 #

  • Update to description

2.0.0+2 #

  • Updated Readme.md

example/README.md

Examples #

This folder contains various examples on how you can use the library.

Currently there are 2 examples.

  • The classic XOR example
  • IRIS dataset example

Kindly check the respective folders for the implementation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_nn: ^2.0.0+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_nn/dart_nn.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
9
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Feb 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health issues and suggestions

Document public APIs. (-1 points)

82 out of 82 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
dart_numerics ^0.0.5 0.0.5
path ^1.6.4 1.6.4
Transitive dependencies
matcher 0.12.6
meta 1.1.8
quiver 2.1.2+1
stack_trace 1.9.3
tuple 1.0.3
Dev dependencies
csv ^4.0.3
pedantic ^1.9.0
test ^1.11.1