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

Ordered transform doesn't work without testval #4722

Closed
impact27 opened this issue May 26, 2021 · 2 comments
Closed

Ordered transform doesn't work without testval #4722

impact27 opened this issue May 26, 2021 · 2 comments

Comments

@impact27
Copy link

impact27 commented May 26, 2021

If you have questions about a specific use case, or you are not sure whether this is a bug or not, please post it to our discourse channel: https://discourse.pymc.io

Description of your problem

Please provide a minimal, self-contained, and reproducible example.

import pymc3 as pm
import theano.tensor as tt
import pymc3.distributions.transforms as tr
from theano.graph.op import Op
import theano
import numpy as np

tr_order = tr.Ordered()
tr_bounds = tr.interval(0, 0.5)

with pm.Model() as model:
    DRi = pm.Uniform("DRi", lower=0, upper=0.5, shape=2,
                      transform=tr.Chain([tr_bounds, tr_order]),
                       # testval=[0.1, 0.4]
                     )
    pm.Normal("A",
              mu=tt.sum(DRi),
              sigma=1,
              observed=np.random.uniform(0, 0.5, size=10))
    trace = pm.sample(return_inferencedata=True, cores=1)

Please provide the full traceback.

Traceback (most recent call last):

  File "C:\Users\quentin.peter\Desktop\aSyn_Kd_sizing\untitled0.py", line 19, in <module>
    DRi = pm.Uniform("DRi", lower=0, upper=0.5, shape=2,

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymc3\distributions\distribution.py", line 122, in __new__
    return model.Var(name, dist, data, total_size, dims=dims)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymc3\model.py", line 1142, in Var
    var = TransformedRV(

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymc3\model.py", line 2013, in __init__
    transformed_name, transform.apply(distribution), total_size=total_size

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymc3\distributions\transforms.py", line 126, in apply
    return TransformedDistribution.dist(dist, self)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymc3\distributions\distribution.py", line 130, in dist
    dist.__init__(*args, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymc3\distributions\transforms.py", line 150, in __init__
    testval = forward(dist.default())

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymc3\distributions\transforms.py", line 536, in forward
    y = transf.forward(y)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pymc3\distributions\transforms.py", line 385, in forward
    y = tt.inc_subtensor(y[..., 0], x[..., 0])

  File "C:\ProgramData\Anaconda3\lib\site-packages\theano\tensor\var.py", line 493, in __getitem__
    raise IndexError("too many indices for array")

IndexError: too many indices for array

Please provide any additional information below.
This works if I give testval=[0.1, 0.4]

Versions and main components

PyMC3 Version: 3.11.2
Aesara Version: NA
Python Version: 3.8.5
Operating system: windows
How did you install PyMC3: (conda/pip) pip
@OriolAbril
Copy link
Member

We need the versions of the packages you are using to be able to help

@ricardoV94
Copy link
Member

ricardoV94 commented May 26, 2021

This is a known limitation of the ordered transform: #3680

You have to manually specify a testval. In the future we will probably implement a pm.Sort that takes care of this sort of low level details for the user, see #4530

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

3 participants