MCPcopy Create free account
hub / github.com/Open-Quant/openquant / fit_impl

Function fit_impl

crates/openquant/src/fingerprint.rs:127–164  ·  view source on GitHub ↗
(
    predictor: F,
    x: &[Vec<f64>],
    num_values: usize,
    pairwise_combinations: Option<&[(usize, usize)]>,
)

Source from the content-addressed store, hash-verified

125 ];
126 if let Some(p) = pair {
127 lines.push(format!("pairwise:{} pairs", p.raw.len()));
128 }
129 Ok(lines)
130 }
131}
132
133fn 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>
139where
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 });

Callers 1

fitMethod · 0.85

Calls 9

get_feature_valuesFunction · 0.85
get_linear_effectFunction · 0.85
get_non_linear_effectFunction · 0.85
normalize_usize_mapFunction · 0.85
get_pairwise_effectFunction · 0.85
normalize_string_mapFunction · 0.85
is_emptyMethod · 0.80
lenMethod · 0.80

Tested by

no test coverage detected