TuringLang / Bijectors.jl

Implementation of normalising flows and constrained random variable transformations
https://turinglang.org/Bijectors.jl/
MIT License
200 stars 33 forks source link

What to do with `CorrBijector` ? #268

Open harisorgn opened 1 year ago

harisorgn commented 1 year ago

After #246, CorrBijector is no longer in use. This was the old bijector for LKJ which mapped a correlation matrix to a matrix of the same dimensions in unconstrained space (see https://mc-stan.org/docs/reference-manual/correlation-matrix-transform.html).

Shall we remove CorrBijector altogether or keep/adapt it for some other purpose (can't think of something right now) ?

sethaxen commented 4 months ago

There's still a use-case for a bijector that is effectively F = cholesky(R) for correlation matrix R. Suppose one wants a parameter F because their model needs the Cholesky factorization, but they want to put a Normal(0.9, 0.01) prior on R[1, 2]. Then they would need something like

@model function demo(n)
    F ~ LKJCholesky(n, 1)  # uniform distribution on Matrix(F)
    Rmat, logJ = with_logabsdet_jacobian(inverse(CorrToCholeskyBijector()), F)
    R := Rmat  # track R
    Turing.@addlogprob! logJ + logpdf(Normal(0.9, 0.01), R[1, 2])
    # add the rest of the model using F
end

The current CorrBijector() is effectively VecCholeskyBijector() ∘ CorrToCholeskyBijector()