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
use crate::nonparametric::{DiscreteMeasurableSpace, DiscreteMeasure};
use crate::RandomVariable;
#[derive(Clone, Debug)]
pub struct DirichletRandomMeasure<T>
where
T: RandomVariable,
{
w_theta: Vec<(f64, T)>,
}
impl<T> DiscreteMeasure for DirichletRandomMeasure<T>
where
T: RandomVariable,
{
fn measure(&self, a: DiscreteMeasurableSpace) -> f64 {
a.iter().map(|&i| self.w_theta[i].0).sum::<f64>()
}
}
impl<T> DirichletRandomMeasure<T>
where
T: RandomVariable,
{
pub fn new(w_theta: Vec<(f64, T)>) -> Self {
Self { w_theta }
}
pub fn w_theta(&self) -> &Vec<(f64, T)> {
&self.w_theta
}
}