Description
I'm trying to understand a discrepancy in the log_prob computation between Stan and TFP. I don't know if this is bug, and if it is, where; I'm reporting this here in case anyone thinks this may be of interest.
I generated Cholesky factors of LKJ matrices using the following Stan code:
code <- "
data {
int K;
}
parameters {
cholesky_factor_corr[K] L;
}
model {
target += lkj_corr_cholesky_lpdf(L|2.0);
}
I extracted samples and log_prob:
library(rstan)
data = list(K=5)
fit <- stan(model_code = code, data=data)
e <- as.data.frame(extract(fit))
Finally, I computed the log prob of these matrices using TFP:
m = tfd.CholeskyLKJ(5,2)
b = tfb.CorrelationCholesky()
for datum in data[:k,:-1]:
L = datum.reshape(5,5).T
tfp_lps.append(m.log_prob(L).numpy())
When I compare tfp_lps
to Stan's lp__
, I get a high correlation, but they're not the same. For comparison, running this check with something like a normal distribution passes np.allclose
. I've also suspected that this might be related to different handling of log_det_jacobian, but subtracting tfb.CorrelationCholesky().inverse_log_det_jacobian(L,2) didn't help.
Is there something wrong in the way I'm running the comparison, or in the expectation that they would be the same in the first place?
Thanks in advance!