-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Broadcastable pattern error using Metropolis in large graph #1983
Comments
Seems to similar to #1304 |
Found a solution to this problem. instead of doing: v1 = pm.HalfNormal('v1', sd=1, shape=(ns, 1, nc))
s1 = pm.Deterministic('s1', tt.argsort(v1, axis=2)) create a variable and then reshape it resolved the problem v1 = pm.HalfNormal('v1', sd=1, shape=ns*nc)
s1 = tt.argsort(v1.reshape((ns, 1, nc)), axis=2) |
Glad it's working. I don't see why the above code shouldn't work. It could point to a subtle problem in |
Hi, with rbf_model:
alpha_model = pm.Normal('alpha', mu=init_alpha, sd=200, shape = numberOfBasis)
Cx_model = pm.Normal('Cx', mu=init_Cx, sd=20, shape = numberOfBasis)
Cy_model = pm.Normal('Cy', mu=init_Cy, sd=20, shape = numberOfBasis)
l_model = pm.Lognormal('l', mu = l, sd=20, shape = 1)
sigma_model = pm.HalfNormal('sigma', tau = np.ones(2), shape=(2,2), testval=init_sigma)
PHI_Re, PHI_Im = Vobs_function(U, l_model, alpha_model, Cx_model, Cy_model)
V_model = tt.stack([PHI_Re, PHI_Im], axis = 1)
V_obs = pm.MvNormal('V_obs', mu=V_model, cov=sigma_model, observed=V)
n_samples = 5000
step = pm.Metropolis()
trace = pm.sample(n_samples, step) In my case, my model I don't know where is the shape-error. Can you help me?
|
hmm, it is a bit difficult to say without the data and the parameters. But I dont think you should use |
Using I think that is a problem from the source specificly for the function |
I am the same problem here when trying to do some hierarchical stuff.
Mocked input have right dimensions:
Output:
The error traceback is the same as previous comments or at least the error reads analogously. The non hierarchical model works fine. Is it a problem generated by the indexing (which are actually used also in previous cases)? |
Same issue (crossposting on SO). It's not clear to me how the workaround for other models in this thread translates to my model implementation. If anyone can help with that, I'd greatly appreciate it! Model
Sample Data
Error and Stack Trace
|
I know this thread is older, but I just had the same issue and wanted to share what worked for me. Oddly, what fixed it was not flattening anything (tried that, didn't fix it). It turns out I had one variable that had |
@natalieklein Thanks for posting! That seemed to work for me as well. Changing my shapes from (N x 1) --> (N) seemed to fix the issue for me. |
Feel free to reopen if still an issue. |
It seems like broadcasting information gets lost when applying `pm.make_shared_replacements`, leading to problems with the metropolis sampler. Potentially related issues below: - #1083 - #1304 - #1983 This fix was previously suggested in the following issue: - #3337 It could be that further adaptations are necessary as indicated in the issue. Strangely, this does not seem to lead to problems when using NUTS.
It seems like broadcasting information gets lost when applying `pm.make_shared_replacements`, leading to problems with the metropolis sampler. Potentially related issues below: - pymc-devs#1083 - pymc-devs#1304 - pymc-devs#1983 This fix was previously suggested in the following issue: - pymc-devs#3337 It could be that further adaptations are necessary as indicated in the issue. Strangely, this does not seem to lead to problems when using NUTS.
I am reworking on my PyMC3 port of Lee and Wagenmakers' Bayesian Cognitive Modeling book, seems there is a bug running Metropolis sampler if the theano graph is large:
This model compiled without problem, and sample without problem in ADVI and NUTS, however, if I set
step=pm.Metropolis()
the following error returns:I am on the master branch of
pymc3
. The background of the model could be found in Chapter 18 of the book.The text was updated successfully, but these errors were encountered: