Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stevenmiller888/mind
A neural network library built in JavaScript
https://github.com/stevenmiller888/mind
mind neural-network prediction
Last synced: 27 days ago
JSON representation
A neural network library built in JavaScript
- Host: GitHub
- URL: https://github.com/stevenmiller888/mind
- Owner: stevenmiller888
- Created: 2015-07-06T20:26:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-16T22:53:44.000Z (over 2 years ago)
- Last Synced: 2024-10-01T22:21:46.854Z (about 1 month ago)
- Topics: mind, neural-network, prediction
- Language: JavaScript
- Homepage: http://stevenmiller888.github.io/mindjs.net/
- Size: 136 KB
- Stars: 1,510
- Watchers: 51
- Forks: 112
- Open Issues: 8
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
- awesome-javascript - mind - A neural network library built in JavaScript - ★ 1334 (Machine Learning)
README
[![](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
![Mind Logo](https://cldup.com/D1yUfBz7Iu.png)
[![CircleCI](https://circleci.com/gh/stevenmiller888/mind.svg?style=svg)](https://circleci.com/gh/stevenmiller888/mind)
A flexible neural network library for Node.js and the browser. Check out a live [demo](http://stevenmiller888.github.io/mindjs.net/) of a movie recommendation engine built with Mind.
## Features
- Vectorized - uses a matrix implementation to process training data
- Configurable - allows you to customize the network topology
- Pluggable - download/upload minds that have already learned## Installation
```bash
$ yarn add node-mind
```## Usage
```js
const Mind = require('node-mind');/**
* Letters.
*
* - Imagine these # and . represent black and white pixels.
*/const a = character(
'.#####.' +
'#.....#' +
'#.....#' +
'#######' +
'#.....#' +
'#.....#' +
'#.....#'
)const b = character(
'######.' +
'#.....#' +
'#.....#' +
'######.' +
'#.....#' +
'#.....#' +
'######.'
)const c = character(
'#######' +
'#......' +
'#......' +
'#......' +
'#......' +
'#......' +
'#######'
)/**
* Learn the letters A through C.
*/const mind = new Mind({ activator: 'sigmoid' })
.learn([
{ input: a, output: map('a') },
{ input: b, output: map('b') },
{ input: c, output: map('c') }
])/**
* Predict the letter C, even with a pixel off.
*/const result = mind.predict(character(
'#######' +
'#......' +
'#......' +
'#......' +
'#......' +
'##.....' +
'#######'
))console.log(result) // ~ 0.5
/**
* 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
}
}/**
* Map letter to a number.
*/function map(letter) {
if (letter === 'a') return [ 0.1 ]
if (letter === 'b') return [ 0.3 ]
if (letter === 'c') return [ 0.5 ]
return 0
}
```## 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:
```js
const Mind = require('node-mind')
const ocr = require('mind-ocr')const mind = Mind()
.upload(ocr)
.predict(
'.#####.' +
'#.....#' +
'#.....#' +
'#######' +
'#.....#' +
'#.....#' +
'#.....#'
)
```To create a plugin, simply call `download` on your trained mind:
```js
const Mind = require('node-mind')const mind = Mind()
.learn([
{ input: [0, 0], output: [ 0 ] },
{ input: [0, 1], output: [ 1 ] },
{ input: [1, 0], output: [ 1 ] },
{ input: [1, 1], output: [ 0 ] }
]);const xor = mind.download()
```Here's a list of available plugins:
- [xor](https://github.com/stevenmiller888/mind-xor)
## API
### Mind(options)
Create a new instance of Mind that can learn to make predictions.The available options are:
* `activator`: the activation function to use, `sigmoid` or `htan`
* `learningRate`: the speed at which the network will learn
* `hiddenUnits`: the number of units in the hidden layer/s
* `iterations`: the number of iterations to run
* `hiddenLayers`: the number of hidden layers#### .learn()
Learn from training data:
```js
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 prediction:
```js
mind.predict([0, 1])
```#### .download()
Download a mind:
```js
const xor = mind.download()
```#### .upload()
Upload a mind:
```js
mind.upload(xor)
```#### .on()
Listen for the 'data' event, which is fired with each iteration:
```js
mind.on('data', (iteration, errors, results) => {
// ...
})
```## Releasing / Publishing
CircleCI will handle publishing to npm. To cut a new release, just do:
```
$ git changelog --tag
$ vim package.json # enter
$ git release
```Where `` follows the [semver](http://semver.org/) spec.
## Note
If you're interested in learning more, I wrote a blog post on how to build your own neural network:
- [How to Build a Neural Network](http://stevenmiller888.github.io/mind-how-to-build-a-neural-network/)
Also, here are some fantastic libraries you can check out:
- [convnetjs](https://github.com/karpathy/convnetjs)
- [synaptic](https://github.com/cazala/synaptic)
- [brain](https://github.com/harthur-org/brain.js)## License
[MIT](https://tldrlegal.com/license/mit-license)
---
> [stevenmiller888.github.io](https://stevenmiller888.github.io) ·
> GitHub [@stevenmiller888](https://github.com/stevenmiller888) ·
> Twitter [@stevenmiller888](https://twitter.com/stevenmiller888)