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

gmm.gmm covariance_bound: Buffer has wrong number of dimensions #37

Open
rgmyr opened this issue Jul 18, 2018 · 0 comments
Open

gmm.gmm covariance_bound: Buffer has wrong number of dimensions #37

rgmyr opened this issue Jul 18, 2018 · 0 comments

Comments

@rgmyr
Copy link

rgmyr commented Jul 18, 2018

I get a buffer error when trying to pass a scalar covariance_bound to gmm.gmm. The issue can be demonstrated with a short example:

n_samples, n_features = 100, 12
x = np.random.rand(n_samples, n_features)
cb = x.var()*0.01
m, c, prior, ll, post = cyvlfeat.gmm.gmm(x, covariance_bound=cb)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-23-570fcaba71f2> in <module>()
      2 x = np.random.rand(n_samples, n_features)
      3 cb = x.var()*0.0001
----> 4 m, c, prior, ll, post = gmm.gmm(x, covariance_bound=cb)

~/anaconda3/envs/core-dev/lib/python3.6/site-packages/cyvlfeat/gmm/gmm.py in gmm(X, n_clusters, max_num_iterations, covariance_bound, init_mode, init_priors, init_means, init_covars, n_repetitions, verbose)
    114                   n_repetitions, int(verbose),
    115                   covariance_bound=covariance_bound, init_priors=init_priors,
--> 116                   init_means=init_means, init_covars=init_covars)

~/anaconda3/envs/core-dev/lib/python3.6/site-packages/cyvlfeat/gmm/cygmm.pyx in cyvlfeat.gmm.cygmm.cy_gmm (cyvlfeat/gmm/cygmm.c:4852)()

ValueError: Buffer has wrong number of dimensions (expected 1, got 0)

When I change the argument to a 1D array, it seems to work, at least for this toy example:

m, c, prior, ll, post = gmm.gmm(x, covariance_bound=np.array([cb]))

The difference here is between having ndim=0 and ndim=1:

>>> np.asarray(cb, dtype=np.float).ndim, np.asarray(np.array([cb]), dtype=np.float).ndim
(0, 1)

Previously, in my actual (much larger) use case, I was then getting a Buffer error that complained about getting a double instead of a float32_t, even when explicitly casting to np.float or np.float32. If I can reproduce that issue I will post a follow up.

In any case, thanks to the contributors for these wrappers, I've been finding them very useful!

@rgmyr rgmyr changed the title gmm.gmm ValueError: Buffer has wrong number of dimensions gmm.gmm covariance_bound: Buffer has wrong number of dimensions Jul 18, 2018
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

1 participant