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

[BUG] HMM edges matrix initialization contains NaNs #1078

Open
asn32 opened this issue Jan 24, 2024 · 0 comments
Open

[BUG] HMM edges matrix initialization contains NaNs #1078

asn32 opened this issue Jan 24, 2024 · 0 comments

Comments

@asn32
Copy link

asn32 commented Jan 24, 2024

Describe the bug
Hi, I have been testing out the DenseHMM implementation in Pomegranate v1.0.3 for models with > 50 states, and have occasionally encountered a bug where initializing the model.edges matrix using the model.add_edge results in an edges matrix containing NaNs. The NaNs then propagate through downstream calculations including model.forward_backward and model.predict.

I tracked this down to the following snippet located here:

	if self.edges is None:
		self.edges = torch.empty((n, n), dtype=self.dtype, 
			device=self.device) - inf

where torch.empty sometimes returns an array with NaNs, and NaN - float("inf") = NaN. I think additionally, because in my testing I don't set every entry of the edges matrix manually to a specific probability, subsequent usage of model.edges propagates those NaNs.

To Reproduce
Since the bug (I think) comes from the initialization of a large array using torch.empty, the simplest way I have been able to reproduce it is using the above snippet where n is large (> 50), and then not fill in every edge.

The quickest fix I have found is to just pre-set the matrix with torch.log(torch.zeroes((n,n)).

I'm a big fan of the package, and thank you for all the effort you've put in developing it. Just wanted to put this on your radar.

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

1 participant