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

Chronocell PBMC Trajectory Inference Step - Nan Value Normalization Error #10

Closed
emix-c opened this issue Feb 4, 2025 · 3 comments
Closed

Comments

@emix-c
Copy link

emix-c commented Feb 4, 2025

Hi,
I'm heavily interested in trajectory inference and I was very interested in learning more about Chronocell after reading the preprint.
I am currently trying to run the PBMC notebook to understand the steps better.
But, I'm running into an issue with the trajectory portion.
Specifically, I am seeing an error with the normalization function in the fit method where it is saying that 'new_Q contains NaN value'.
I've attached a screenshot of the code block where this occurs:

Image

I've been following the notebook step by step to try to reproduce it and all the previous steps have been working well with no issues, so it's curious that normalization isn't working as planned.

I was wondering if there was any insight you could provide, thank you!

@meichenfang
Copy link
Collaborator

meichenfang commented Feb 6, 2025

Thank you so much for your interest in Chronocell!

Regarding the error message about new_Q containing NaN values, I wasn’t sure whether the NaNs were already present in the input Q or if they were introduced within the normalize_Q function. I reran the notebook, but somehow the error didn’t appear, though I suspect my environment might be outdated. So I added

assert not np.any(np.isnan(Q)), "Q contains NaN values"
assert not np.any(np.isinf(Q)), "Q contains Inf values"

at the end of the normalized_Q function. You can either pull the changes (commit check Q in update_Q) or add it directly. Could you try it again to see whether NaNs were already in Q in order to narrow down which function produces the NaNs?

@emix-c
Copy link
Author

emix-c commented Feb 6, 2025

Hi, thank you so much for your response!
I was able to narrow it down and it looks like it's caused by the normalize_Q function.
Specifically, caused by this line:
new_Q /= new_Q.sum(axis=(-2,-1),keepdims=True)

where I see this error:
RuntimeWarning: invalid value encountered in divide new_Q /= new_Q.sum(axis=(-2,-1),keepdims=True)

From my assertion I get this:
AssertionError: new_Q contains NaN values, seed = 78, after 2nd norm

I actually noticed that this error only comes up with a few seeds in particular, and most of the seeds work just fine.

To get around this, I temporarily added a small epsilon value to the sum as I was suspecting this was due to a division by zero, and it works fine now. Would this be an appropriate workaround in your opinion?

epsilon = 1e-8  
new_Q /= (new_Q.sum(axis=(-2,-1), keepdims=True) + epsilon)

@meichenfang
Copy link
Collaborator

That's cool! Glad to hear it’s working well for you!

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

No branches or pull requests

2 participants