fdars_core/explain/
ale_lime.rs1use crate::error::FdarError;
4use crate::matrix::FdMatrix;
5use crate::scalar_on_function::{FregreLmResult, FunctionalLogisticResult};
6
7#[derive(Debug, Clone, PartialEq)]
13#[non_exhaustive]
14pub struct AleResult {
15 pub bin_midpoints: Vec<f64>,
17 pub ale_values: Vec<f64>,
19 pub bin_edges: Vec<f64>,
21 pub bin_counts: Vec<usize>,
23 pub component: usize,
25}
26
27#[must_use = "expensive computation whose result should not be discarded"]
36pub fn fpc_ale(
37 fit: &FregreLmResult,
38 data: &FdMatrix,
39 scalar_covariates: Option<&FdMatrix>,
40 component: usize,
41 n_bins: usize,
42) -> Result<AleResult, FdarError> {
43 crate::explain_generic::generic_ale(fit, data, scalar_covariates, component, n_bins)
44}
45
46#[must_use = "expensive computation whose result should not be discarded"]
52pub fn fpc_ale_logistic(
53 fit: &FunctionalLogisticResult,
54 data: &FdMatrix,
55 scalar_covariates: Option<&FdMatrix>,
56 component: usize,
57 n_bins: usize,
58) -> Result<AleResult, FdarError> {
59 crate::explain_generic::generic_ale(fit, data, scalar_covariates, component, n_bins)
60}
61
62#[derive(Debug, Clone, PartialEq)]
68#[non_exhaustive]
69pub struct LimeResult {
70 pub observation: usize,
72 pub attributions: Vec<f64>,
74 pub local_intercept: f64,
76 pub local_r_squared: f64,
78 pub kernel_width: f64,
80}
81
82#[must_use = "expensive computation whose result should not be discarded"]
88pub fn lime_explanation(
89 fit: &FregreLmResult,
90 data: &FdMatrix,
91 scalar_covariates: Option<&FdMatrix>,
92 observation: usize,
93 n_samples: usize,
94 kernel_width: f64,
95 seed: u64,
96) -> Result<LimeResult, FdarError> {
97 crate::explain_generic::generic_lime(
98 fit,
99 data,
100 scalar_covariates,
101 observation,
102 n_samples,
103 kernel_width,
104 seed,
105 )
106}
107
108#[must_use = "expensive computation whose result should not be discarded"]
114pub fn lime_explanation_logistic(
115 fit: &FunctionalLogisticResult,
116 data: &FdMatrix,
117 scalar_covariates: Option<&FdMatrix>,
118 observation: usize,
119 n_samples: usize,
120 kernel_width: f64,
121 seed: u64,
122) -> Result<LimeResult, FdarError> {
123 crate::explain_generic::generic_lime(
124 fit,
125 data,
126 scalar_covariates,
127 observation,
128 n_samples,
129 kernel_width,
130 seed,
131 )
132}