mattjj / pyhsmm

MIT License
545 stars 172 forks source link

On Forecasting #91

Open tiddlerhxy opened 5 years ago

tiddlerhxy commented 5 years ago

Hello! I have a question about prediction.Error while running code, i don't know what happened. The code is as follows:


import pyhsmm
import random

Nmax = 25

obs_hypparams = {'mu_0':np.zeros(2),
                'sigma_0':np.eye(2),
                'kappa_0':0.25,
                'nu_0':4}

dur_hypparams = {'alpha_0':1,
                 'beta_0':1}

obs_distns = [pyhsmm.distributions.Gaussian(**obs_hypparams) for state in range(Nmax)]
dur_distns = [pyhsmm.distributions.PoissonDuration(**dur_hypparams) for state in range(Nmax)]

sample_data = np.array([random.randint(0,10) for i in range(20)])
print("sample_data:",sample_data)

posteriormodel = pyhsmm.models.WeakLimitHDPHSMM(
    alpha=6, gamma=6,
    init_state_concentration=6,
    obs_distns=obs_distns,
    dur_distns=dur_distns)

posteriormodel.add_data(sample_data)
prediction, hidden_states = posteriormodel.predict(np.array([]),timesteps=10)
print("prediction:",prediction)
``

the wrong report:
Traceback (most recent call last):
  File "/root/root/eyes/appone/tt1.py", line 28, in <module>
    prediction, hidden_states = posteriormodel.predict(np.array([]),timesteps=10)
  File "/usr/local/python3.6.6/lib/python3.6/site-packages/pyhsmm/models.py", line 120, in predict
    s.resample()  # fills in states
  File "/usr/local/python3.6.6/lib/python3.6/site-packages/pyhsmm/internals/hsmm_states.py", line 325, in resample
    betal, betastarl = self.messages_backwards()
  File "/usr/local/python3.6.6/lib/python3.6/site-packages/pyhsmm/internals/hsmm_states.py", line 505, in messages_backwards
    np.maximum(self.trans_matrix,1e-50),self.aBl,np.maximum(self.aDl,-1000000),
  File "/usr/local/python3.6.6/lib/python3.6/site-packages/pyhsmm/internals/hmm_states.py", line 103, in aBl
    aBl[:,idx] = obs_distn.log_likelihood(data).ravel()
  File "/usr/local/python3.6.6/lib/python3.6/site-packages/pybasicbayes/distributions/gaussian.py", line 74, in log_likelihood
    out[bads] = 0
IndexError: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 1