I'm still not getting the same answers from Stan.
The parameters are slightly different in that
wishart uses a covariance parameter and wishart2x2
a correlation parameter.
wishart: cov12,var1,var2 and wishart2x2
wishart2x2: corr12,var1,var2.
I'm so lost with Ben's transform that I don't know
what to do next for debugging.
- Bob
I also don't understand why there is a double loop there
of size K when the doc says it's computing a diagonal
Jacobian.
I tried with all four options of commenting out/including
the Jacobian adjustments for the transforms of the first
two parts:
+/- : (-inf,inf) -> (-1,1) [CPCs]
+/- : (-inf,inf) -> (0,inf) [sds]
We get a random init of the parameters in the
unconstrained space. But the parameterizations in
wishart and wishart2x2 are not the same!
In wishart, the unconstrained params are whatever the
LKJ thingy uses. I think that's a CPC (presumably just the
correlation) and two standard deviations?
In the wishart2x2.hpp case, the unconstrained parameters
are exp() of the two variances and atanh() of the correlation.
I'd expect the correlation to have the same
gradient. But maybe not because of the dependency?
I haven't worked through the algebra.
- Bob
If the log prob isn't being incremented in
cov_matrix_constrain() with the log Jacobian determinant
of the full transform, the steps need to be added back in.
The only transform called out in the read_cov_L() doc is the
correlation -> covariance one and none are called out
in read_corr_L().I also don't understand why there is a double loop there
of size K when the doc says it's computing a diagonal
Jacobian.
I tried with all four options of commenting out/including
the Jacobian adjustments for the transforms of the first
two parts:+/- : (-inf,inf) -> (-1,1) [CPCs]
+/- : (-inf,inf) -> (0,inf) [sds]We get a random init of the parameters in the
unconstrained space. But the parameterizations in
wishart and wishart2x2 are not the same!
We should cut out the loops since they are equivalent to
log_prob += log_sds.sum() * K * 2.0;
The effective sample size may still be pretty low for
this. I'll take a look at a bunch of longer runs and
see how multiple runs of wishart vary compared to wishart2x2.
- Bob
Should I make the changes or do you want to?
1. replace the two loops in read_cov_L() with:
log_prob += log_sds.sum() * K * 2.0;
But I don't see why that's right. If it's just the
diagonal, then isn't that just transforming var -> sd?
In which case I see the 2.0 * log_sds.sum(), but why
the K?
2. Add the Jacobians back in for the cov_matrix_constrain()
Now I have to go back and follow your unbranch instructions.
- Bob
How are you even seeing W? The test_grad function
only prints the unconstrained value.
Should I make the changes or do you want to?
1. replace the two loops in read_cov_L() with:
log_prob += log_sds.sum() * K * 2.0;
But I don't see why that's right. If it's just the
diagonal, then isn't that just transforming var -> sd?
In which case I see the 2.0 * log_sds.sum(), but why
the K?
2. Add the Jacobians back in for the cov_matrix_constrain()
Now I have to go back and follow your unbranch instructions.
Could you make the changes?
Indeed, I doin't need to unmerge, just discard,
which is easy. It's just not at my fingertips.
I'm getting sucked into revising the Stan NSF proposal,
so haven't actually coded anything recently or written
any doc.
- Bob
Ben:Could you make the changes?