Giter VIP home page Giter VIP logo

Comments (1)

bob-carpenter avatar bob-carpenter commented on July 3, 2024

Not yet. It's something we've been thinking about. The main problem is that transforms are ordered and their composition doesn't always make sense. When you write <lower=0, multiplier=2>, then I presume your intent is to have the constraining transform first apply the multiplier, then the lower bound, so that the map f:(-inf, inf) -> (0, inf) is f(x) = exp(2 * x). It's also possible to do it the other way around, f(x) = 2 * exp(x). To disambiguate, we'd need to have something like

real<lower=0><multiplier=2> sigma1;  // sigma1 = exp(sigma1_unconstrained) * 2
real<multiplier=2><lower=0> sigma2;  // sigma2 = exp(2 * sigma2_unconstrained)

to clarify which of these transforms is desired. We're worried that people will confuse the ordering of composition, which here I've assumed is left to right, or equivalently, inside out from real.

Now consider offsets, where we might have <lower=0, offset=2>. IN this case, the ambiguity is between the constraining transforms f(x) = 2 + exp(x) and f(x) = exp(2 + x). The problem is that the former maps (-inf, inf) to (2, inf), whereas the latter maps (-inf, inf) to (0, inf).

We'd like to be able to extend these transforms to things with upper and lower bounds, orderings, simplexes, etc.

Having said all that, if you want the effect you are after, you can code it yourself as the Jacobian is trivial here for f(x) = exp(2 * x), where f'(x) = 2 * exp(2 * x). Wolfram Alpha is very convenient for scalar functions, where you can just enter d/dx exp(2 * x) and it'll give you the answer.

parameters {
  real sigma_unc;
}
transformed parameters {
  real<lower=0> sigma = exp(2 * sigma_unc);
}
model {
  target +=  2 * exp(2 * sigma_unc);  // more efficiently, target += 2 * sigma;
}

You can do the same exercise if you intended the other way around, 2 * exp(sigma_unc).

I'm going to close this issue as we already have similar issues in the math library (e.g., stan-dev/math#2959), which is where we'd start. We're actively working on this and want a general solution, perhaps with user-defined transforms, but as with all things Stan, there's no schedule for when it'll be done.

from stan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.