use ferric::make_model;
#[test]
fn rejection_sampling_deterministic_observation() {
make_model! {
name det_obs_reject;
use ferric::distributions::Bernoulli;
let x : bool ~ Bernoulli::new(0.5);
let two_x : u8 = 2u8 * x as u8;
observe two_x;
query x;
};
let model = det_obs_reject::Model { two_x: 2 };
let num_samples = 1000;
for s in model.sample_iter().take(num_samples) {
assert!(s.x, "x must be true when two_x is observed to be 2");
}
}
#[test]
fn weighted_sampling_deterministic_query() {
make_model! {
name det_query_weighted;
use ferric::distributions::Bernoulli;
let x : bool ~ Bernoulli::new(0.5);
let two_x : u8 = 2u8 * x as u8;
observe x;
query two_x;
};
let model = det_query_weighted::Model { x: true };
let num_samples = 1000;
for ws in model.weighted_sample_iter().take(num_samples) {
assert_eq!(
ws.sample.two_x, 2,
"two_x must be 2 when x is observed to be true"
);
}
}