use crate::{
datasets::{CatIncTable, IncDataset, MissingMethod},
estimators::{CSSEstimator, ParCSSEstimator, SSE},
models::{CatCPDS, Labelled},
types::{Result, Set},
};
impl CSSEstimator<CatCPDS> for SSE<'_, CatIncTable> {
fn fit(&self, x: &Set<usize>, z: &Set<usize>) -> Result<CatCPDS> {
let x_z = Some(&(x | z));
let m = self.missing_method.as_ref().unwrap_or(&MissingMethod::PW);
let r = self.missing_mechanism.as_ref();
let d = self.dataset.apply_missing_method(m, x_z, r)?;
let labels = self.dataset.labels();
let x = d.indices_from(x, labels)?;
let z = d.indices_from(z, labels)?;
d.map_either(
|d| SSE::new(&d).fit(&x, &z), |d| SSE::new(&d).fit(&x, &z), )
.into_inner()
}
}
impl ParCSSEstimator<CatCPDS> for SSE<'_, CatIncTable> {
fn par_fit(&self, x: &Set<usize>, z: &Set<usize>) -> Result<CatCPDS> {
let x_z = Some(&(x | z));
let m = self.missing_method.as_ref().unwrap_or(&MissingMethod::PW);
let r = self.missing_mechanism.as_ref();
let d = self.dataset.apply_missing_method(m, x_z, r)?;
let labels = self.dataset.labels();
let x = d.indices_from(x, labels)?;
let z = d.indices_from(z, labels)?;
d.map_either(
|d| SSE::new(&d).par_fit(&x, &z), |d| SSE::new(&d).par_fit(&x, &z), )
.into_inner()
}
}