Skip to content

Commit 287288b

Browse files
Merge branch 'master' into v1.x
2 parents a82faba + 45ce6ff commit 287288b

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

README.md

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33

44
<img src="https://cdn.rawgit.com/harthur-org/brain.js/ff595242/logo.svg" alt="Logo" width=200px/>
55

6-
[![npm](https://img.shields.io/npm/dt/brain.js.svg?style=flat-square)](https://npmjs.com/package/brain.js)
7-
8-
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/brain-js/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6+
[![npm](https://img.shields.io/npm/dt/brain.js.svg?style=flat-square)](https://npmjs.com/package/brain.js)
7+
[![Backers on Open Collective](https://opencollective.com/brainjs/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/brainjs/sponsors/badge.svg)](#sponsors)
98

10-
[![Slack](https://slack.bri.im/badge.svg)](https://slack.bri.im)
9+
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/brain-js/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Slack](https://slack.bri.im/badge.svg)](https://slack.bri.im)
1110

12-
[![Backers on Open Collective](https://opencollective.com/brainjs/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/brainjs/sponsors/badge.svg)](#sponsors)
11+
## About
1312

1413
`brain.js` is a library of [Neural Networks](http://en.wikipedia.org/wiki/Artificial_neural_network) written in JavaScript.
1514

1615
:bulb: **Note**: This is a continuation of the [**harthur/brain**](https://github.com/harthur/brain) repository (which is not maintained anymore). For more details, check out [this issue](https://github.com/harthur/brain/issues/72).
1716

17+
## Table of Contents
18+
1819
- [Examples](#examples)
1920
+ [More Examples](#more-examples)
2021
- [Usage](#usage)
@@ -45,57 +46,60 @@
4546

4647
# Examples
4748
Here's an example showcasing how to approximate the XOR function using `brain.js`:
48-
More info on config [here](https://github.com/BrainJS/brain.js/blob/develop/src/neural-network.js#L31).
49+
more info on config [here](https://github.com/BrainJS/brain.js/blob/develop/src/neural-network.js#L31).
4950

5051
```javascript
51-
//provide optional config object (or undefined). Defaults shown.
52-
var config = {
52+
// provide optional config object (or undefined). Defaults shown.
53+
const config = {
5354
binaryThresh: 0.5, // ¯\_(ツ)_/¯
5455
hiddenLayers: [3], // array of ints for the sizes of the hidden layers in the network
55-
activation: 'sigmoid' // Supported activation types ['sigmoid', 'relu', 'leaky-relu', 'tanh']
56-
}
57-
//create a simple feed forward neural network with backpropagation
58-
var net = new brain.NeuralNetwork();
56+
activation: 'sigmoid' // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh']
57+
};
58+
59+
// create a simple feed forward neural network with backpropagation
60+
const net = new brain.NeuralNetwork(config);
5961

6062
net.train([{input: [0, 0], output: [0]},
6163
{input: [0, 1], output: [1]},
6264
{input: [1, 0], output: [1]},
6365
{input: [1, 1], output: [0]}]);
6466

65-
var output = net.run([1, 0]); // [0.987]
67+
const output = net.run([1, 0]); // [0.987]
6668
```
6769
or
68-
More info on config [here](https://github.com/BrainJS/brain.js/blob/develop/src/recurrent/rnn.js#L726).
70+
more info on config [here](https://github.com/BrainJS/brain.js/blob/develop/src/recurrent/rnn.js#L726).
71+
6972
```javascript
70-
//provide optional config object, defaults shown.
71-
var config = {
73+
// provide optional config object, defaults shown.
74+
const config = {
7275
inputSize: 20,
7376
inputRange: 20,
74-
hiddenSizes:[20,20],
77+
hiddenSizes: [20,20],
7578
outputSize: 20,
7679
learningRate: 0.01,
7780
decayRate: 0.999,
78-
}
79-
//create a simple recurrent neural network
80-
var net = new brain.recurrent.RNN(config);
81+
};
82+
83+
// create a simple recurrent neural network
84+
const net = new brain.recurrent.RNN(config);
8185

8286
net.train([{input: [0, 0], output: [0]},
8387
{input: [0, 1], output: [1]},
8488
{input: [1, 0], output: [1]},
8589
{input: [1, 1], output: [0]}]);
8690

87-
var output = net.run([0, 0]); // [0]
88-
output = net.run([0, 1]); // [1]
89-
output = net.run([1, 0]); // [1]
90-
output = net.run([1, 1]); // [0]
91+
let output = net.run([0, 0]); // [0]
92+
output = net.run([0, 1]); // [1]
93+
output = net.run([1, 0]); // [1]
94+
output = net.run([1, 1]); // [0]
9195
```
9296

9397
However, there is no reason to use a neural network to figure out XOR. (-: So, here is a more involved, realistic example:
9498
[Demo: training a neural network to recognize color contrast](https://brain.js.org/).
9599

96100
## More Examples
97-
You check out this fantastic screencast, which explains how to train a simple neural network using a real world dataset: [How to create a neural network in the browser using Brain.js](https://scrimba.com/c/c36zkcb).
98-
* [writing a children's book using a recurrent neural neural network](./examples/childrens-book.js)
101+
You can check out this fantastic screencast, which explains how to train a simple neural network using a real world dataset: [How to create a neural network in the browser using Brain.js](https://scrimba.com/c/c36zkcb).
102+
* [writing a children's book using a recurrent neural network](./examples/childrens-book.js)
99103
* [simple letter detection](./examples/which-letter-simple.js)
100104

101105
# Usage
@@ -112,12 +116,7 @@ Or if you prefer yarn:
112116
yarn add brain.js
113117
```
114118

115-
Alternatively, you can install `brain.js` with [bower](https://bower.io/):
116-
```
117-
bower install brain.js
118-
```
119-
120-
At present, the npm version of brain.js is approximately 1.0.0, featuring only Feed forward NN. All other models are beta and are being jazzed up and battle hardened.
119+
At present, the published version of brain.js is approximately 1.0.0, featuring only Feed-forward NN. All other models are beta and are being jazzed up and battle hardened.
121120
You can still download the latest, though. They are cool!
122121

123122
### Browser
@@ -233,7 +232,7 @@ net.train(data, {
233232

234233
The network will stop training whenever one of the two criteria is met: the training error has gone below the threshold (default `0.005`), or the max number of iterations (default `20000`) has been reached.
235234

236-
By default training will not let you know how its doing until the end, but set `log` to `true` to get periodic updates on the current training error of the network. The training error should decrease every time. The updates will be printed to console. If you set `log` to a function, this function will be called with the updates instead of printing to the console.
235+
By default training will not let you know how it's doing until the end, but set `log` to `true` to get periodic updates on the current training error of the network. The training error should decrease every time. The updates will be printed to console. If you set `log` to a function, this function will be called with the updates instead of printing to the console.
237236

238237
The learning rate is a parameter that influences how quickly the network trains. It's a number from `0` to `1`. If the learning rate is close to `0`, it will take longer to train. If the learning rate is closer to `1`, it will train faster, but training results may be constrained to a local minimum and perform badly on new data.(_Overfitting_) The default learning rate is `0.3`.
239238

@@ -258,17 +257,17 @@ A boolean property called `invalidTrainOptsShouldThrow` is set to `true` by defa
258257
With multiple networks you can train in parallel like this:
259258

260259
```javascript
261-
var net = new brain.NeuralNetwork();
262-
var net2 = new brain.NeuralNetwork();
260+
const net = new brain.NeuralNetwork();
261+
const net2 = new brain.NeuralNetwork();
263262

264-
var p1 = net.trainAsync(data, options);
265-
var p2 = net2.trainAsync(data, options);
263+
const p1 = net.trainAsync(data, options);
264+
const p2 = net2.trainAsync(data, options);
266265

267266
Promise
268267
.all([p1, p2])
269268
.then(values => {
270-
var res = values[0];
271-
var res2 = values[1];
269+
const res = values[0];
270+
const res2 = values[1];
272271
console.log(`net trained in ${res.iterations} and net2 trained in ${res2.iterations}`);
273272
// do something super cool with my 2 trained networks
274273
})
@@ -295,23 +294,23 @@ If the training error is still something huge like `0.4` after 20000 iterations,
295294
Serialize or load in the state of a trained network with JSON:
296295

297296
```javascript
298-
var json = net.toJSON();
297+
const json = net.toJSON();
299298
net.fromJSON(json);
300299
```
301300

302301
You can also get a custom standalone function from a trained network that acts just like `run()`:
303302

304303
```javascript
305-
var run = net.toFunction();
306-
var output = run({ r: 1, g: 0.4, b: 0 });
304+
const run = net.toFunction();
305+
const output = run({ r: 1, g: 0.4, b: 0 });
307306
console.log(run.toString()); // copy and paste! no need to import brain.js
308307
```
309308

310309
# Options
311310
`NeuralNetwork()` takes a hash of options:
312311

313312
```javascript
314-
var net = new brain.NeuralNetwork({
313+
const net = new brain.NeuralNetwork({
315314
activation: 'sigmoid', // activation function
316315
hiddenLayers: [4],
317316
learningRate: 0.6 // global learning rate, useful when training using streams
@@ -326,7 +325,7 @@ This parameter lets you specify which activation function your neural network sh
326325
- [leaky-relu](https://www.wikiwand.com/en/Rectifier_(neural_networks))
327326
- [tanh](https://theclevermachine.wordpress.com/tag/tanh-function/)
328327

329-
Here's a table (Thanks, Wikipedia!) summarizing a plethora of activation functions — [Activation Function](https://www.wikiwand.com/en/Activation_function)
328+
Here's a table (thanks, Wikipedia!) summarizing a plethora of activation functions — [Activation Function](https://www.wikiwand.com/en/Activation_function)
330329

331330
### hiddenLayers
332331
You can use this to specify the number of hidden layers in the network and the size of each layer. For example, if you want two hidden layers - the first with 3 nodes and the second with 4 nodes, you'd give:
@@ -362,11 +361,14 @@ To train the network using a stream you must first create the stream by calling
362361
Use a [Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform) to coerce the data into the correct format. You might also use a Transform stream to normalize your data on the fly.
363362

364363
# Utilities
364+
365365
### `likely`
366+
366367
```js
367-
var likely = require('brain/likely');
368-
var key = likely(input, net);
368+
const likely = require('brain/likely');
369+
const key = likely(input, net);
369370
```
371+
370372
Likely example see: [simple letter detection](./examples/which-letter-simple.js)
371373

372374
# Neural Network Types
@@ -385,7 +387,9 @@ Different neural nets do different things well. For example:
385387
* A Recurrent Neural Network _remembers_, and has a finite set of results.
386388

387389
# Get Involved!
390+
388391
### Issues
392+
389393
If you have an issue, either a bug or a feature you think would benefit your project let us know and we will do our best.
390394

391395
Create issues [here](https://github.com/BrainJS/brain.js/issues) and follow the template.
@@ -417,5 +421,3 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
417421
<a href="https://opencollective.com/brainjs/sponsor/7/website" target="_blank"><img src="https://opencollective.com/brainjs/sponsor/7/avatar.svg"></a>
418422
<a href="https://opencollective.com/brainjs/sponsor/8/website" target="_blank"><img src="https://opencollective.com/brainjs/sponsor/8/avatar.svg"></a>
419423
<a href="https://opencollective.com/brainjs/sponsor/9/website" target="_blank"><img src="https://opencollective.com/brainjs/sponsor/9/avatar.svg"></a>
420-
421-

0 commit comments

Comments
 (0)