Make `unflatten!!` return an `AbstractInitStrategy`

Aperta
#1,252 1 commento 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
30/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
julia

Direzione di ricerca

Inizia confrontando i percorsi slowLDF e fastLDF e tracciando gli utilizzi di unflatten!!, InitFromParams e init!!. Esamina poi come VectorValueAccumulator e OnlyAccsVarInfo si inseriscono nell’API proposta; il lavoro è completato quando unflatten!! restituisce un AbstractInitStrategy che può essere passato a init!! senza richiedere un VarInfo costruito ex novo né lasciare i transforms obsoleti.

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

Descrizione

I think unflatten is the single thing that I've complained about the most and I would dearly like to remove all need for this function ever again.

I've thought about this a fair amount and there are a few blockers to this, specifically, Gibbs (https://github.com/TuringLang/Turing.jl/issues/2764). However, a very positive intermediate step would be to make unflatten!! return a new AbstractInitStrategy instead of a new VarInfo.

If you look at the difference between old slow LDF and new fast LDF, it mostly boils down to:

  • slowLDF used unflatten + evaluate!! on a VarInfo;
  • fastLDF constructs an InitFromParams{<:VectorWithRanges}, that is semantically equal to a VarInfo whose contents have been replaced with the vector, but avoids actually using a VarInfo

I think this idea can be extended more broadly to also work with generic VarInfo. Essentially, unflatten!! would probably return exactly the same InitFromParams{<:VectorWithRanges} object that the LDF constructs. We could probably even share some code.

If you REALLY want a new VarInfo with those values, simple! Just do this

new_init_strategy = unflatten!!(varinfo, vec)
_, new_varinfo = init!!(model, varinfo, new_init_strategy)

The second line will overwrite everything inside the old varinfo. It will also cause the transforms to be updated, so there is no risk of having out of date transforms, which is my current number one gripe with unflatten!!.

Essentially, the above would replace the current workflow of

new_varinfo = unflatten!!(varinfo, vec)

# If you forget to do this (e.g. because you want to avoid the cost
# of reevaluating) and just use new_varinfo directly...... maybe in 
# a subsequent MCMC step or in a different function ....... Oops!!!!
_, new_varinfo = evaluate!!(model, new_varinfo)

However, returning an AbstractInitStrategy is also more versatile. You can use it with an OnlyAccsVarInfo. You can use it with a LogDensityFunction (once I've reimplemented #1232, which is not difficult). It doesn't tie you into using a full VarInfo.

In fact, unflatten!! doesn't need a full VarInfo either -- it only needs a VectorValueAccumulator. That would be the next logical step after the above. What this means is that, any function who uses unflatten!! would be responsible upfront for making sure that there is a VectorValueAccumulator somewhere that it can use.

new_init_strategy = unflatten!!(vector_value_acc, vec)
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.