mattjj / pyhsmm-autoregressive

autoregressive plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error running demo.py

nonagonal opened this issue · comments

Hi,

I'm getting an assertion error in demo.py in _natural_to_standard() (callstack below). I used pip to install pyhsmm and then just cloned the pyhsmm-autoregressive repo locally. Any tips on how to get the demo working would be most appreciated!

/Users/jeremy/Documents/autoregressive/examples/demo.py in ()
66
67 for itr in progprint_xrange(100):
---> 68 model.resample_model()
69
70 model.plot()

/Library/Python/2.7/site-packages/pyhsmm/models.pyc in resample_model(self, num_procs)
428 @line_profiled
429 def resample_model(self,num_procs=0):
--> 430 self.resample_parameters()
431 self.resample_states(num_procs=num_procs)
432

/Users/jeremy/Documents/autoregressive/autoregressive/models.pyc in resample_parameters(self)
61
62 def resample_parameters(self):
---> 63 super(_ARMixin,self).resample_parameters()
64 # self.resample_init_emission_distn()
65

/Library/Python/2.7/site-packages/pyhsmm/models.pyc in resample_parameters(self)
433 @line_profiled
434 def resample_parameters(self):
--> 435 self.resample_obs_distns()
436 self.resample_trans_distn()
437 self.resample_init_state_distn()

/Library/Python/2.7/site-packages/pyhsmm/models.pyc in resample_obs_distns(self)
439 def resample_obs_distns(self):
440 for state, distn in enumerate(self.obs_distns):
--> 441 distn.resample([s.data[s.stateseq == state] for s in self.states_list])
442 self._clear_caches()
443

/Library/Python/2.7/site-packages/pybasicbayes/distributions/regression.pyc in resample(self, data, stats)
254 stats = self._get_statistics(data) if stats is None else stats
255 self.A, self.sigma = sample_mniw(
--> 256 *self._natural_to_standard(self.natural_hypparam + stats))
257 self._initialize_mean_field()
258

/Library/Python/2.7/site-packages/pybasicbayes/distributions/regression.pyc in _natural_to_standard(natparam)
94 K += 1e-8_np.eye(K.shape[0])
95 S += 1e-8_np.eye(S.shape[0])
---> 96 assert np.all(0 < np.linalg.eigvalsh(S))
97 assert np.all(0 < np.linalg.eigvalsh(K))
98

AssertionError:

/Library/Python/2.7/site-packages/pybasicbayes/distributions/regression.py(96)_natural_to_standard()
95 S += 1e-8*np.eye(S.shape[0])
---> 96 assert np.all(0 < np.linalg.eigvalsh(S))
97 assert np.all(0 < np.linalg.eigvalsh(K))

Hmm... that doesn't seem to be happening with my local copies. It could be that I broke a pypi version or something.

Can you try running the same thing with git master versions of pybasicbayes and pyhsmm? You could set those up by doing something like this:

git clone --recursive https://github.com/mattjj/pybasicbayes.git
cd pybasicbayes
pip install -e .
cd ..

git clone --recursive https://github.com/mattjj/pyhsmm.git
cd pyhsmm
pip install -e .

Then try running the autoregressive example again.

Another thing to check on the matrix that failed the assertion. If you know how to get into a debugger on the line that raised the exception, printing np.linalg.eigvalsh(S) may be informative. (If you run the file from within ipython, then you can jump into a post-mortem debugger by using the %debug magic command.)

I tried with git master versions of pybasicbayes and pyhsmm and get the same error, here's the S matrix on the failing line:
array([[ -1.42530989e+17, 1.73226519e+17],
[ 1.73226519e+17, -2.12271460e+17]])
and here are the eigenvalues:
array([ -3.54102555e+17, -6.99893794e+14])

I'm getting the same error.

What platform are you on?

I'm not able to reproduce the error so I can't really debug it. Maybe try updating all your libraries, including pybasicbayes and pyhsmm (using the instructions above, making sure that you're not loading an old version from site-packages or something). On the OS X computer on which I just tested demo.py, I'm on numpy 1.10.4 and scipy 0.17.0.

Ah! So the bug seems to occur due to old versions of numpy and scipy (numpy 1.8 and scipy 0.14). Updating to numpy 1.10.4 and scipy 0.17.0 seems to fix it. Thank you!

Sidenote: numpy 1.12 seems to break it in a different way. May or may not be a consequence of it still being in development.

Excellent! Thanks for figuring that out. I'll keep an eye out for numpy 1.12.