Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiments all fail due to sample_mean_prec() mean calculation #1

Open
danstowell opened this issue Aug 17, 2016 · 2 comments
Open

Comments

@danstowell
Copy link

Hi. I read the paper, I wanted to try the code!

I'm using python 2.7. If I run any of the experiments (i.e. cd experiments; python experiment_1.py) I get something like this:

../transition.py:25: RuntimeWarning: divide by zero encountered in log
  return np.log(self.A[i,j])
../log_space.py:7: RuntimeWarning: underflow encountered in exp
  return lny + log(1 + exp(lnx - lny))
Traceback (most recent call last):
  File "experiment_1.py", line 70, in 
    online=True, sample_U = True
  File "../edhmm.py", line 537, in beam
    self.O.update(Z_samples, Y)
  File "../emission.py", line 140, in update
    mu, tau = self.sample_mean_prec(Z, Y)
  File "../emission.py", line 59, in sample_mean_prec
    ybar = np.mean(n[i],1)
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 2885, in mean
    out=out, keepdims=keepdims)
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/_methods.py", line 56, in _mean
    rcount = _count_reduce_items(arr, axis)
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/_methods.py", line 50, in _count_reduce_items
    items *= arr.shape[ax]
IndexError: tuple index out of range
zsh: exit 1     python experiment_1.py

I notice that the line that chokes is protected by an except ValueError. Maybe this should, or should also, guard against IndexError, but I don't know the code so I don't know the intention.

(In case it matters, on my system I also had to mildly rearrange the order of imports)

@mikedewar
Copy link
Owner

It's been many years since we wrote this, so I'm not really sure there remains any specific intention! I guess I'd worry first about why ybar = np.mean(n[i],1) is puking an index error. If you have a moment, can you see how big n is and what i is causing the problem? No worries if not, I'll try to get around to having a play at some point!

@danstowell
Copy link
Author

Yeah I realise the code is a little old, but I'm rather hoping it can still be useful!

It turns out that n is a dict with keys 0, 1, 2 and each one holds a numpy array whose shapes are:

 0: (99,)
 1: (105,)
 2: (296,)

Each of the Y passed in via Ys is a list containing scalar-valued arrays, such as [array(-2.8626048450849297), array(-2.043008544196465), array(-3.752285935165192), .... When converted using np.array(.).T it makes a flat 1D array - the programmer was clearly expecting to end up with 2D arrays. I wondered about changing the conversion to np.array(., ndmin=2).T - but then there's an np.squeeze() immediately after, deliberately dropping size-1 axes. It gives me the feeling that something is happening such as the code expects vector-valued observations and is being given scalar-valued ones?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants