-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Handles User Object Validation #142 #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,4 +166,94 @@ describe('train() and trainAsync() use the same private methods', () => { | |
| done() | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('training options validation', () => { | ||
| it('iterations validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ iterations: 'should be a string' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ iterations: () => {} }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ iterations: false }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ iterations: -1 }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ iterations: 5000 }) }); | ||
| }); | ||
|
|
||
| it('errorThresh validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ errorThresh: 'no strings'}) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ errorThresh: () => {} }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ errorThresh: 5}) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ errorThresh: -1}) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ errorThresh: false}) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ errorThresh: 0.008}) }); | ||
| }); | ||
|
|
||
| it('log validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ log: 'no strings' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ log: 4 }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ log: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ log: () => {} }) }); | ||
| }); | ||
|
|
||
| it('logPeriod validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ logPeriod: 'no strings' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ logPeriod: -50 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ logPeriod: () => {} }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ logPeriod: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ logPeriod: 40 }) }); | ||
| }); | ||
|
|
||
| it('learningRate validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ learningRate: 'no strings' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ learningRate: -50 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ learningRate: 50 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ learningRate: () => {} }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ learningRate: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ learningRate: 0.5 }) }); | ||
| }); | ||
|
|
||
| it('momentum validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ momentum: 'no strings' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ momentum: -50 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ momentum: 50 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ momentum: () => {} }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ momentum: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ momentum: 0.8 }) }); | ||
| }); | ||
|
|
||
| it('callback validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ callback: 'no strings' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ callback: 4 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ callback: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ callback: null }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ callback: () => {} }) }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a "valid" callback?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep (it just does nothing with the passed in object, I am not enforcing the params) |
||
| }); | ||
|
|
||
| it('callbackPeriod validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ callbackPeriod: 'no strings' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ callbackPeriod: -50 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ callbackPeriod: () => {} }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ callbackPeriod: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ callbackPeriod: 40 }) }); | ||
| }); | ||
|
|
||
| it('timeout validation', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.throws(() => { net._updateTrainingOptions({ timeout: 'no strings' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ timeout: -50 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ timeout: () => {} }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ timeout: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ timeout: 40 }) }); | ||
| }); | ||
|
|
||
| it('should handle unsupported options', () => { | ||
| let net = new brain.NeuralNetwork(); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ fakeProperty: 'should be handled fine' }) }); | ||
| }) | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a "valid" log function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it would be user defined. (logging allows the user to either set true and it will console.log or set their own method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the
logvalue can be user defined, that's the point ofcallback. Buuuuuut, I was a bit too hasty with this and the other "Valid callback" comment. This is fine with me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. The main idea is so that if the user has their own logging system (i.e. it writes to file or whatever) then they can keep the log to do just that, without having to use up their callback for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh, I don't think it would "use up" their callback. But this is a moot point, we can continue discussion outside of this PR.