log absolute determinant of the Jacobian

651 views
Skip to first unread message

Vishv Jeet

unread,
Dec 8, 2016, 10:48:19 AM12/8/16
to Stan users mailing list
I am trying to sample a vector y in the model block, y is a non-linear transform of a parameter which is a matrix. So the Jacobian J of the transform is a matrix but non-square. 

Since J is non-square matrix, J' * J is a square matrix; whose determinant would be square of the determinant I need, so I multiply the log_determinant with 0.5. I did the following:

target += 0.5 * log_determinant(J' * J)

This should be correct but I want to make sure. 

STAN reference does mention that log_determinant or determinant takes only a square matrix but I guess that an is obvious requirement.


Regards,
Vishy 

Vishv Jeet

unread,
Dec 8, 2016, 10:55:23 AM12/8/16
to Stan users mailing list

Another related question would be how to do this if the parameter matrix that vector y depends upon is ragged, i.e., not every entry in the parameter matrix is defined?

Michael Betancourt

unread,
Dec 8, 2016, 12:30:41 PM12/8/16
to stan-...@googlegroups.com
This is not correct.

The Jacobian adjustment is for a 1-1 transformation which always
yields a square Jacobian.  For many-to-one or one-to-many
transformations you have to first construct a 1-1 transformation
with auxiliary parameters and then marginalize out the auxiliary
parameters from the resulting joint distribution.  For example,
if you had pi(x, y) and wanted the density for r = sqrt(x^2 + y^2)
then you could compute

pi(r) = \int d(theta) pi(r, theta) = \int d(theta) pi( x(r, theta), y(r, theta) ) | J (r, theta) |

Additionally, computing J and then calling log_determinant will be
viciously inefficient.  You almost always want to (and can) figure 
out the log Jacobian determinant analytically.

--
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.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vishv Jeet

unread,
Dec 8, 2016, 3:28:03 PM12/8/16
to Stan users mailing list

Thanks Michael. Not sure if I understood your suggestion entirely. My question is perhaps simpler, say

z = sqrt(x^2 + y^2)

suppose in STAN I am sampling z and x, y are parameters.

The jacobian J = (dz/dx, dz/dy) = (x / (x^2 + y^2)^1.5, y / (x^2 + y^2)^1.5) is a vector. So how do I compute the det(J)?

regards,
Vishy

andre.p...@googlemail.com

unread,
Dec 9, 2016, 4:22:31 AM12/9/16
to stan-...@googlegroups.com
Vishv,

wolframalpha showed something different:


For the Determinant, since x and y are independent, the bc part in ad-bc is 0.
Thus its ad. Since STAN needs on log scale its log(ad) = log(a) + log(d).
target += log(a)
target += log(d)


I hope that made it clear and I dont have a typo somewhere.

Andre
Reply all
Reply to author
Forward
0 new messages