(x: &[f64], y: &[f64])
| 412 | } |
| 413 | |
| 414 | fn 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 | |
| 437 | fn rank_desc(values: &[f64]) -> Vec<usize> { |
| 438 | let mut idx: Vec<usize> = (0..values.len()).collect(); |
no test coverage detected