causal_hub/estimators/parameters/bayesian/table/
mixed.rs1use crate::{
2 estimators::{BE, CPDEstimator, ParCPDEstimator},
3 models::{MixedCPD, MixedIncTable, MixedTable, MixedWtdTable},
4 types::Set,
5};
6
7macro_rules! impl_be_for_mixed {
8 ($enum:ident) => {
9 impl CPDEstimator<MixedCPD> for BE<'_, $enum, ()> {
10 fn fit(&self, x: &Set<usize>, z: &Set<usize>) -> crate::types::Result<MixedCPD> {
11 match self.dataset {
12 $enum::Categorical(t) => BE::new(t)
13 .with_missing_method(self.missing_method, self.missing_mechanism.clone())?
14 .fit(x, z)
15 .map(MixedCPD::Categorical),
16 $enum::Gaussian(t) => BE::new(t)
17 .with_missing_method(self.missing_method, self.missing_mechanism.clone())?
18 .fit(x, z)
19 .map(MixedCPD::Gaussian),
20 }
21 }
22 }
23 impl ParCPDEstimator<MixedCPD> for BE<'_, $enum, ()> {
24 fn par_fit(&self, x: &Set<usize>, z: &Set<usize>) -> crate::types::Result<MixedCPD> {
25 match self.dataset {
26 $enum::Categorical(t) => BE::new(t)
27 .with_missing_method(self.missing_method, self.missing_mechanism.clone())?
28 .par_fit(x, z)
29 .map(MixedCPD::Categorical),
30 $enum::Gaussian(t) => BE::new(t)
31 .with_missing_method(self.missing_method, self.missing_mechanism.clone())?
32 .par_fit(x, z)
33 .map(MixedCPD::Gaussian),
34 }
35 }
36 }
37 };
38}
39
40impl_be_for_mixed!(MixedTable);
41impl_be_for_mixed!(MixedIncTable);
42impl_be_for_mixed!(MixedWtdTable);