ai 0.1.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 59

Library for creating AI with Dart #

Created under a MIT-style license.

Overview #

This library represent an simple way to create neural network. Currently multilayer and single-layer perceptron can be created. In learning used backpropagation algorithm for both of them.

API #

Perseptron is designed due to Rosenblatt's perseptron.

The main class is the MultilayerPerseptron which can contains Layers. Each layer consist of one or many Neurons. First layer always consist of InputNeurons where each of them take one input value and have weight equal to 1. All neurons of previous layer have contacts with each neurons of next layer.

Memory #

Neural network have long-time and short-time memory. All information (knowledge - weights of synapces) of neural network during studying pass through short-time memory. When studying finished and knowledge is structured, then it pass to long-time memory. Knowledge is saved in JSON file knowledge.json in resources directory. For next time network take knowledge from file and initialize with proper weights.

Sample #

This testing network recognize number 5 from numbers in range from 0 to 9. Also she detects distorted numbers of 5.

Numbers

import 'package:ai/ai.dart';

void main() {
  final l1 = Layer<InputNeuron>(<InputNeuron>[
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron()
  ]);
  final l2 = Layer<Neuron>(<Neuron>[
    Neuron(15),
    Neuron(15),
    Neuron(15),
    Neuron(15),
    Neuron(15)
  ]);
  final l3 = Layer<Neuron>(<Neuron>[
    Neuron(5)
  ]);
  final n = MultilayerPerceptron(<Layer<NeuronBase>>[
    l1,
    l2,
    l3
  ]);

  final expected = <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01];

  // Learning data
  final trainInput = <List<double>>[
    '111101101101111'.split('').map(double.parse).toList(),
    '001001001001001'.split('').map(double.parse).toList(),
    '111001111100111'.split('').map(double.parse).toList(),
    '111001111001111'.split('').map(double.parse).toList(),
    '101101111001001'.split('').map(double.parse).toList(),
    '111100111001111'.split('').map(double.parse).toList(), // 5
    '111100111101111'.split('').map(double.parse).toList(),
    '111001001001001'.split('').map(double.parse).toList(),
    '111101111101111'.split('').map(double.parse).toList(),
    '111101111001111'.split('').map(double.parse).toList()
  ];

  // Testing data
  final testInput = <List<double>>[
    '111100111000111'.split('').map(double.parse).toList(),
    '111100010001111'.split('').map(double.parse).toList(),
    '111100011001111'.split('').map(double.parse).toList(),
    '110100111001111'.split('').map(double.parse).toList(),
    '110100111001011'.split('').map(double.parse).toList(),
    '111100101001111'.split('').map(double.parse).toList()
  ];

  // Number which this network must recognize
  final num5 = '111100111001111'.split('').map(double.parse).toList();

  // This network trains
  n.train(input: trainInput, expected: expected, learningRate: 0.42, epoch: 5000);

  // This network predicts result
  print('Recognize 5? - ${n.predict(num5)}');
  for (var item in testInput) {
    print('Recognize distorted 5? - ${n.predict(item)[0]}');
  }
  print('Аnd 0? - ${n.predict(trainInput[0])}');
  print('Аnd 8? - ${n.predict(trainInput[8])}');
  print('Аnd 3? - ${n.predict(trainInput[3])}');

Features and bugs #

Please file feature requests and bugs at the issue tracker.

With ❤️ to AI

0.1.3 #

  • Fix internal createFile() method for ...Memory class.
  • Change docs in ShortMemory class.

0.1.2 #

  • Fix expected parameter of train() method of MuslilayerPerceptron to accept list of expected output.

0.1.1 #

  • Add MemoryBase class.
  • Add description to package.

0.1.0 #

  • Initial release.
  • Implement MultilayerPerseptron class.

example/ai_example.dart

import 'package:ai/ai.dart';

