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

LinAlg error when sampling from trained hmm #130

Open
vcorbit opened this issue Apr 21, 2021 · 0 comments
Open

LinAlg error when sampling from trained hmm #130

vcorbit opened this issue Apr 21, 2021 · 0 comments

Comments

@vcorbit
Copy link

vcorbit commented Apr 21, 2021

Hi,

I have an HMM that I trained and tested on some joint data. I'm trying now to sample from the HMM to simulate data and test some further analyses. However, every time I run hmm.sample(timebins) with my model, I get this error:

originalstates, sampledobs = trainedhmm.sample(timebins)
t:\updatedssm\ssm\ssm\observations.py:491: RuntimeWarning: divide by zero encountered in true_divide
sqrt_Sigma = np.linalg.cholesky(Sigmas[z] / tau) if with_noise else 0
Traceback (most recent call last):

File "", line 1, in
originalstates, sampledobs = trainedhmm.sample(timebins)

File "t:\updatedssm\ssm\ssm\hmm.py", line 221, in sample
data[0] = self.observations.sample_x(z[0], data[:0], input=input[0], with_noise=with_noise)

File "t:\updatedssm\ssm\ssm\observations.py", line 491, in sample_x
sqrt_Sigma = np.linalg.cholesky(Sigmas[z] / tau) if with_noise else 0

File "C:\ProgramData\Anaconda3\lib\site-packages\autograd\tracer.py", line 48, in f_wrapped
return f_raw(*args, **kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\linalg\linalg.py", line 759, in cholesky
r = gufunc(a, signature=signature, extobj=extobj)

File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\linalg\linalg.py", line 100, in _raise_linalgerror_nonposdef
raise LinAlgError("Matrix is not positive definite")

LinAlgError: Matrix is not positive definite

When I create a new HMM from scratch using the same K and D values, I don't get this error. So it seems like something is going wrong with my trained HMM but I'm not sure what it could be, since the trained HMM works fine for other functions like getting the LL or predicting states on new observations. Not sure if this is a bug or something I'm doing wrong on my end.

Any advice you could give would be greatly appreciated!!

Thanks!

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