-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix CrossValidate to have tests for when data too small
Also upgrade to use newer es6 syntax for defining optional properties. Upgrade examples to be more straightforward when using CrossValidate. Fix values from being set to NaN when training with smaller data in CrossValidate.
- Loading branch information
1 parent
f0a1a56
commit ca437f3
Showing
14 changed files
with
85 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,5 +31,5 @@ | |
"node_modules", | ||
"test" | ||
], | ||
"version": "1.4.1" | ||
"version": "1.4.2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import assert from 'assert'; | ||
import brain from '../../src'; | ||
import CrossValidate from '../../src/cross-validate'; | ||
|
||
describe('CrossValidation', () => { | ||
describe('simple xor example', () => { | ||
it('throws exception when training set is too small', () => { | ||
const xorTrainingData = [ | ||
{ input: [0, 1], output: [1] }, | ||
{ input: [0, 0], output: [0] }, | ||
{ input: [1, 1], output: [0] }, | ||
{ input: [1, 0], output: [1] } | ||
]; | ||
const net = new CrossValidate(brain.NeuralNetwork); | ||
assert.throws(() => { | ||
net.train(xorTrainingData); | ||
}); | ||
}); | ||
it('handles training and outputs values that are all numbers', () => { | ||
const xorTrainingData = [ | ||
{ input: [0, 1], output: [1] }, | ||
{ input: [0, 0], output: [0] }, | ||
{ input: [1, 1], output: [0] }, | ||
{ input: [1, 0], output: [1] }, | ||
|
||
{ input: [0, 1], output: [1] }, | ||
{ input: [0, 0], output: [0] }, | ||
{ input: [1, 1], output: [0] }, | ||
{ input: [1, 0], output: [1] } | ||
]; | ||
const net = new CrossValidate(brain.NeuralNetwork); | ||
net.train(xorTrainingData); | ||
const json = net.toJSON(); | ||
for (let p in json.avgs) { | ||
assert(json.avgs[p] >= 0); | ||
} | ||
for (let p in json.stats) { | ||
assert(json.stats[p] >= 0); | ||
} | ||
}); | ||
}); | ||
}); |