(
predictor: F,
x: &[Vec<f64>],
num_values: usize,
pairwise_combinations: Option<&[(usize, usize)]>,
)
| 125 | ]; |
| 126 | if let Some(p) = pair { |
| 127 | lines.push(format!("pairwise:{} pairs", p.raw.len())); |
| 128 | } |
| 129 | Ok(lines) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | fn fit_impl<F>( |
| 134 | predictor: F, |
| 135 | x: &[Vec<f64>], |
| 136 | num_values: usize, |
| 137 | pairwise_combinations: Option<&[(usize, usize)]>, |
| 138 | ) -> Result<(Effect, Effect, Option<PairwiseEffect>), FingerprintError> |
| 139 | where |
| 140 | F: Fn(&[Vec<f64>]) -> Vec<f64>, |
| 141 | { |
| 142 | if x.is_empty() { |
| 143 | return Err(FingerprintError::Empty("x")); |
| 144 | } |
| 145 | if num_values < 2 { |
| 146 | return Err(FingerprintError::Invalid { name: "num_values", requirement: ">= 2" }); |
| 147 | } |
| 148 | let n_features = x[0].len(); |
| 149 | if n_features == 0 { |
| 150 | return Err(FingerprintError::NoFeatures); |
| 151 | } |
| 152 | if x.iter().any(|r| r.len() != n_features) { |
| 153 | return Err(FingerprintError::RaggedX); |
| 154 | } |
| 155 | |
| 156 | let feature_values = get_feature_values(x, num_values); |
| 157 | let partial_dep = get_individual_partial_dependence(&predictor, x, &feature_values); |
| 158 | let linear_raw = get_linear_effect(&feature_values, &partial_dep); |
| 159 | let nonlin_raw = get_non_linear_effect(&feature_values, &partial_dep); |
| 160 | let linear = Effect { norm: normalize_usize_map(&linear_raw), raw: linear_raw }; |
| 161 | let non_linear = Effect { norm: normalize_usize_map(&nonlin_raw), raw: nonlin_raw }; |
| 162 | |
| 163 | let pair = pairwise_combinations.map(|pairs| { |
| 164 | let raw = |
| 165 | get_pairwise_effect(pairs, &predictor, x, num_values, &feature_values, &partial_dep); |
| 166 | PairwiseEffect { norm: normalize_string_map(&raw), raw } |
| 167 | }); |
no test coverage detected