mattjj / pyslds

MIT License
90 stars 34 forks source link

error on simple example #27

Open andrewcz opened 6 years ago

andrewcz commented 6 years ago

hey champion just getting some errors on the simple example

......................... [ 825/1000, 0.04sec avg, ETA 6.19 ] ......................... [ 850/1000, 0.04sec avg, ETA 5.31 ] ......................... [ 875/1000, 0.04sec avg, ETA 4.42 ] ......................... [ 900/1000, 0.04sec avg, ETA 3.54 ] ......................... [ 925/1000, 0.04sec avg, ETA 2.65 ] ......................... [ 950/1000, 0.04sec avg, ETA 1.77 ] ......................... [ 975/1000, 0.04sec avg, ETA 0.88 ] ......................... [ 1000/1000, 0.04sec avg, ETA 0.00 ]

0.04sec avg, 35.35 total

Fitting with VBEM ................/home/andrewcz/anaconda3/lib/python3.6/site-packages/pyhsmm/internals/hmm_states.py:675: RuntimeWarning: divide by zero encountered in log np.log(trans_potential),likelihood_log_potential,alphal,betal, /home/andrewcz/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 "simple_demo.py", line 95, in vbem_lls = [update(testmodel) for in progprint_xrange(N_vbem_iters)] File "simple_demo.py", line 95, in vbem_lls = [update(testmodel) for in progprint_xrange(N_vbem_iters)] File "simple_demo.py", line 91, in update model.VBEM_step() File "/home/andrewcz/pyslds/pyslds/models.py", line 217, in VBEM_step self._vb_E_step() File "/home/andrewcz/pyslds/pyslds/models.py", line 170, in _vb_E_step state.vb_E_step() File "/home/andrewcz/pyslds/pyslds/states.py", line 586, in vb_E_step H_z = self.vb_E_step_discrete_states() File "/home/andrewcz/pyslds/pyslds/states.py", line 595, in vb_E_step_discrete_states return hmm_entropy(params, self.all_expected_stats) File "/home/andrewcz/pyslds/pyslds/util.py", line 63, in hmm_entropy neg_entropy += np.sum(sum_E_ztztp1T * log_transmatrix) FloatingPointError: invalid value encountered in multiply

best andrew

kekehia123 commented 6 years ago

I got the same error. Hope someone can help!

veronica320 commented 6 years ago

I got another problem when running simle_demo.py:

Traceback (most recent call last): File "/Users/Veronica 1/slds_trial.py", line 94, in test_model._init_mf_from_gibbs() File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyslds/models.py", line 230, in _init_mf_from_gibbs s._init_mf_from_gibbs() File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyslds/states.py", line 458, in _init_mf_from_gibbs self.meanfield_update_gaussian_states() File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyslds/states.py", line 465, in meanfield_update_gaussian_states E_xtp1_xtT = info_E_step(*self.expected_info_params) File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyslds/states.py", line 393, in expected_info_params self.expected_info_dynamics_params + \ File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyslds/states.py", line 346, in expected_info_dynamics_params h_pair_2 = np.einsum('ti,tij->tj', self.inputs, E_BT_Qinv) File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy/core/einsumfunc.py", line 1087, in einsum einsum_call=True) File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy/core/einsumfunc.py", line 710, in einsum_path "not match previous terms.", char, tnum) ValueError: ("Size of label '%s' for operand %d does not match previous terms.", 'i', 1)

And when I try with an even simpler example myself, like this:

import numpy as np
import numpy.random as npr
from pyslds.models import DefaultSLDS

K = 5
D_obs = 10
D_latent = 2
T = 20
n_sample = 10

data = npr.randn(n_sample*T*D_obs).reshape(n_sample, T, D_obs)
test_model = DefaultSLDS(K, D_obs, D_latent)
for sample in data:
    test_model.add_data(sample)

print("Initializing with Gibbs")
N_gibbs_samples = 100
def initialize(model):
    model.resample_model()
    return model.log_likelihood()

gibbs_lls = [initialize(test_model) for _ in range(N_gibbs_samples)]

print("Fitting with VBEM")
N_vbem_iters = 100
def update(model):
    model.VBEM_step()
    return model.log_likelihood()

test_model._init_mf_from_gibbs()
vbem_lls = [update(test_model) for _ in range(N_vbem_iters)]

I got another error: Traceback (most recent call last): File "/Users/Veronica 1/slds_simple_demo.py", line 32, in vbem_lls = [update(testmodel) for in range(N_vbem_iters)] File "/Users/Veronica 1/slds_simple_demo.py", line 32, in vbem_lls = [update(testmodel) for in range(N_vbem_iters)] File "/Users/Veronica 1/slds_simple_demo.py", line 28, in update model.VBEM_step() AttributeError: 'HMMSLDS' object has no attribute 'VBEM_step'

Could you kindly give some help with this? Thanks a lot!

Corleno commented 3 years ago

As for the error "FloatingPointError: invalid value encountered in multiply", it is because some log transition is -inf. So you only need to add "log_transmatrix[np.isinf(log_transmatrix)] = -1e+8" and it then works.