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

Function pearson_corr

crates/openquant/src/feature_importance.rs:414–435  ·  view source on GitHub ↗
(x: &[f64], y: &[f64])

Source from the content-addressed store, hash-verified

412}
413
414fn pearson_corr(x: &[f64], y: &[f64]) -> f64 {
415 if x.len() != y.len() || x.is_empty() {
416 return 0.0;
417 }
418 let mx = x.iter().sum::<f64>() / x.len() as f64;
419 let my = y.iter().sum::<f64>() / y.len() as f64;
420 let mut num = 0.0;
421 let mut vx = 0.0;
422 let mut vy = 0.0;
423 for i in 0..x.len() {
424 let dx = x[i] - mx;
425 let dy = y[i] - my;
426 num += dx * dy;
427 vx += dx * dx;
428 vy += dy * dy;
429 }
430 if vx == 0.0 || vy == 0.0 {
431 0.0
432 } else {
433 num / (vx.sqrt() * vy.sqrt())
434 }
435}
436
437fn rank_desc(values: &[f64]) -> Vec<usize> {
438 let mut idx: Vec<usize> = (0..values.len()).collect();

Callers 2

feature_pca_analysisFunction · 0.70
spearman_corrFunction · 0.70

Calls 2

lenMethod · 0.80
is_emptyMethod · 0.80

Tested by

no test coverage detected