absolute functions

346 views
Skip to first unread message

Sebastian Weber

unread,
Apr 7, 2015, 7:52:06 AM4/7/15
to stan-...@googlegroups.com
Hi!

I understand that discontinuous functions are inadvertently bad news for HMC. But I wonder if the absolute value functions could be replaced with something which removes the sign, but remains fully continuous (or I am missing here something):

abs(a) := sqrt( a^2 )

If possible, a function log_diff_exp_abs would be great to have, i.e.

  real log_diff_exp_abs(real la, real lb) {
    return(0.5 * log_diff_exp(log_sum_exp(2*la, 2*lb), log(2) + la + lb));
  }

which uses

sqrt( (a - b)^2 ) = sqrt( a^2 - 2 * a * b + b^2 )

Anything wrong here?

Best,
Sebastian

Bob Carpenter

unread,
Apr 7, 2015, 8:29:45 AM4/7/15
to stan-...@googlegroups.com
abs(a) is continuous, just not continously differentiable.
Same for sqrt(a^2).

You can get close with a "soft" absolute value that is
equal to abs(a) except for a small neighborhood around 0
where it's smoothed out.

But that doesn't help with the other issue that abs(a) creates,
namely that it introduces a reflection-based multimodality
if a is a parameter.

What's the purpose of that log_diff_exp_abs function you're
proposing?

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Michael Betancourt

unread,
Apr 7, 2015, 8:39:24 AM4/7/15
to stan-...@googlegroups.com
Just use x * coth(alpha * x) for some large alpha.
For details, http://arxiv.org/pdf/1212.4693.pdf.

Sebastian Weber

unread,
Apr 7, 2015, 10:22:31 AM4/7/15
to stan-...@googlegroups.com
Hi!

Yes, I just calculated the diff myself and came to the same conclusion. I will look at the coth stuff, thanks.

The purpose of the log_diff_exp_abs function is to be able to calculate what is called the "Bateman" function, i.e. in PK systems you often have the following form:

1/(a-b) * ( exp(-a*t) - exp(-b*t))

If a > b, then everything is straightforward. If a < b the result is still always positive, but using log_diff_exp does not work, as a - b is negative and hence only the total expression remains positive.

Doing this squaring and root thing solves the issue.

Sebastian

PS: I just had to find out, that the Bateman function seems to be, in general, differently defined if you refer to mathworld: http://mathworld.wolfram.com/BatemanFunction.html
Reply all
Reply to author
Forward
0 new messages