Skip to content
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

handle min = max case during data normalization #208

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

ziyuan-linn
Copy link
Member

This PR addresses issue #204 by adding a check for min === max in normalizeValue, preventing the divide by zero situation.

Copy link
Member

@shiffman shiffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a small question to think about before merging!

@@ -11,6 +11,10 @@ class NeuralNetworkUtils {
*/
// eslint-disable-next-line class-methods-use-this
normalizeValue(value, min, max) {
// When min is equal to max, set everything to 0
if (min === max) {
return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just thinking about this a bit, should we log some sort of warning in the console? Perhaps we should also just return min (or max) to keep the original values? And log that they cannot be normalized?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a warning would be helpful! I am not sure how to word it though. Perhaps "The input parameter cannot be normalized because all values for that parameter are identical. The NeuralNetwork can still be trained, but please check your input data".

If we keep the original (non-zero) data, that parameter effectively becomes a bias value for the next layer since it is constant. If we zero that parameter we are pretty much deleting it from the neural network. I'm not sure whether keeping it could throw off the training, but I'm leaning toward just zeroing the parameter since it doesn't contribute to training anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you mean! How about:

console.warn("Normalization failed: All values for this feature are identical (min === max). The data for this feature will be set to 0, effectively removing it from the model. Please check your input data.");

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I will work on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! let me know when it is ready to merge! Maybe we can do a release after this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge!

@shiffman
Copy link
Member

shiffman commented Oct 3, 2024

Yay, great work @ziyuan-linn!

@shiffman shiffman merged commit 8241125 into main Oct 3, 2024
@ziyuan-linn ziyuan-linn deleted the normalizeData-handle-zeros branch October 11, 2024 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

normalizeData() does not handle only zeros in one of the inputs to the neural net
2 participants