probcomp / GenExperimental.jl

Featherweight embedded probabilistic programming language and compositional inference programming library
MIT License
17 stars 2 forks source link

AIDE #66

Closed marcoct closed 7 years ago

marcoct commented 7 years ago

Basic implementation in terms of atomic generators added at https://github.com/probcomp/Gen.jl/blob/59b1cfc6710fd0dc6c27b26c49d95f3fb7efb00c/src/aide.jl

It's quite simple. The details around multiple-sample replicates are taken care of the replicate generator combinator.

"""
Estimate the KL divergence between two generators with the same output type.

AIDE: An algorithm for measuring the accuracy of probabilistic inference algorithms
Marco F. Cusumano-Towner, Vikash K. Mansinghka
https://arxiv.org/abs/1705.07224
"""
function aide(p::AtomicGenerator{T}, p_args::Tuple,
              q::AtomicGenerator{T}, q_args::Tuple) where {T}
    trace = AtomicTrace(T)
    propose!(trace, (), T)
    (p_log_weight, _) = generate!(p, p_args, trace)
    constrain!(trace, (), trace[()])
    (q_log_weight, _) = generate!(q, q_args, trace)
    p_log_weight - q_log_weight
end

export aide

Next step is to add a general-purpose SIR and SMC implementations, with AtomicGenerator views on these inference algorithms.

marcoct commented 7 years ago

AIDE implementation simplified using the compose module combinator:

"""
Estimate the KL divergence between two generators with the same output type.

AIDE: An algorithm for measuring the accuracy of probabilistic inference algorithms
Marco F. Cusumano-Towner, Vikash K. Mansinghka
https://arxiv.org/abs/1705.07224
"""
function aide(p::AtomicGenerator{T}, p_args::Tuple,
              q::AtomicGenerator{T}, q_args::Tuple) where {T}
    generator = compose(q, p, ())
    (score, _) = generate!(generator, (q_args, p_args), AtomicTrace(T))
    -score
end

export aide