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] Improvement: nan while training DenseHMM #1119

Open
MBradbury opened this issue Oct 24, 2024 · 0 comments
Open

[BUG] Improvement: nan while training DenseHMM #1119

MBradbury opened this issue Oct 24, 2024 · 0 comments

Comments

@MBradbury
Copy link

Describe the bug
I am attempting to train a DenseHMM (code below) with 1000 sequences of length 61 observations that have a single categorical emission. But the training does not succeed. I presume that I am using the APIs incorrectly, so some direction would be appreciated.

Based on the documentation I believe I should be providing Categorical(n_categories=[n_categories]) but Categorical._initialize requires n_categories to be an int, hence Categorical(n_categories=n_categories).

Output from the script:

torch.Size([1000, 61, 1])
[1] Improvement: nan, Time: 0.6118s
[2] Improvement: nan, Time: 0.6179s
[3] Improvement: nan, Time: 0.614s
[4] Improvement: nan, Time: 0.6247s
[5] Improvement: nan, Time: 0.621s
[6] Improvement: nan, Time: 0.6254s
[7] Improvement: nan, Time: 0.612s
[8] Improvement: nan, Time: 0.6098s
[9] Improvement: nan, Time: 0.6171s
[10] Improvement: nan, Time: 1.235s
tensor([[0, 0, 0,  ..., 0, 0, 0],
        [0, 0, 0,  ..., 0, 0, 0],
        [0, 0, 0,  ..., 0, 0, 0],
        ...,
        [0, 0, 0,  ..., 0, 0, 0],
        [0, 0, 0,  ..., 0, 0, 0],
        [0, 0, 0,  ..., 0, 0, 0]])

Version information

$ python
Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pomegranate
>>> pomegranate.__version__
'1.1.1'

To Reproduce

from pomegranate.hmm import DenseHMM
from pomegranate.distributions import Categorical

import torch

n_hidden_states = 123
n_categories = 61

distributions = [
    Categorical(n_categories=n_categories)
    for _ in range(n_hidden_states)
]

model = DenseHMM(
    distributions,
    max_iter=10,
    verbose=True
)

xs = torch.randint(low=0, high=n_categories, size=(1000, 61, 1))

print(xs)
print(xs.shape)

assert xs.shape[0] == 1000 # xs.shape[0] is the number of sequences
assert xs.shape[1] == n_categories
assert xs.shape[2] == 1

model.fit(xs)

print(model.predict(xs))
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