Dynamic models with index notation

Aperta
#1,008 2 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
20/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
julia

Direzione di ricerca

Inizia con gli esempi f_indices, f_product e f_addinf nell’issue, quindi esamina la discussione sulla semantica statistica e sui limiti del sampler. Il lavoro è completo quando si è deciso quale interpretazione del modello DynamicPPL debba supportare e come debba essere specificato il suo comportamento; non sono indicati file di implementazione né test.

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

Descrizione

enhancement

What is the statistical model that this should implement?

@model function f_indices()
    b ~ Bernoulli()
    x = Vector{Float64}(undef, b ? 1 : 2)
    if b
        x[1] ~ Normal(1.0)
    else
        x[1] ~ Normal(1.0)
        x[2] ~ Normal(2.0)
    end
end

Some options:

  1. Nothing. That should be invalid.

  2. A model for which the domain of x[2] is Union(Reals, {N/A}) and the joint is

p(b, x1, x2) = p(b) p(x1) p(x2 | b)

where

p(b) = Bernoulli
p(x1) = Normal(1.0)

and the distribution p(x2 | b) is such that its density function is

pdf(p(x2 | b == true))(y) = y == N/A ? 1.0 : 0.0
pdf(p(x2 | b == false))(y) = y == N/A ? 0.0 : pdf(Normal(2.0))(y)

  1. A model like the above but where the domain of x[2] is Reals and

pdf(p(x2 | b))(y) = b ? 1.0 : pdf(Normal(2.0))(y)

This is what we currently do. I'm not convinced that this is a valid statistical model though.

Other similar models

@model function f_product()
    b ~ Bernoulli()
    if b
        dists = [Normal(1.0)]
    else
        dists = [Normal(1.0), Normal(2.0)]
    end
    x ~ product_distribution(dists)
end

This seems to currently implement option 2. from above.

@model function f_addinf()
    b ~ Bernoulli()
    x = Vector{Float64}(undef, b ? 1 : 2)
    if b
        x[1] ~ Normal(1.0)
    else
        if length(__varinfo__[@varname(x)]) == 1
            @addlogprob! -Inf
        end
        x[1] ~ Normal(1.0)
        x[2] ~ Normal(2.0)
    end
end

This, too, seems to implement something like option 2. from above, in a different manner. f_product errors if you evaluate it with a VarInfo where b is false and x only has one element, whereas f_addinf executes but rejects all such samples.

Sampling

Note that we don't know how to sample from f_product or from f_addinf, or more generally anything that implements option 2. from above. The only samplers that I know of that can handle both discrete and continuous parameters are MH and Gibbs. Gibbs won't ever work for this, because if x is in the acceptable range for some value of b then you can't get a valid sample from changing just b or changing just the range of x; You'd have to change both at once, and that is exactly what Gibbs doesn't do. MH could in principle work, but we would need to use a proposal distribution that allows going from x being length 1 to x being length 2. Such a jump would then have to be done at the same time as changing the value of b.

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.