Skip to content

Handle NaN values in Y normalization#110

Open
micchu wants to merge 1 commit into
mainfrom
fix_y_normlization
Open

Handle NaN values in Y normalization#110
micchu wants to merge 1 commit into
mainfrom
fix_y_normlization

Conversation

@micchu

@micchu micchu commented Oct 24, 2025

Copy link
Copy Markdown
Member

Since the results of Y normalization can contain not only np.inf but also np.nan, I added a process to replace them with 0.

Numpy operations have the following properties:

  • 1/0 results in np.inf (dividing a non-zero value by 0)
  • 0/0 results in np.nan (dividing 0 by 0)

Since this occurs immediately after Y - y_mean, the procedure should essentially be 0/0. However, a very small error in float32 results in an operation like 3.2e-25/0 instead of 0/0, resulting np.inf in most cases. This makes this problem difficult to notice.
In very rare cases, 0/0 occurs, resulting in np.nan feature values. In such cases, the weights W contain np.nan values. This causes np.nan values ​​to appear in the predicted values, causing problems when using the predicted values ​​for reconstruction, etc.

Since the results of Y normalization can contain not only `inf` but also `nan`, I added a process to replace them with 0.

@KenyaOtsuka KenyaOtsuka left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I do not think this should be accepted as-is.

The proposed change treats every NaN after Y normalization as if it came from 0/0, but that is not necessarily true. NaN may also indicate invalid input data or invalid normalization parameters. In those cases, silently replacing them with 0 may hide invalid input data or normalization parameters.

A safer fix would be to handle only the y_norm == 0 case explicitly, and then check that the normalized Y contains no remaining non-finite values.

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.

3 participants