void main() {
  final l1 = Layer<InputNeuron>(<InputNeuron>[
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron(),
    InputNeuron()
  ]);
  final l2 = Layer<Neuron>(<Neuron>[
    Neuron(15),
    Neuron(15),
    Neuron(15),
    Neuron(15),
    Neuron(15)
  ]);
  final l3 = Layer<Neuron>(<Neuron>[
    Neuron(5)
  ]);
  final n = MultilayerPerceptron(<Layer<NeuronBase>>[
    l1,
    l2,
    l3
  ]);

  // Expected results according to learning data (10)
  final expected = <List<double>>[
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01],
    <double>[0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01]
  ];

  // Learning data (10)
  final trainInput = <List<double>>[
    '111101101101111'.split('').map(double.parse).toList(),
    '001001001001001'.split('').map(double.parse).toList(),
    '111001111100111'.split('').map(double.parse).toList(),
    '111001111001111'.split('').map(double.parse).toList(),
    '101101111001001'.split('').map(double.parse).toList(),
    '111100111001111'.split('').map(double.parse).toList(), // 5
    '111100111101111'.split('').map(double.parse).toList(),
    '111001001001001'.split('').map(double.parse).toList(),
    '111101111101111'.split('').map(double.parse).toList(),
    '111101111001111'.split('').map(double.parse).toList()
  ];

  // Testing data
  final testInput = <List<double>>[
    '111100111000111'.split('').map(double.parse).toList(),
    '111100010001111'.split('').map(double.parse).toList(),
    '111100011001111'.split('').map(double.parse).toList(),
    '110100111001111'.split('').map(double.parse).toList(),
    '110100111001011'.split('').map(double.parse).toList(),
    '111100101001111'.split('').map(double.parse).toList()
  ];

  // Number which this network must recognize
  final num5 = '111100111001111'.split('').map(double.parse).toList();

  // This network trains
  n.train(input: trainInput, expected: expected, learningRate: 0.42, epoch: 5000);

  // This network predicts result
  print('Recognize 5? - ${n.predict(num5)}');
  for (var item in testInput) {
    print('Recognize distorted 5? - ${n.predict(item)[0]}');
  }
  print('Аnd 0? - ${n.predict(trainInput[0])}');
  print('Аnd 8? - ${n.predict(trainInput[8])}');
  print('Аnd 3? - ${n.predict(trainInput[3])}');
}

Use this package as a library

1. Depend on it

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


dependencies:
  ai: ^0.1.3

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:ai/ai.dart';
  
Version Uploaded Documentation Archive
0.1.10 May 10, 2019 Go to the documentation of ai 0.1.10 Download ai 0.1.10 archive
0.1.9 Mar 14, 2019 Go to the documentation of ai 0.1.9 Download ai 0.1.9 archive
0.1.8+1 Mar 3, 2019 Go to the documentation of ai 0.1.8+1 Download ai 0.1.8+1 archive
0.1.8 Feb 14, 2019 Go to the documentation of ai 0.1.8 Download ai 0.1.8 archive
0.1.7 Feb 1, 2019 Go to the documentation of ai 0.1.7 Download ai 0.1.7 archive
0.1.6 Jan 26, 2019 Go to the documentation of ai 0.1.6 Download ai 0.1.6 archive
0.1.5 Jan 25, 2019 Go to the documentation of ai 0.1.5 Download ai 0.1.5 archive
0.1.4 Jan 17, 2019 Go to the documentation of ai 0.1.4 Download ai 0.1.4 archive
0.1.3 Jan 14, 2019 Go to the documentation of ai 0.1.3 Download ai 0.1.3 archive
0.1.2 Jan 13, 2019 Go to the documentation of ai 0.1.2 Download ai 0.1.2 archive

All 11 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
56
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on May 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.16

Platforms

Detected platforms: Flutter, other

Primary library: package:ai/ai.dart with components: io.

Health issues and suggestions

Fix lib/src/neuron/base/neuron_base.dart. (-43.75 points)

Analysis of lib/src/neuron/base/neuron_base.dart failed with 2 errors:

line 29 col 30: Too many positional arguments: 0 expected, but 1 found.

line 59 col 37: The method 'dotProduct' isn't defined for the class 'Vector'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
extended_math ^0.0.14 0.0.28
meta ^1.1.7 1.1.7
Transitive dependencies
matcher 0.12.5
path 1.6.2
quiver 2.0.3
stack_trace 1.9.3
Dev dependencies
test ^1.5.1