question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add unconstrained/transformed variables to InferenceData

See original GitHub issue

@ahartikainen suggested adding unconstrained variables to the schema somewhere. It seems like they could go

  1. Make new unconstrained_posterior group Good:
    • Explicit is better than implicit: it is clear what this group is for Bad:
    • Should there also be unconstrained_prior?
  2. Add them to the existing posterior group Good:
    • Can reuse existing coords/dims
    • Can add to prior in the same way Bad:
    • Would need a naming convention, which we’ve managed to avoid so far
    • PyMC3 currently does this, and it is kind of a pain to have a flag everywhere to include or exclude these variables.
  3. Don’t include them at all Good:
    • No work 😃 Bad:
    • Bounds and domain information are not captured anywhere currently

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
aseyboldtcommented, Aug 11, 2021

I would also like to see a way to get the transformed variables in the trace. The fact that this isn’t possible right now is pretty much the only reason I still use the original trace object of pymc3 quite a bit. I think I might even prefer if one of option 1 or 2 was the default behavior. The most common use cases I can see would be

  • When diagnosing convergence issues the untransformed space often doesn’t tell you much. If the transformation is just a log transform, that is easy to fix, but say for a Dirichlet this isn’t the case anymore. I think we should always think in the transformed space when making scatter plots of the posteriors, looking for funnels, correlations etc.
  • Anything that uses the logp has to also take into account which space we are talking about. The logp that is stored in the trace is with respect to the unconstrained space, so it doesn’t even make much sense when you don’t know what this is.
  • If we interact with the model a bit more, because for example we want to also look at the gradients of the logp (this can tell us something about correlations), or if we want to compute sensitivities with respect to some other variable, we need to interact with the aesara graph of the logp function. This is defined in terms of the transformed variables though. Getting at the gradients is easy with the original trace:
func = model.logp_dlogp_function()
func.set_extra_values({})
for point in trace.points():
    logp, grad = func(func.dict_to_array(point))

This is a lot more work if if we do not have the pymc3 trace, because we first have to manually map the values to the transformed space.

1reaction
ColCarrollcommented, Mar 17, 2021

hey dan! I think I’m generally on team option 3 still, but also on team “lets help out science”. So I’m totally on board with you adding a little backdoor option to allow this on pymc3, and if you do, maybe I can open a second issue requesting help to add it to various other backends (or even rethinking the design)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Built-in constrain vs user transformation - The Stan Forums
Hi all, I have a very basic question for constrained parameter/transform parameters (e.g. lower>0) Should there be any different in terms of ...
Read more >
Creating InferenceData — ArviZ dev documentation
InferenceData is the central data format for ArviZ. InferenceData itself is just a container that maintains references to one or more xarray.Dataset s....
Read more >
Getting started with PyMC3 - Learn PyMC & Bayesian modeling
PyMC3 random variables and data can be arbitrarily added, subtracted, divided, ... are also transformed to be unconstrained but with a log odds...
Read more >
API Reference - sbi - mackelab
_data_round_index.append(0) prior_masks = mask_sims_from_prior(0, ... Whether to transform parameters to unconstrained space during MAP optimization.
Read more >
Sparse logistic regression - Bean Machine
It also introduces the @bm.functional decorator, which can be used to deterministically transform random variables which can be convenient for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found