Should we keep storing draws from non-free parameters in the trace by default? #787
Replies: 5 comments 8 replies
-
I would argue we keep them by default but enable users to disable them (manually selecting the parameters to keep? or not to keep) |
Beta Was this translation helpful? Give feedback.
-
I've been doing some distributional models in brms lately, they don't return the additional parameter.
We're certainly not bound to what they do by any means but I just wanted to put that here as a data point from another library that has tackled this issue. Now onto my opinion as a personal user, when I write pymc models, most times I don't put observation-level deterministic in my models, so I will haphazardly chuck |
Beta Was this translation helpful? Give feedback.
-
I will chat with some PyMC folks to see how feasible it is to adapt pm.sample to not include deterministics. That way we would get a good graph plus avoid extra memory requirement |
Beta Was this translation helpful? Give feedback.
-
@ricardoV94 shared the other day a trick that we could exploit (don't know if we would be causing undesired problems). edit with this, we would have the best of all worlds
Look at this code import pymc as pm
# Simulate data
x = pm.draw(pm.Normal.dist(), 100)
y = 3 + 2 * pm.draw(pm.Normal.dist(sigma=2), 100)
# Create model, including the mean as a deterministic
with pm.Model() as model:
alpha = pm.Normal("alpha")
beta = pm.Normal("beta")
sigma = pm.HalfNormal("sigma")
mu = pm.Deterministic("mu", alpha + beta * x)
_ = pm.Normal("y", mu=mu, sigma=sigma, observed=y)
# Get the graph, showing "mu"
model.to_graphviz()
# The deterministics are stored in a list in the attribute `deterministics`.
# Store them for later
deterministics = model.deterministics
# Prints [mu]
print(deterministics)
# Set the model deterministics to an empty list
model.deterministics = []
# Sample
with model:
idata = pm.sample()
# Check the deterministics are not in the trace
print(idata.posterior.data_vars)
# Bring deterministics back to the model, so the graph includes them again
model.deterministics = deterministics
model.to_graphviz()
|
Beta Was this translation helpful? Give feedback.
-
PyMC 5.12 has been released and I think we can have the best of both worlds https://github.com/pymc-devs/pymc/releases/tag/v5.12.0 |
Beta Was this translation helpful? Give feedback.
-
See the following simple model and the output
The model has 3 free parameters.
Intercept
andx
determine the linear predictor for the mean mu, andy_sigma
is the standard deviation of the error term, a scalar.Now look at the following
The model has 4 free parameters:
Intercept
andx
for the linear predictor of the mean, andsigma_Intercept
andsigma_x
for the linear predictor of the standard deviation of the error term. However, here we are also storingsigma
, which is not a free parameter as its values are determined by the values fromsigma_Intercept
,sigma_x
, and the predictorx
.When I implemented distributional models, I decided to keep
sigma
in the trace by default. It seemed the natural choice, assigma
was already being included in the non-distributional approach.However, now I realize (thanks to @AlexanderFengler) this approach is both inconsistent and inefficient. What's more, we're not giving the user the option to disable it for computational issues.
Deterministic
in PyMC, which is also not the best.The only positive aspect I see of creating Deterministics (and I would consider it for both mu and sigma) is the nicer graph viz we would get.
If we don't keep these draws by default, we would still be able to compute them when it's needed.
6 votes ·
Beta Was this translation helpful? Give feedback.
All reactions