Function smartnoise_runtime::components::covariance::matrix_covariance [−][src]
pub fn matrix_covariance(
data: &ArrayD<Float>,
delta_degrees_of_freedom: usize
) -> Result<Vec<Vec<Float>>>
Construct upper triangular of covariance matrix from data matrix.
Arguments
data
- Data for which you want covariance matrix.delta_degrees_of_freedom
- 0 for population, 1 for finite sample correction
Return
Upper triangular of covariance matrix of your data.
Example
use ndarray::{ArrayD, arr2}; use smartnoise_runtime::components::covariance::matrix_covariance; // covariance matrix is: // [12.5 7.5 -7.5] // [ 7.5 4.5 -4.5] // [-7.5 -4.5 4.5] let data = arr2(&[ [0., 2., 9.], [5., 5., 6.] ]).into_dyn(); let cov_mat = matrix_covariance(&data, 1).unwrap(); assert_eq!(cov_mat, vec![ vec![12.5, 7.5, -7.5], vec![4.5, -4.5], vec![4.5] ]);