Reconstructing Cholesky variables from their indices gives wrong result in VNT

Aperta
#1,262 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
julia
Ambito
backend

Direzione di ricerca

Inizia in src/varnamedtuple.jl alle righe 167-208 e segui come @vnt utilizza il template fornito quando ricostruisce i valori di Cholesky da MCMCChains.Chains. Confronta le due direzioni proposte —costruire incrementalmente un PartialCholesky oppure rimuovere il supporto per MCMCChains— e conferma che il VNT risultante preservi la struttura di Cholesky senza il workaround hasvalue/getvalue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

data-structures enhancement
julia> using DynamicPPL, Distributions

julia> c = rand(LKJCholesky(3, 0.5))
Cholesky{Float64, Matrix{Float64}}
L factor:
3×3 LinearAlgebra.LowerTriangular{Float64, Matrix{Float64}}:
  1.0        ⋅         ⋅
 -0.71428   0.69986    ⋅
  0.255189  0.911365  0.322942

julia> vnt = @vnt begin
           @template c
           c.L[1, 1] := c.L[1, 1]
           c.L[2, 1] := c.L[2, 1]
           c.L[2, 2] := c.L[2, 2]
           c.L[3, 1] := c.L[3, 1]
           c.L[3, 2] := c.L[3, 2]
           c.L[3, 3] := c.L[3, 3]
       end
VarNamedTuple
└─ c => VarNamedTuple
        └─ L => PartialArray size=(3, 3) data::LinearAlgebra.LowerTriangular{Float64, Matrix{Float64}}
                ├─ (1, 1) => 1.0
                ├─ (2, 1) => -0.7142799536546864
                ├─ (3, 1) => 0.25518913641826435
                ├─ (2, 2) => 0.6998600915947837
                ├─ (3, 2) => 0.9113653464249535
                └─ (3, 3) => 0.3229422703670502

Obviously, this doesn't reconstruct the Cholesky sample c despite us passing the template to it.

When does this pathological situation occur? Easy, it's when trying to load samples back into a VNT from MCMCChains.Chains, since Cholesky samples get broken up in MCMCChains.

(with FlexiChains it doesn't break up the sample so you would get something like this and it's a-ok

julia> vnt2 = @vnt begin
           c := c
       end
VarNamedTuple
└─ c => Cholesky{Float64, Matrix{Float64}}([1.0 5.0e-324 0.0; -0.7142799536546864 0.6998600915947837 0.0; 0.25518913641826435 0.9113653464249535 0.3229422703670502], 'L', 0)

)

Now the above issue doesn't yet cause problems because we have this patch for VNT that calls hasvalue(..., dist) and getvalue(..., dist)

https://github.com/TuringLang/DynamicPPL.jl/blob/fd3d2800ba43023d4bed571f467451d7eae61bb2/src/varnamedtuple.jl#L167-L208

However, it is really just wrong to even create a VNT with the wrong structure. That VNT should never be allowed to exist!!! We do have enough info to re-create the correct form of c because we pass the template in, it's just that we're not using it.

There are two Correct Things to do, either of which will allow us to stop creating these wrong VNTs, and thereby remove these hasvalue / getvalue methods:

  1. Use the template to make a PartialCholesky thing, and then fill it in one element by one element.
  2. Stop using MCMCChains, and once we stop using MCMCChains, just declare this as unsupported.
Lingua principale
Julia
Stelle
291
Fork
43
Merge medio
1g 23h
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TuringLang/DynamicPPL.jl

Tutte le issue di TuringLang/DynamicPPL.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.