Skip to content

Commit

Permalink
fix: TrainStream, CrossValidate, and Typescript
Browse files Browse the repository at this point in the history
Overhauled the internals of TrainStream and CrossValidate so they are decoupled from the networks themselves, as well as being able to restore or store CrossValidate from json.

Added examples for CrossValidate and TrainStream, and as well one for learning math, to test the typescript type file.

Too I added missing typescript configs and examples.

*
  • Loading branch information
robertleeplummerjr committed Sep 20, 2018
1 parent d9b853e commit eebe6c8
Show file tree
Hide file tree
Showing 47 changed files with 17,821 additions and 16,502 deletions.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
+ [For training with `RNN`, `LSTM` and `GRU`](#for-training-with-rnn-lstm-and-gru)
+ [Training Options](#training-options)
+ [Async Training](#async-training)
+ [Cross Validation](#cross-validation)
+ [Train Stream](#train-stream)
- [Methods](#methods)
+ [train](#train)
- [Failing](#failing)
Expand Down Expand Up @@ -274,6 +276,49 @@ With multiple networks you can train in parallel like this:
.catch(handleError);
```

### Cross Validation
[Cross Validation](https://en.wikipedia.org/wiki/Cross-validation_(statistics)) can provide a less fragile way of training on larger data sets. The brain.js api provides Cross Validation in this example:
```js
const crossValidate = new CrossValidate(brain.NeuralNetwork);
const stats = crossValidate.train(data, networkOptions, trainingOptions, k); //note k (or KFolds) is optional
const net = crossValidate.toNetwork();


// optionally later
const json = crossValidate.toJSON();
const net = crossValidate.fromJSON(json);
```

An example of using cross validate can be found in [examples/cross-validate.js](examples/cross-validate.js)

### Train Stream
Streams are a very powerful tool in node for massive data spread across processes and are provided via the brain.js api in the following way:
```js
const net = new brain.NeuralNetwork();
const trainStream = new brain.TrainStream({
neuralNetwork: net,
floodCallback: function() {
flood(trainStream, data);
},
doneTrainingCallback: function(stats) {
// network is done training! What next?
}
});

// kick it off
readInputs(trainStream, data);

function readInputs(stream, data) {
for (let i = 0; i < data.length; i++) {
stream.write(data[i]);
}
// let it know we've reached the end of the inputs
stream.endInputs();
}
```

An example of using train stream can be found in [examples/stream-example.js](examples/stream-example.js)

# Methods
### train
The output of `train()` is a hash of information about how the training went:
Expand Down Expand Up @@ -341,7 +386,7 @@ The network now has a [WriteStream](http://nodejs.org/api/stream.html#stream_cla


### Example
Refer to [`stream-example.js`](./examples/cli/stream-example.js) for an example on how to train the network with a stream.
Refer to [`stream-example.js`](examples/stream-example.js) for an example on how to train the network with a stream.


### Initialization
Expand Down
Loading

0 comments on commit eebe6c8

Please sign in to comment.