mattjj / pyslds

MIT License
90 stars 35 forks source link

Initialization error in simple_demo.py #23

Closed zqwei closed 6 years ago

zqwei commented 6 years ago

There is an error in the code, where the data is of shape (T-1) x m (m is the latent dimension) and x0 and Q0 should be add into the data.

Assertion error is reported at pylds/lds_messages_interface.py

The detailed report is as follow:

Initializing with Gibbs
Traceback (most recent call last):

File "pyslds/examples/simple_demo.py", line 85, in <module>
    gibbs_lls = [initialize(test_model) for _ in progprint_xrange(N_gibbs_samples)]

File "pyslds/examples/simple_demo.py", line 82, in initialize
    model.resample_model()

File "python2.7/site-packages/pyhsmm/models.py", line 442, in resample_model
    self.resample_states(num_procs=num_procs)

File "python2.7/site-packages/pyhsmm/models.py", line 467, in resample_states
    s.resample()

File "pyslds/pyslds/states.py", line 418, in resample
    self.resample_gaussian_states()

File "pyslds/pyslds/states.py", line 429, in resample_gaussian_states
    info_sample(*self.info_params)

File "python2.7/site-packages/pylds/lds_messages_interface.py", line 65, in wrapped
    return func(*check(*args,**kwargs))

File "python2.7/site-packages/pylds/lds_messages_interface.py", line 95, in _info_argcheck
    [J_pair_11, J_pair_21, J_pair_22, J_node])

File "python2.7/site-packages/pylds/lds_messages_interface.py", line 24, in _ensure_ndim
    assert X.shape[0] == T

AssertionError
slinderman commented 6 years ago

Can you please try installing pylds from source? I.e. git clone the repository then, from the cloned directory, run pip install -e .? I believe the version on pypi is a bit out of date.

zqwei commented 6 years ago

Yes I install pylds and pyhsmm-autoregressive from GitHub.

The new bug (zero division error) looks like this

Fitting with VBEM
................/lib/python2.7/site-packages/pyhsmm/internals/hmm_states.py:675: RuntimeWarning: divide by zero encountered in log
  np.log(trans_potential),likelihood_log_potential,alphal,betal,
pyslds/pyslds/states.py:594: RuntimeWarning: divide by zero encountered in log
  params = (np.log(self.trans_matrix), np.log(self.pi_0), aBl, self._normalizer)
Traceback (most recent call last):
  File "pyslds/examples/simple_demo.py", line 95, in <module>
    vbem_lls = [update(test_model) for _ in progprint_xrange(N_vbem_iters)]
  File "pyslds/examples/simple_demo.py", line 91, in update
    model.VBEM_step()
  File "pyslds/pyslds/models.py", line 217, in VBEM_step
    self._vb_E_step()
  File "pyslds/pyslds/models.py", line 170, in _vb_E_step
    state.vb_E_step()
  File "pyslds/pyslds/states.py", line 586, in vb_E_step
    H_z = self.vb_E_step_discrete_states()
  File "pyslds/pyslds/states.py", line 595, in vb_E_step_discrete_states
    return hmm_entropy(params, self.all_expected_stats)
  File "pyslds/pyslds/util.py", line 63, in hmm_entropy
    neg_entropy += np.sum(sum_E_ztztp1T * log_transmatrix)
FloatingPointError: invalid value encountered in multiply