Church¶
Church is a probabilistic programming language based on Scheme, in which a program is an expression whose random choices pass values to the rest of the computation, and in which observations and factors change the weight of an execution (Goodman et al., 2008). Church's semantics is given by sampling: running a program produces an execution, a sequence of random choices with their addresses and values, and the joint log density of an execution is the sum of the log densities of its choices (Goodman and Stuhlmüller, 2014). The probabilistic choice operator on which such languages rest was given a semantics in a probability monad by Ramsey and Pfeffer (Ramsey and Pfeffer, 2002). The renderer writes programs whose execution under this reading gives the QVR density (Transpilation correctness).
No external Church implementation is fixed for the tests, and there is no Church image in the shared Docker matrix, so separate tests check selected emitted programs.
Change of variables¶
Church's distributions are defined by their samplers and densities, with no automatic change of variables, so \(\Psi_{\mathsf{Church}} = \mathrm{id}\).
Family parameterizations¶
Church uses the usual names of distributions (gaussian, dirichlet, categorical, bernoulli, beta, and
others). The map is the identity for every family with a Church counterpart, and
\(c_{F, \mathsf{Church}} = 0\).
Emitted constructs¶
sample and observe. (define <name> (sample (<family> <args>))) for a latent variable and
(observe (<family> <args>) <obs>) for an observation.
Plates. (map (lambda (m) (sample (<family> <args>))) (iota B)) makes a list of \(B\) independent draws,
and an observed plate is (for-each (lambda (n) (observe ...)) (iota N)). The density of the \(B\) independent
draws is the product of their densities.
marginalize. The renderer scores the scope once for each value of the latent variable, combines the
weighted alternatives with log-sum-exp, and adds the result with factor. A grouped block sums the rows of
each group before the reduction, so the latent variable is summed out.
score, let, return. (factor <expr>) for a score (Goodman and Stuhlmüller, 2014), (define <name> <expr>) for a
let, and the last expression of the (define (model ...) ...) body as the returned value.
Refusals. The renderer refuses a matrix literal with arg:matrix-literal, since Scheme has no standard
matrix form, and wrapper families that need the inner morphism's ~ Family(...) clause, such as Truncated
by rejection sampling.
Evidence¶
- Level 1. Every emitted model is a
(define (model ...) ...)withsampleandobservecalls, and calling the stages directly or composed gives the same output. - Level 2. No external Church parser is used. A check that the parentheses balance catches unmatched delimiters, and checking forms and primitive names would need a chosen Church implementation.
- Level 3. Church is not in the shared Docker matrix. Tests for Church check selected emitted programs.
Cited sources¶
Noah D. Goodman, Vikash K. Mansinghka, Daniel Roy, Keith Bonawitz, and Joshua B. Tenenbaum. Church: A Language for Generative Models. In Proceedings of the 24th Conference on Uncertainty in Artificial Intelligence, volume R6 of Proceedings of Machine Learning Research, 220–229. PMLR, 2008. Reissued by PMLR on 9 October 2024. URL: https://proceedings.mlr.press/r6/goodman08a.html.
Noah D. Goodman and Andreas Stuhlmüller. The Design and Implementation of Probabilistic Programming Languages. Author-published electronic textbook, 2014. URL: https://dippl.org.
Norman Ramsey and Avi Pfeffer. Stochastic Lambda Calculus and Monads of Probability Distributions. In Proceedings of the 29th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), 154–165. 2002. doi:10.1145/503272.503288.