-
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
Conversation
src/neural-network.js
Outdated
| }; | ||
| } | ||
|
|
||
| static get trainingValidations() { |
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.
Do we need a get for this? Why not just define these in the validation method itself?
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.
sorry I didn't see your comments but yeah I got rid of the getter/setter. Originally when they set this to false I was printing out a message showing what it would do, but I thought that overkill.
| iterations: (val) => { return typeof val === 'number' && val > 0; }, | ||
| errorThresh: (val) => { return typeof val === 'number' && val > 0 && val < 1; }, | ||
| log: (val) => { return typeof val === 'function' || typeof val === 'boolean'; }, | ||
| logPeriod: (val) => { return typeof val === 'number' && val > 0; }, |
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.
logPeriod only matters if you also defined log as well. I think these functions don't have to be a one-to-one mapping for the training options and can instead explicitly check the training options they are testing. This way, they all would be of the form (opts) => { ... }.
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 am not sure I completely understand your point. I could couple them so that we only check things that are dependent on each other and I could set them to check the value of the already set property. I chose not to because I wanted to keep each property decoupled. I think that will make it easier to extend (if you change the function of one property you don't have to worry about additional side effects) and I also didn't want to check every property each time I validate, just the properties that are changed. Does that make sense? I am open to changing but I don't yet understand the benefit.
src/neural-network.js
Outdated
| this.trainOpts = {}; | ||
| this._updateTrainingOptions(Object.assign({}, this.constructor.trainDefaults, options)); | ||
|
|
||
| this._isStrict = true; |
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.
If we are going to have multiple validation options, this should be contained within an object that contains the options and this as well. If we are not going to have multiple validation options, this should be named to something more descriptive, e.g. this._strictTrainingOptionValidation or something
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.
totally agree the name didn't fit. I ended up changing it before I saw this comment.
src/neural-network.js
Outdated
| * When true: setting a training option outside expected range will throw an error | ||
| * When false: setting a training option outside expected range will log out and continue | ||
| */ | ||
| get validateTrainingOptions() { return this._isStrict; } |
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.
Return an object? the name suggests there are multiple
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 see how that name suggests an object is returned. I did change it from being a getter/setter. Originally I was printing out the a log saying what was happening when you set it to false but I thought that was a bit overkill especially once someone understands already how it works.
src/neural-network.js
Outdated
| * When false: setting a training option outside expected range will log out and continue | ||
| */ | ||
| get validateTrainingOptions() { return this._isStrict; } | ||
| set validateTrainingOptions(s) { this._isStrict = s; } |
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.
pass in an object?
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.
yeah it was a setter/getter but I got rid of that (since there aren't any intentional side effects)
test/base/bitwise.js
Outdated
| {input: [1, 1], output: [0]}]; | ||
| testBitwiseAsync(xor, 'xor', done); | ||
| }).timeout(10000); | ||
| }).timeout(15000); |
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.
Why the change?
test/base/bitwise.js
Outdated
| {input: [1, 1], output: [1]}]; | ||
| testBitwiseAsync(or, 'or', done); | ||
| }).timeout(10000); | ||
| }).timeout(15000); |
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.
Why the change?
test/base/bitwise.js
Outdated
| {input: [1, 1], output: [1]}]; | ||
| testBitwiseAsync(and, 'and', done); | ||
| }).timeout(10000); | ||
| }).timeout(15000); |
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.
Why the change?
| assert.throws(() => { net._updateTrainingOptions({ log: 'no strings' }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ log: 4 }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ log: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ log: () => {} }) }); |
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 log value can be user defined, that's the point of callback. 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.
| assert.throws(() => { net._updateTrainingOptions({ callback: 4 }) }); | ||
| assert.throws(() => { net._updateTrainingOptions({ callback: false }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ callback: null }) }); | ||
| assert.doesNotThrow(() => { net._updateTrainingOptions({ callback: () => {} }) }); |
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" callback?
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 just does nothing with the passed in object, I am not enforcing the params)
|
@perkyguy I think this is ready for another look-see |
877adf1 to
b40f305
Compare
perkyguy
left a comment
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.
Questions more than anything
src/neural-network.js
Outdated
| this.trainOpts = {}; | ||
| this._updateTrainingOptions(Object.assign({}, this.constructor.trainDefaults, options)); | ||
|
|
||
| this.invalidTrainOptsShouldThrow = true; |
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.
why put this on the instance and not just always require valid options? Brain won't train correctly without these set?
src/neural-network.js
Outdated
| callbackPeriod: (val) => { return typeof val === 'number' && val > 0; }, | ||
| timeout: (val) => { return typeof val === 'number' && val > 0 } | ||
| }; | ||
| Object.keys(options).forEach(key => { |
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.
Only reason I would go over all the validation keys rather than the passed in objects, was to ensure validity of all options?
b40f305 to
5c2d010
Compare
|
@perkyguy you waiting for anything else here? |
|
I think I'm good with all of this. Fix the merge conflicts though, and make sure you build prior to merging. |
Added in validation for training options and tests as well. Updates the readme Updates the readme again and uses a property for `validatesTrainOpts` instead of a getter/setter Updated the things I updated the `isStrict` property's name to be longer but more descriptive I reverted the timeout for async bitwise tests I moved the `validateTrainingOptions` method to be static Updated readme and got names a little better. Updates the things
Updates to iterate over the whole object each time.
Rebased against develop ran the make command double checked tests
e3c3fc9 to
23af33d
Compare
|
nice |
Added in validation for training options and tests as well.
Description
Creates validation for when the user sets the training options.
Motivation and Context
issue
This should help users who run into problems to see things they may have done wrong.
How Has This Been Tested?
I created a slew of tests that go over the expected supported functionality
Types of changes
Author's Checklist:
Reviewer's Checklist: