Coder Social home page Coder Social logo

mind's Introduction

Mind Logo

A flexible neural network library for Node.js and the browser. Check out a live demo of a movie recommendation engine built with Mind.

NPM version build status license

Features

  • Vectorized - uses a matrix implementation to efficiently process training data
  • Transformable - apply transforms so you can pass in diverse datasets
  • Configurable - allows you to customize the network topology
  • Pluggable - download/upload minds that have already learned

Installation

$ npm install node-mind

Usage

var Mind = require('node-mind');
var mind = Mind();

/**
 * Letters.
 *
 * - Imagine these # and . represent black and white pixels.
 */

var a = character(
  '.####.' +
  '#....#' +
  '#....#' +
  '######' +
  '#....#' +
  '#....#' +
  '#....#'
);

var b = character(
  '#####.' +
  '#....#' +
  '#....#' +
  '#####.' +
  '#....#' +
  '#....#' +
  '#####.'
);

var c = character(
  '######' +
  '#.....' +
  '#.....' +
  '#.....' +
  '#.....' +
  '#.....' +
  '######'
);

/**
 * Learn the letters A through C.
 */

var mind = Mind()
  .learn([
    { input: a, output: [ 0.1 ] },
    { input: b, output: [ 0.2 ] },
    { input: c, output: [ 0.3 ] }
  ]);

/**
 * Predict the letter C, even with a pixel off.
 */

var result = mind.predict(character(
  '######' +
  '#.....' +
  '#.....' +
  '#.....' +
  '#.....' +
  '##....' +
  '######'
));

console.log(result); // ~ 0.3

/**
 * Turn the # into 1s and . into 0s.
 */

function character(string) {
  return string
    .trim()
    .split('')
    .map(integer);

  function integer(symbol) {
    if ('#' === symbol) return 1;
    if ('.' === symbol) return 0;
  }
};

You can use Mind in the browser by requiring it with Duo or Browserify. Or you can simply use the prebuilt root index.js file directly, which will expose Mind on the window object.

Plugins

Use plugins created by the Mind community to configure pre-trained networks that can go straight to making predictions.

Here's a cool example of the way you could use a hypothetical mind-ocr plugin:

var Mind = require('node-mind');
var ocr = require('mind-ocr');

var mind = Mind()
  .upload(ocr)
  .predict(
    '.####.' +
    '#....#' +
    '#....#' +
    '######' +
    '#....#' +
    '#....#' +
    '#....#'
  );

To create a plugin, simply call download on your trained mind:

var Mind = require('node-mind');

var mind = Mind()
  .learn([
    { input: [0, 0], output: [ 0 ] },
    { input: [0, 1], output: [ 1 ] },
    { input: [1, 0], output: [ 1 ] },
    { input: [1, 1], output: [ 0 ] }
  ]);

var xor = mind.download();

Here's a list of available plugins:

Transforms

Use transforms so you can perform analysis on any dataset. A transform is just an object with a before function and an after function, which will be applied to each data point before and after analysis. Here's an example currency transform:

var currency = {
  before: function(value) {
    return Number(value.slice(1));
  },
  after: function(value) {
    return '$' + value;
  }
};

You can apply this transform to the dataset in the following way:

var currency = require('mind-currency');
var Mind = require('node-mind');

var mind = Mind()
  .transform(currency)
  .learn([
    { input: ["$1500", "$870"], output: [ "$1010" ] },
    { input: ["$1400", "$700"], output: [ "$1140" ] },
    { input: ["$2000", "$1100"], output: [ "$1432" ] },
    { input: ["$1800", "$1000"], output: [ "$910" ] }
  ])
  .predict([ "$3288", "$170" ]);

Here's a list of available transforms:

API

Mind(options)

Create a new instance of Mind that can learn to make predictions.

The available options are:

  • learningRate: how quickly the network should learn.
  • hiddenNeurons: how many neurons are in the hidden layer.
  • activator: which activation function to use, sigmoid or htan.
  • iterations: the number of iterations to run.

.learn()

Learn from training data:

mind.learn([
  { input: [0, 0], output: [ 0 ] },
  { input: [0, 1], output: [ 1 ] },
  { input: [1, 0], output: [ 1 ] },
  { input: [1, 1], output: [ 0 ] }
]);

.predict()

Make a new prediction:

mind.predict([0, 1]);

.download()

Download the mind:

var xor = mind.download();

.upload()

Upload a mind:

mind.upload(xor);

Note

This is a very simple library and there are far more sophisticated neural network libraries out there. Why did I build Mind then? Because I love figuring out how things work and sometimes you just need to build shit in order to understand how they work. Also, I wanted to write a library with clear, readable code that wouldn't scare newcomers away from the wonderful world of machine learning :)

If you're interested in learning more about neural networks, you'll definitely want to check out these fantastic libraries:

License

MIT

mind's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.