-
-
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
Unexpected behavior with pm.sample(var_names=...)
#7258
Comments
Nope. I guess we didn't incorporate it well. CC @fonnesbeck |
@ricardoV94 @fonnesbeck I had a look at the code but I'm not very familiar with the trace and sampler internals. Do you have any pointer on what needs to be modified? I could give it a shot |
I've been trying to better understand what's happening here and I reached the initiliaziation method of the Lines 145 to 158 in 60a6314
So I imagined something was happening with the compiled function. I manually re-created the compiled function with var_names = ["b_batch", "b_temp", "kappa"]
vars_trace = [v for v in model.unobserved_RVs if v.name in var_names]
point_func = model.compile_fn(vars_trace, inputs=model.value_vars, on_unused_input="ignore")
point_func({"b_batch": np.array([0] * 10), "b_temp": 0, "kappa_log__":0})
If I don't use
which I think it indicates the problem. Also, notice every time you ran the previous chunk it'll return different values. On the other hand, if we reproduce what vars_trace = model.unobserved_value_vars
var_names = [var.name for var in vars_trace] # ['b_batch', 'b_temp', 'kappa_log__', 'kappa', 'mu']
point_func = model.compile_fn(vars_trace, inputs=model.value_vars)
point_func({"b_batch": np.array([0] * 10), "b_temp": 0, "kappa_log__":0})
To summarize, I'm thinking not including variables in the trace is a bit more complicated than expected? I'm not sure what is the next step is. To me it looks like we need to pass all the necessary outputs to |
My hunch is that with var_names it's trying to create a function of the RVs (which explains why it's random and why it does not depend on the model.value_vars), but we want one of the respective value variables. We basically want to use |
If you check what We want to do the same when |
Reopening as a robust test is still missing |
Would a comparison of draws between two posteriors one with and without var_names be enough? Or do you have something more elaborate in mind? |
That's what I had in mind. |
Description
PyMC 5.13 incorporates the
var_names
parameter inpm.sample()
. The documentation saysvar_names: Names of variables to be stored in the trace. Defaults to all free variables and deterministics
.This comes very handy for something I've been trying to do in Bambi. Now I'm porting Bambi to use this feature and noticed weird results with tests. I reproduced one of the models with PyMC and noticed the problem. Have a look at this
I want to sample the posterior, but I don't want to store the draws of
"mu"
by default. So I usevar_names=["b_batch", "b_temp", "kappa"]
(and I also sample withoutvar_names
to see the difference).When I don't use
var_names
I get the following posteriorand when I use
var_names
it's the followingwhich makes me think it's basically omitting the likelihood and thus sampling from the prior.
Is this behavior expected?
The text was updated successfully, but these errors were encountered: