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

IndexError using ordered transform #3680

Closed
sammosummo opened this issue Nov 14, 2019 · 5 comments
Closed

IndexError using ordered transform #3680

sammosummo opened this issue Nov 14, 2019 · 5 comments

Comments

@sammosummo
Copy link

import pymc3 as pm

with pm.Model():
    x = pm.Uniform('x', 0., 1., shape=2, transform=pm.distributions.transforms.ordered)
    pm.sample()
Traceback (most recent call last):
  File "C:/Users/sm2286/PycharmProjects/ForgettingPitch/_testordered.py", line 4, in <module>
    x = pm.Uniform('x', 0., 1., shape=2, transform=pm.distributions.transforms.ordered)
  File "C:\Users\sm2286\Anaconda3\envs\PerceptualAnchors\lib\site-packages\pymc3\distributions\distribution.py", line 46, in __new__
    return model.Var(name, dist, data, total_size)
  File "C:\Users\sm2286\Anaconda3\envs\PerceptualAnchors\lib\site-packages\pymc3\model.py", line 833, in Var
    model=self)
  File "C:\Users\sm2286\Anaconda3\envs\PerceptualAnchors\lib\site-packages\pymc3\model.py", line 1557, in __init__
    transformed_name, transform.apply(distribution), total_size=total_size)
  File "C:\Users\sm2286\Anaconda3\envs\PerceptualAnchors\lib\site-packages\pymc3\distributions\transforms.py", line 95, in apply
    return TransformedDistribution.dist(dist, self)
  File "C:\Users\sm2286\Anaconda3\envs\PerceptualAnchors\lib\site-packages\pymc3\distributions\distribution.py", line 56, in dist
    dist.__init__(*args, **kwargs)
  File "C:\Users\sm2286\Anaconda3\envs\PerceptualAnchors\lib\site-packages\pymc3\distributions\transforms.py", line 120, in __init__
    testval = forward(dist.default())
  File "C:\Users\sm2286\Anaconda3\envs\PerceptualAnchors\lib\site-packages\pymc3\distributions\transforms.py", line 334, in forward
    y = tt.inc_subtensor(y[..., 0], x[..., 0])
  File "C:\Users\sm2286\Anaconda3\envs\PerceptualAnchors\lib\site-packages\theano\tensor\var.py", line 510, in __getitem__
    raise IndexError('too many indices for array')
IndexError: too many indices for array
@junpenglao
Copy link
Member

Did you try specifying the test_val? I think this is still required currently.

@junpenglao
Copy link
Member

Yep, you need to do:

import pymc3 as pm

with pm.Model():
    x = pm.Uniform('x', 0., 1., shape=2, transform=pm.distributions.transforms.ordered, testval=np.asarray([.5, .9]))
    pm.sample(init='adapt_diag')

You probably should use a Chain transformation to make it sample better, see eg: cell [22] in https://docs.pymc.io/notebooks/api_quickstart.html

@sammosummo
Copy link
Author

sammosummo commented Dec 5, 2019

Can you explain what you mean by Chain transformation and why this improves sampling?

@rpgoldman
Copy link
Contributor

The transformations are now documented at https://docs.pymc.io/api/distributions/transforms.html

Please let us know if this material is not clear -- I did the extraction of docstrings from code, but I'm not responsible for any of the code itself. So it would be good to know if these leave unanswered questions, so we can fix them.

@eigenfoo
Copy link
Member

eigenfoo commented Dec 5, 2019

@sammosummo you can check out this "release blog post" by Colin: https://colindcarroll.com/2018/07/20/why-im-excited-about-pymc3-v3.5.0/

Specifically, the section 5 on the ordered transform. Hope this helps!

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

4 participants