Skip to content
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

Support for constrained variables #502

Open
fehiepsi opened this issue Mar 18, 2021 · 0 comments
Open

Support for constrained variables #502

fehiepsi opened this issue Mar 18, 2021 · 0 comments
Labels
discussion enhancement New feature or request

Comments

@fehiepsi
Copy link
Member

It could be nice to have a simple syntax to define a constrained variable. With this, users can be write code without having to worry about which transforms to use (sigmoid is simple but for many constraints, which transform to use is not trivial), for example

weight = Variable("x", constraint=unit_interval)
# weight = Variable("x").sigmoid()
spn = weight  * dist.Categorical([0.2, 0.8], value="v0").exp() \
    + (1 - weight) * dist.Categorical([0.3, 0.7], value="v1").exp() 

I think we can substitute x to spn as follows:

  • For the pattern Variable("x").sigmoid(), we can just substitute an unconstrained value: spn(x=unconstrained_value).
  • For the pattern Variable("x", constraint=unit_interval), it makes more sense to substitute a constrained value: spn(x=constrained_value). For optimizers, it would be nice to have a "magical" way to substitute an unconstrained value to spn, for example something like spn(x=unit_interval.transform(unconstrained_value)).

It is not clear to me how useful constrained variables will be in other situations, so I would like to consider this FR as low priority. It is a nice topic to discuss though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant