deeplearning4d 0.0.1

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

deeplearning4d

Deep learning library for Dart based on Tensorflow Playground Neural Net implementation.

Example


import 'package:deeplearning4d/deeplearning4d.dart';
import 'dataset.dart';

List<List<Node>> network = null;
int iterations = 400;
List<Example2D> trainData = classifyTwoGaussData(500.0, 0.1);
List<Example2D> testData = classifyTwoGaussData( 50.0, 0.1);
double learningRate = 0.03;
double regularizationRate = 0.0;
double lossTrain = 0.0;
double lossTest = 0.0;
int batchSize = 30;


void main() {
  network = buildNetwork([2, 1, 1], Activations.RELU, Activations.TANH, RegularizationFunctions.L1, ["x", "y"], initZero: false);
  lossTrain = getLoss(network, trainData);
  lossTest = getLoss(network, testData);
  for (int i = 0; i < iterations; i ++) {
    oneStep();
  }
}

oneStep() {
  trainData.asMap().forEach((i, example2D) {
    List<double> input = constructInput(example2D.x, example2D.y);
    forwardProp(network, input);
    backProp(network, example2D.label, Errors.SQUARE);
    if ((i + 1) % batchSize == 0) {
      updateWeights(network, learningRate, regularizationRate);
    }
  });
// Compute the loss.
  lossTrain = getLoss(network, trainData);
  lossTest = getLoss(network, testData);
  print(lossTest.toString() + ',       ' + lossTrain.toString());
}


List<double> constructInput(double x, double y) {
  List<double> input = <double>[];
  input.add(x);
  input.add(y);
  return input;
}

double getLoss(List<List<Node>> network, List<Example2D> dataPoints) {
  double loss = 0.0;
  for (int i = 0; i < dataPoints.length; i++) {
    Example2D dataPoint = dataPoints[i];
    List<double> input = constructInput(dataPoint.x, dataPoint.y);
    double output = forwardProp(network, input);
    loss += Errors.SQUARE.error(output, dataPoint.label);
  }
  return loss / dataPoints.length;
}

Changelog

0.0.1

  • Initial version

example/deeplearning4d_example.dart

/* Copyright 2017. Marat Gubaidullin. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/

import 'package:deeplearning4d/deeplearning4d.dart';
import 'dataset.dart';

List<List<Node>> network = null;
int iterations = 400;
List<Example2D> trainData = classifyTwoGaussData(500.0, 0.1);
List<Example2D> testData = classifyTwoGaussData( 50.0, 0.1);
double learningRate = 0.03;
double regularizationRate = 0.0;
double lossTrain = 0.0;
double lossTest = 0.0;
int batchSize = 30;


void main() {
  network = buildNetwork([2, 1, 1], Activations.RELU, Activations.TANH, RegularizationFunctions.L1, ["x", "y"], initZero: false);
  lossTrain = getLoss(network, trainData);
  lossTest = getLoss(network, testData);
  for (int i = 0; i < iterations; i ++) {
    oneStep();
  }
}

oneStep() {
  trainData.asMap().forEach((i, example2D) {
    List<double> input = constructInput(example2D.x, example2D.y);
    forwardProp(network, input);
    backProp(network, example2D.label, Errors.SQUARE);
    if ((i + 1) % batchSize == 0) {
      updateWeights(network, learningRate, regularizationRate);
    }
  });
// Compute the loss.
  lossTrain = getLoss(network, trainData);
  lossTest = getLoss(network, testData);
  print(lossTest.toString() + ',       ' + lossTrain.toString());
}


List<double> constructInput(double x, double y) {
  List<double> input = <double>[];
  input.add(x);
  input.add(y);
  return input;
}

double getLoss(List<List<Node>> network, List<Example2D> dataPoints) {
  double loss = 0.0;
  for (int i = 0; i < dataPoints.length; i++) {
    Example2D dataPoint = dataPoints[i];
    List<double> input = constructInput(dataPoint.x, dataPoint.y);
    double output = forwardProp(network, input);
    loss += Errors.SQUARE.error(output, dataPoint.label);
  }
  return loss / dataPoints.length;
}

Use this package as a library

1. Depend on it

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


dependencies:
  deeplearning4d: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:deeplearning4d/deeplearning4d.dart';
  
Version Uploaded Documentation Archive
0.0.1 Aug 17, 2017 Go to the documentation of deeplearning4d 0.0.1 Download deeplearning4d 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0