Giter Site home page Giter Site logo

Comments (8)

torfjelde avatar torfjelde commented on August 20, 2024

I don't think there's anything wrong here, it's just that it's numerically very unstable. If I run the code with an inserted print statement in the definition of the inverse-evaluation of CorrBijector, I get the following as an input (i.e. the value in the unconstrained space that HMC is working with):

10×10 Array{Float64,2}:
 0.0  -1630.14  -857.317  -8051.24      -825.602   -1598.03   -1801.29
 0.0      0.0   8426.06   25379.5       -5603.79    -6840.33   -3651.21
 0.0      0.0      0.0    30092.8       -2565.67    -4733.44     -56.0023
 0.0      0.0      0.0        0.0       -7583.1    -10285.7     8297.9
 0.0      0.0      0.0        0.0       -4432.82    -6084.45    6599.2
 0.0      0.0      0.0        0.0     -23834.4    -31462.6   -55327.8
 0.0      0.0      0.0        0.0      -33831.2    -42291.8    22720.5
 0.0      0.0      0.0        0.0           0.0     42018.5    13520.2
 0.0      0.0      0.0        0.0           0.0         0.0    32250.5
 0.0      0.0      0.0        0.0           0.0         0.0        0.0

Now, that doesn't look too pretty. The "transformed" version (from unconstrained to constrained) is:

10×10 Array{Float64,2}:
  1.0  -1.0  -1.0  -1.0  -1.0  -1.0   1.0  -1.0  -1.0  -1.0
 -1.0   1.0   1.0   1.0   1.0   1.0  -1.0   1.0   1.0   1.0
 -1.0   1.0   1.0   1.0   1.0   1.0  -1.0   1.0   1.0   1.0
 -1.0   1.0   1.0   1.0   1.0   1.0  -1.0   1.0   1.0   1.0
 -1.0   1.0   1.0   1.0   1.0   1.0  -1.0   1.0   1.0   1.0
 -1.0   1.0   1.0   1.0   1.0   1.0  -1.0   1.0   1.0   1.0
  1.0  -1.0  -1.0  -1.0  -1.0  -1.0   1.0  -1.0  -1.0  -1.0
 -1.0   1.0   1.0   1.0   1.0   1.0  -1.0   1.0   1.0   1.0
 -1.0   1.0   1.0   1.0   1.0   1.0  -1.0   1.0   1.0   1.0

I need to look more into the LKJ distribution to see how we can deal with this though. Possibly related: https://mc-stan.org/docs/2_18/functions-reference/cholesky-lkj-correlation-distribution.html

from bijectors.jl.

cpfiffer avatar cpfiffer commented on August 20, 2024

Actually, I wonder if this is just an initilization problem. Like if we tilted the initialization towards regions of the unconstrained space that actually mapped to meaningfully differentiable correlation matrices.

Edit: bad solution, I know, because then it's a different density.

from bijectors.jl.

torfjelde avatar torfjelde commented on August 20, 2024

No, this is fine. This is essentially what we do in Turing wit the "robust" init-methods. But this is more of an issue with Turing rather than Bijectors, no?

EDIT: As in, it's fine to change the initialization procedure, but not the actual distribution, yeah.

from bijectors.jl.

devmotion avatar devmotion commented on August 20, 2024

Possibly also related: #134

from bijectors.jl.

cpfiffer avatar cpfiffer commented on August 20, 2024

No, this is fine. This is essentially what we do in Turing wit the "robust" init-methods. But this is more of an issue with Turing rather than Bijectors, no?

Yeah, perhaps, though the real issue might be the numerical instability. If the "true" bijector exists and is really numerically stable, then it doesn't matter how it's initialized.

from bijectors.jl.

bratslavia avatar bratslavia commented on August 20, 2024

Just a data point that may be relevant to this issue - I noticed that LKJ seems to never work with NUTS (giving the above posdef error), but it does seems to work just fine with HMC. E.g.,

using Turing

@model function LKJ_demo(P)
    y ~ LKJ(P, 1)
end
model = LKJ_demo(5)

m1 = sample(model, HMC(0.01, 20), MCMCThreads(), 1, 4) # Works
m2 = sample(model, NUTS(1, 0.65), MCMCThreads(), 1, 4) # Always fails

from bijectors.jl.

torfjelde avatar torfjelde commented on August 20, 2024

@bratslavia This is because NUTS has an adaptation phase where it will try out possibly "extreme" step-sizes, while HMC is using the fixed-step size of 0.01 that you provide. As a result, numerical issues are more likely to show up when using NUTS rather than HMC (unless you specify a very large step-size).

from bijectors.jl.

mgmverburg avatar mgmverburg commented on August 20, 2024

So what is the current suggested workaround, if any?
Bratslavia's MWE is indeed perfectly indicative of what I have been experiencing, that, at least as long as using NUTS then probably, it is very likely to run into an error that will basically stop all sampling.

from bijectors.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.