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

HSMM-SLDS #25

Open
vruetten opened this issue Feb 26, 2018 · 7 comments
Open

HSMM-SLDS #25

vruetten opened this issue Feb 26, 2018 · 7 comments

Comments

@vruetten
Copy link

Hi Matt and Scott,

Thanks for the awesome toolbox.

I’ve been having some trouble when trying to link a HSMM and an SLDS.
A “NotImplementedError” error gets raised when I try to generate from the model. (The HMMSLDS version works fine.) I'm not sure if I'm doing something wrong.

For instance if I try to generate from a HSMMSLDS, I get the following error.
Thanks for letting me know what I should do (and again for making your code open-source)

import pyslds.models as mm  
import numpy as np
from pyhsmm.basic import distributions
D_latent = 2                  
D_obs = 2                        
D_input = 0        
K = 2

mu_init = np.zeros(D_latent)
mu_init[0] = 1.0
sigma_init = 0.01 * np.eye(D_latent)

alpha_0,beta_0 = 20.0, 2.0
betas = [(alpha_0,beta_0) for state in range(K)]
As = [np.eye(D_latent) for state in range(K)]
Cs = [np.random.randn(D_obs, D_latent) for state in range(K)]
init_dynamics_distns = [distributions.Gaussian(mu=mu_init, sigma=sigma_init) for _ in range(K)]
dynamics_distns = [distributions.Regression(A=A, sigma=0.01*np.eye(D_latent)) for A in As]
emission_distns = [distributions.Regression(A=C, sigma=0.01*np.eye(D_latent)) for C in Cs]
dur_distns=[distributions.PoissonDuration(alpha_0=alpha,beta_0=beta)
                       for (alpha, beta) in betas]
    
model=mm.HSMMSLDS(
       init_dynamics_distns=init_dynamics_distns,
       dynamics_distns=dynamics_distns,
       emission_distns=emission_distns,
       dur_distns=dur_distns,
       init_state_distn='uniform',
       alpha=3.0)

model.generate(1)
-----------------------------------
AttributeErrorTraceback (most recent call last)
<ipython-input-6-1ab324cecf4b> in <module>()
     29         alpha=3.0)
     30 
---> 31 model.generate(1)

~/anaconda/lib/python3.5/site-packages/pyslds/models.py in generate(self, T, keep, **kwargs)
     37 
     38     def generate(self, T=100, keep=True, **kwargs):
---> 39         s = self._states_class(model=self, T=T, initialize_from_prior=True, **kwargs)
     40         s.generate_states()
     41         data = self._generate_obs(s)

~/anaconda/lib/python3.5/site-packages/pyslds/states.py in __init__(self, model, data, mask, fixed_stateseq, **kwargs)
    754         super(_SLDSStatesCountData, self). \
    755             __init__(model, data=data, mask=mask,
--> 756                      fixed_stateseq=fixed_stateseq, **kwargs)
    757 
    758         # Check if the emission matrix is a count regression

~/anaconda/lib/python3.5/site-packages/pyslds/states.py in __init__(self, model, T, data, inputs, mask, stateseq, gaussian_states, generate, initialize_from_prior, fixed_stateseq)
    553                                                     generate=generate,
    554                                                     initialize_from_prior=initialize_from_prior,
--> 555                                                     fixed_stateseq=fixed_stateseq)
    556 
    557     @property

~/anaconda/lib/python3.5/site-packages/pyslds/states.py in __init__(self, model, T, data, inputs, stateseq, gaussian_states, generate, initialize_from_prior, fixed_stateseq)
     47                 self.resample()
     48             else:
---> 49                 self.generate_states()
     50 
     51     def generate_states(self):

~/anaconda/lib/python3.5/site-packages/pyslds/states.py in generate_states(self)
     50 
     51     def generate_states(self):
---> 52         super(_SLDSStates,self).generate_states()
     53         self.generate_gaussian_states()
     54 

~/anaconda/lib/python3.5/site-packages/pyhsmm/internals/hsmm_states.py in generate_states(self)
    113     # potentials?
    114     def generate_states(self):
--> 115         if self.left_censoring:
    116             raise NotImplementedError
    117         idx = 0

AttributeError: 'HSMMSLDSStatesEigen' object has no attribute 'left_censoring'
@zqwei
Copy link

zqwei commented Feb 26, 2018

@vrutten I added some details for installation. Hope it helps. https://github.com/zqwei/pyslds

@slinderman
Copy link
Collaborator

slinderman commented Feb 26, 2018 via email

@vruetten
Copy link
Author

vruetten commented Feb 26, 2018

Hi Ziqiang(!)
Funny to find you through this interface.

I'm not quite sure why you reference "details for installation.".
Installation/models work fine. I just seem to have issues with the HSMMSLSD one.
Thanks for any clarifications.

@slinderman
Copy link
Collaborator

slinderman commented Feb 26, 2018 via email

@zqwei
Copy link

zqwei commented Feb 26, 2018

@vrutten Hi, Virginia, as Scott mentioned, some of the code uses updated libs and I wrote a summary which should be pip-installed with independent effort to make the code runnable (if you did not realize that).

@vruetten
Copy link
Author

Hi again,

Would you have a maths write up of the derivations associated with the various models?
It would make following the code quite a bit easier. (Or point me to a paper which has them explicitly.)

Thanks!

@vruetten
Copy link
Author

vruetten commented Feb 28, 2018

Hi again :)
Double checking (in order not to duplicate work)
Gibbs sampling works fine, VBEM works for the DefaultSLDS model, but not for all the other models (e.g.: HSMMSLDS).
I get errors when trying to run inference using the Viterbi approximation on the DefaultSLDS. Could you tell me if the code is supposed to be working (i.e.: there's a simple implementation issue on my half) or if that part of the code is still to be debugged?

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

3 participants