Skip to content

Choose parametrization in sampling statement #1924

Closed
@aseyboldt

Description

@aseyboldt

Non-centered parametrizations are often a better choice than the centered parametrizations that are more natural to code in pymc3:

val = pm.Normal('val', mu=mu, sd=sd)

vs

val_raw = pm.Normal('val_raw', mu=0, sd=1)
val = pm.Deterministic('val', val_raw * sd + mu)

Couldn't we add a parameter parametrization or similar to distributions, such that we can automate that? This would also make it easier to for new users to try a couple of different parametrizations if something does not work well. I think we could reuse the framework we have in place for transformations. All we need for the non-centered parametrization is an affine transformation.

Some useful candidates:

# non-centered Normal
pm.Normal('val', mu=mu, sd=sd, parametrization='non-centered')
# as shortcut for
val_raw = pm.Normal('val_raw', mu=0, sd=1)
val = pm.Deterministic('val', val_raw * sd + mu)

# non-centered MvNormal
pm.MvNormal('val'" mu=mu, cov=cov, parametrization='non-centered')
# ->
val_raw = pm.Normal('val_raw', mu=0, sd=1)
pm.Deterministic('val', tt.slinalg.cholesky(cov).dot(val_raw))

# non-centered Lognormal on log space
pm.Lognormal('val', mu=mu, sd=sd, parametrization='log-non-centered')
# ->
val_raw = pm.Normal('val_raw', mu=0, sd=1)
val = tt.exp(val_raw * sd + mu)

# logit-sf for eg cauchy (not sure about this one, but it would work
# for pretty much any distribution if we can compute the survival function)
pm.Cauchy('val', alpha=alpha, beta=beta, parametrization='logit-sf')
# ->
val_raw = pm.Uniform('val_raw', lower=0, upper=1, transform='logit')
val = stats.cauchy(alpha=alpha, beta=beta).sf(val_raw)

Do you think this would be useful / would work? Other ideas for common reparametrizations (or better names ;)?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions