Should we always pass `rng` to the model?
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
- 25/100
Direzione di ricerca
Inizia tracciando i percorsi di @model evaluator e SamplingContext descritti nell’issue, quindi riproduci l’esempio di subsampling per osservare come viene attualmente ottenuta la casualità. Una modifica completa richiederebbe un design dell’API concordato che preservi il comportamento deterministico del modello per un rng fornito, insieme all’implementazione e ai test corrispondenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Back in the day, the evaluator for a @model would look like
function demo(rng, model, varinfo, context, sampler)
...
end
or something like this.
But when we started making use of contexts more drastically in #249 , this became instead the simpler
function demo(model, varinfo, context)
...
end
and instead we provide the rng and sampler argument sometimes through the Samplingcontext(rng, sampler, context), thus providing a clear separation between when we're sampling and when we're evaluating a model.
However, this consequently doesn't allow someone to define models with inherit randomness in them while still preserving determinisim conditional on a rng.
A simple example is an implementation of a model with subsampling of the data. I could do this as follows:
julia> using DynamicPPL, Distributions
julia> @model function demo(y, batch_size=1)
x ~ Normal()
y_indices = rand(1:length(y), batch_size)
y[y_indices] .~ Normal(x, 1)
end
demo (generic function with 4 methods)
julia> model = demo(randn(32), 4);
julia> model()
4-element view(::Vector{Float64}, [11, 18, 20, 5]) with eltype Float64:
-0.35070761628093716
0.19218100395285695
0.8506289607980133
1.0317998072662038
julia> rand(model)
(x = -0.991550644289528,)
However, the issue in the above is ofc that the rand call inside @model doesn't have access to the rng used internally in the model, and thus cannot ensure that everything is deterministic given an rng.
Ofc, the user could provide the rng as a specific argument, but this seems quite redundant as we often will have an rng available.
As a result, I'm thinking that it might be useful to remove the rng from the SamplingConctext and instead make it a similarly "private" varriable so users could do
julia> @model function demo(y, batch_size=1)
x ~ Normal()
y_indices = rand(__rng__, 1:length(y), batch_size)
y[y_indices] .~ Normal(x, 1)
end
demo (generic function with 4 methods)
as they could before.
Thoughts? @mhauru @penelopeysm @yebai @willtebbutt @sunxd3
- Lingua principale
- Julia
- Stelle
- 291
- Fork
- 43
- Merge medio
- 1g 23h
- PR unite (30g)
- 15
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TuringLang/DynamicPPL.jl
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 64/100
TuringLang/DynamicPPL.jl#1499 ·
I maintainer di solito rispondono entro 2 giorni
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
TuringLang/DynamicPPL.jl#1480 ·
I maintainer di solito rispondono entro 2 giorni
-
Separate model-evaluation inputs from outputsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertadata-structures enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
TuringLang/DynamicPPL.jl#1469 ·
I maintainer di solito rispondono entro 2 giorni
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
TuringLang/DynamicPPL.jl#1466 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
documentation
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
TuringLang/DynamicPPL.jl#1390 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di TuringLang/DynamicPPL.jl
Issue simili
-
Release CorleoneInverse as 0.1.1Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
SciML/Corleone.jl#200 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
JuliaAI/MLJTransforms.jl#120 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
exercism/julia#1205 · 3 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
SciML/OrdinaryDiffEq.jl#5175 ·
I maintainer di solito rispondono entro 1 giorno