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

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] ]);