Skip to content

Dynamic constraints? #356

Open
Open
@Kucharssim

Description

@Kucharssim

In some models, it is handy to constrain parameters dynamically (e.g., based on data or other parameters). This implies that the support of the parameter during simulation is different than parameter support during inference.

A simple (silly) example would be when we want to estimate an upper bound of a uniform distribution:

$$ \begin{aligned} x_i & \sim \text{Uniform}(0, u) \\ u & \sim \text{Exponential}(1) \end{aligned} $$

Then we know that upon observing $x_1, \dots, x_n$, the likelihood of the model is zero for every $u < \max(x)$, and so the posterior of u is constrained from below by $\max(x)$.

To make sure this constraint is respected during inference, it is possible to reparametrize the model

def prior():
    return dict(u = np.random.exponential(1))
def likelihood(u):
    return dict(x = np.random.uniform(low=0, high=u, size=10))
def reparam(u, x):
    return dict(u_shifted=u-np.max(x))

simulator=bf.make_simulator([prior, likelihood, reparam])

then learn the unconstrained version of the shifted upper bound

adapter.constrain("u_shifted", lower=0).rename("u_shifted", "inference_variables")

The downside is that in order to obtain the posterior of u during inference, one has to manually compute it as u_shifted + max(x). That leads me to a question whether the adapter could be changed to handle dynamic bounds so that both the forward and the backward transform is automatic?

While it sounds weird, this can come up in real applications. For example, this is a common feature of basic evidence accumulation models, where the non-decision time parameter cannot be larger than the observed response times. Stan for example also allows dynamic parameter constraints: https://mc-stan.org/docs/reference-manual/types.html#expressions-as-bounds-and-offsetmultiplier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscuss a topic or question not necessarily with a clear output in mind.featureNew feature or requestsugarSyntactical sugar or quality of life improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions