1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Already finished the implementation of "sampleable distribution". The implement has commented out.

use crate::{Distribution, SampleableDistribution};
use rand::prelude::*;
use std::ops::Range;

#[derive(Clone, Debug)]
pub struct ContinuousUniform;

/// p returns the constant multiplied value so it can be used only for MCMC.
impl Distribution for ContinuousUniform {
    type Value = f64;
    type Condition = Range<f64>;

    fn p_kernel(
        &self,
        _: &Self::Value,
        _theta: &Self::Condition,
    ) -> Result<f64, crate::DistributionError> {
        Ok(1.0)
    }
}

impl SampleableDistribution for ContinuousUniform {
    fn sample(
        &self,
        theta: &Self::Condition,
        rng: &mut dyn RngCore,
    ) -> Result<Self::Value, crate::DistributionError> {
        Ok(rng.gen_range(theta.clone()))
    }
}