stan-dev / math

The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
723 stars 183 forks source link

Add overload for `lub_constrain`/`lub_free` for single tuple of bounds #3083

Closed andrjohns closed 1 week ago

andrjohns commented 1 week ago

Description

Requiring separate arguments when specifying upper and lower bounds can lead to redundant computation. By taking a single tuple containing the upper/lower bounds, models can reuse quantities as much as possible

Example

This would be great for copula with discrete marginals, where the linear predictor term is used to specify bounds

Current Version:

v4.9.0

andrjohns commented 1 week ago

This would also require a new keyword for the constraint though, @WardBrian what do you think?

WardBrian commented 1 week ago

I’d want to see an example, but if my first guess is correct it seems reasonable to have a lower_upper=(,) keyword

andrjohns commented 1 week ago

I’d want to see an example, but if my first guess is correct it seems reasonable to have a lower_upper=(,) keyword

Brill! An alternative would also be to allow using transformed parameters in parameter bounds, but I have no idea how complex that might be on the backend