what do we use fvar<fvar<double>> for?

16 views
Skip to first unread message

Charles Margossian

unread,
Aug 23, 2016, 10:44:31 AM8/23/16
to stan development mailing list
I'm learning how to implement unit tests. When looking at existing tests for forward mode, I found functions were expected to handle variables of the type fvar<fvar<double>> (see round_test and sin_test for example). What do we use this variable type for?

I'm guessing for second derivatives, since with x of type fvar<fvar<...>> the tangent of x is itself an AD variable for which we can compute the derivative. But then again, it's just a guest.

Bob Carpenter

unread,
Aug 23, 2016, 11:31:17 AM8/23/16
to stan...@googlegroups.com
I don't think we ever use that in Stan right now, but
it would be used to compute second derivatives with respect
to a single pair of variables. So calling the density with
that argument N times would be the most efficient way to
compute the diagonal of a Hessian as we might use in RHMC.

We'd usually use fvar<var> to compute Hessians and
fvar<fvar<var> > to compute third order derivatives
(as required by the SoftAbs version of RHMC).

- Bob

> On Aug 23, 2016, at 4:44 PM, Charles Margossian <charles.ma...@gmail.com> wrote:
>
> I'm learning how to implement unit tests. When looking at existing tests for forward mode, I found functions were expected to handle variables of the type fvar<fvar<double>> (see round_test and sin_test for example). What do we use this variable type for?
>
> I'm guessing for second derivatives, since with x of type fvar<fvar<...>> the tangent of x is itself an AD variable for which we can compute the derivative. But then again, it's just a guest.
>
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages