stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.58k stars 368 forks source link

Implement Asymmetric Laplace Distribution #2312

Open heroxbd opened 7 years ago

heroxbd commented 7 years ago

Summary:

We would like to have asymmetric Laplace distribution to be implemented in stan.

Description:

As discussed in the mailing list, it is particularly of interest for Bayesian quantile regression.

Also known as skewed Laplace distribution, the asymmetric Laplace distribution has an additional parameter \tau (\tau \in [0,1])

codecogseqn

which reduces to Laplace distribution when \tau=0.5.

With the Laplace distribution already in stan (named DoubleExponential), introducing asymmetric Laplace distribution is relatively straight forward.

Additional Information:

Yu, K., Moyeed, R.A., 2001. Bayesian quantile regression. Statistics & Probability Letters 54, 437–447. doi:10.1016/S0167-7152(01)00124-9

bob-carpenter commented 7 years ago

Thanks for the issue with definition. This should be relatively easy. You can, of course, just code it in Stan now as

real skew_double_exponential_lpdf(real y, real mu, real sigma, real tau) {
  return log(tau) + log1m(tau)
    - log(sigma)
    - 2 * ((y < mu) ? (1 - tau) * (mu - y) : tau * (y - mu)) / sigma;
}

It's not vectorized and doesn't drop constants (if tau is constant you can drop the first two terms and if sigma is constant you can drop the third, but it should work.

And fair warning: this distribution may cause problems in the region around y == mu because the derivative's not continuous there.

bgoodri commented 7 years ago

It is fairly straightforward to do quantile regression when the asymmetric Laplace distribution is represented as a scale mixture of normals, which is differentiable everywhere. But due to the discontinuity, I don't think it is a big priority to add the _lpdf, etc. to Stan Math and the Stan language.

On Mon, May 22, 2017 at 12:22 PM, Bob Carpenter notifications@github.com wrote:

Thanks for the issue with definition. This should be relatively easy. You can, of course, just code it in Stan now as

real skew_double_exponential_lpdf(real y, real mu, real sigma, real tau) { return log(tau) + log1m(tau)

  • log(sigma)
  • 2 ((y < mu) ? (1 - tau) (mu - y) : tau * (y - mu)) / sigma; }

It's not vectorized and doesn't drop constants (if tau is constant you can drop the first two terms and if sigma is constant you can drop the third, but it should work.

And fair warning: this distribution may cause problems in the region around y == mu because the derivative's not continuous there.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stan-dev/stan/issues/2312#issuecomment-303149606, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqhQdA1ZqwsnQrHYRwsRmXtLTbqAIks5r8bZHgaJpZM4NhzRp .

dirmeier commented 4 years ago

Hey @bob-carpenter and @bgoodri , would you mind if I had a look at this and implement it in math? Like I said in another thread, I'd like to help out more with Stan, but have trouble identifying "what needs to be done", so I guess just fixing issues would be a good start (if that is fine with you).

Cheers, Simon

bgoodri commented 4 years ago

I don't think anyone ever has grounds to mind if someone else wants to implement something in Math.

On Mon, Jul 6, 2020 at 12:45 PM Simon Dirmeier notifications@github.com wrote:

Hey @bob-carpenter https://github.com/bob-carpenter and @bgoodri https://github.com/bgoodri , would you mind if I had a look at this and implement it in math? Like I said in another thread, I'd like to help out more with Stan, but have trouble identifying "what needs to be done", so I guess just fixing issues would be a good start (if that is fine with you).

Cheers, Simon

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/stan/issues/2312#issuecomment-654348002, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKTCDQVTCTQJ5EYAKWLR2H5S7ANCNFSM4DMHGRUQ .

bob-carpenter commented 4 years ago

By all means. It's open source and we love getting new contributors. Let us know if you need help. Our onboarding docs are still something of a mess.

I would suggest going to the issue (in stan-dev/math, not in the monorepo project that never got finished) and commenting that you're working on an implementation. If there's not an issue, creating one is the first step.

Basically, anything that has an issue is something we want to implement. The problem is that they're not prioritized or sorted for dependency. That's largely because what to work on is a matter of individual developer priorities and what they're interested in doing. Is there something you'd like to add to Stan, either on the issue tracker or not?

dirmeier commented 4 years ago

Hi @bob-carpenter

I would suggest going to the issue (in stan-dev/math, not in the monorepo project that never got finished) and commenting that you're working on an implementation. If there's not an issue, creating one is the first step.

thanks! Will do.

Is there something you'd like to add to Stan, either on the issue tracker or not?

No, not really. I just want to help out right now until I understand math and stan better...