mattjj / pyslds

MIT License
88 stars 34 forks source link

HSMM-SLDS #25

Open vruetten opened 6 years ago

vruetten commented 6 years ago

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 commented 6 years ago

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

slinderman commented 6 years ago

Thanks Ziqiang. @mattjj, can you update pip with the latest pylds so that we don't have to install it from source? In the meantime, I'll remove the hips dependency.

On Mon, Feb 26, 2018 at 9:59 AM, Ziqiang Wei notifications@github.com wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mattjj/pyslds/issues/25#issuecomment-368530296, or mute the thread https://github.com/notifications/unsubscribe-auth/AFXwKPSPa59QY9BEHpT2kmC-bEWJzdilks5tYsbBgaJpZM4STKeX .

vruetten commented 6 years ago

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 commented 6 years ago

Ah, good point. The HSMM + SLDS is a relatively untested combination. I'll look into the generation code and see if I can debug it.

Best, Scott

On Mon, Feb 26, 2018 at 11:25 AM, vmsr2 notifications@github.com wrote:

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

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mattjj/pyslds/issues/25#issuecomment-368559830, or mute the thread https://github.com/notifications/unsubscribe-auth/AFXwKFp7i75YLqSAST7FxZwR_I9EV455ks5tYtsUgaJpZM4STKeX .

zqwei commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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