Function smartnoise_runtime::components::covariance::matrix_cross_covariance [−][src]
pub fn matrix_cross_covariance(
left: &ArrayD<Float>,
right: &ArrayD<Float>,
delta_degrees_of_freedom: usize
) -> Result<ArrayD<Float>>
Construct cross-covariance matrix from pair of data matrices.
Element (i,j) of the cross-covariance matrix will be the covariance of the
column i of left
and column j
of right
Arguments
left
- One of the two matrices for which you want the cross-covariance matrix.right
- One of the two matrices for which you want the cross-covariance matrix.delta_degrees_of_freedom
- 0 for population, 1 for finite sample correction
Return
Full cross-covariance matrix.
Example
use ndarray::{ArrayD, arr2}; use smartnoise_runtime::components::covariance::matrix_cross_covariance; let left = arr2(&[ [1., 3., 5.,], [2., 4., 6.] ]).into_dyn(); let right = arr2(&[ [2., 4., 6.], [1., 3., 5.] ]).into_dyn(); let cross_covar = matrix_cross_covariance(&left, &right, 1).unwrap(); let left_covar = matrix_cross_covariance(&left, &left, 1).unwrap(); // cross-covariance of left and right matrices assert_eq!(cross_covar, arr2(&[ [-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5] ]).into_dyn()); // cross-covariance of left with itself is equivalent to the standard covariance matrix assert_eq!(left_covar, arr2(&[ [0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5] ]).into_dyn());