pub enum Model<A> {
Pure(A),
SampleF64 {
addr: Address,
dist: Box<dyn Distribution<f64>>,
k: Box<dyn FnOnce(f64) -> Model<A> + Send + 'static>,
},
SampleBool {
addr: Address,
dist: Box<dyn Distribution<bool>>,
k: Box<dyn FnOnce(bool) -> Model<A> + Send + 'static>,
},
SampleU64 {
addr: Address,
dist: Box<dyn Distribution<u64>>,
k: Box<dyn FnOnce(u64) -> Model<A> + Send + 'static>,
},
SampleUsize {
addr: Address,
dist: Box<dyn Distribution<usize>>,
k: Box<dyn FnOnce(usize) -> Model<A> + Send + 'static>,
},
ObserveF64 {
addr: Address,
dist: Box<dyn Distribution<f64>>,
value: f64,
k: Box<dyn FnOnce(()) -> Model<A> + Send + 'static>,
},
ObserveBool {
addr: Address,
dist: Box<dyn Distribution<bool>>,
value: bool,
k: Box<dyn FnOnce(()) -> Model<A> + Send + 'static>,
},
ObserveU64 {
addr: Address,
dist: Box<dyn Distribution<u64>>,
value: u64,
k: Box<dyn FnOnce(()) -> Model<A> + Send + 'static>,
},
ObserveUsize {
addr: Address,
dist: Box<dyn Distribution<usize>>,
value: usize,
k: Box<dyn FnOnce(()) -> Model<A> + Send + 'static>,
},
Factor {
logw: LogF64,
k: Box<dyn FnOnce(()) -> Model<A> + Send + 'static>,
},
}Expand description
Model<A> represents a probabilistic program that yields a value of type A when executed by a handler.
Models are built from four variants: Pure, Sample*, Observe*, and Factor.
Example:
// Deterministic value
let m = pure(42.0);
// Sample from distribution
let s = sample(addr!("x"), Normal::new(0.0, 1.0).unwrap());
// Dependent sampling
let chain = s.bind(|x| sample(addr!("y"), Normal::new(x, 0.5).unwrap()));Variants§
Pure(A)
A deterministic computation yielding a pure value.
SampleF64
Sample from an f64 distribution (continuous distributions).
Fields
dist: Box<dyn Distribution<f64>>Distribution to sample from.
SampleBool
Sample from a bool distribution (Bernoulli).
Fields
dist: Box<dyn Distribution<bool>>Distribution to sample from.
SampleU64
Sample from a u64 distribution (Poisson, Binomial).
Fields
dist: Box<dyn Distribution<u64>>Distribution to sample from.
SampleUsize
Sample from a usize distribution (Categorical).
Fields
dist: Box<dyn Distribution<usize>>Distribution to sample from.
ObserveF64
Observe/condition on an f64 value.
Fields
dist: Box<dyn Distribution<f64>>Distribution that generates the observed value.
ObserveBool
Observe/condition on a bool value.
Fields
dist: Box<dyn Distribution<bool>>Distribution that generates the observed value.
ObserveU64
Observe/condition on a u64 value.
Fields
dist: Box<dyn Distribution<u64>>Distribution that generates the observed value.
ObserveUsize
Observe/condition on a usize value.
Fields
dist: Box<dyn Distribution<usize>>Distribution that generates the observed value.
Factor
Add a log-weight factor to the model.