cov

Covariance matrix.

Slice!(BlasType!Iterator*, 2)
cov
(
Iterator
SliceKind kind
)
(
Slice!(Iterator, 2, kind) matrix
)

Parameters

matrix Slice!(Iterator, 2, kind)

matrix whose rows represent observations and whose columns represent random variables.

Return Value

Type: Slice!(BlasType!Iterator*, 2)

Normalized by N-1 covariance matrix.

Examples

import mir.ndslice;

import std.stdio;
import mir.ndslice;

auto c = 8.magic[0..$-1].cov;

auto result = [
     350.0000, -340.6667, -331.3333,  322.0000,  312.6667, -303.3333, -294.0000,  284.6667,
    -340.6667,  332.4762,  324.2857, -316.0952, -307.9048,  299.7143,  291.5238, -283.3333,
    -331.3333,  324.2857,  317.2381, -310.1905, -303.1429,  296.0952,  289.0476, -282.0000,
     322.0000, -316.0952, -310.1905,  304.2857,  298.3810, -292.4762, -286.5714,  280.6667,
     312.6667, -307.9048, -303.1429,  298.3810,  293.6190, -288.8571, -284.0952,  279.3333,
    -303.3333,  299.7143,  296.0952, -292.4762, -288.8571,  285.2381,  281.6190, -278.0000,
    -294.0000,  291.5238,  289.0476, -286.5714, -284.0952,  281.6190,  279.1429, -276.6667,
     284.6667, -283.3333, -282.0000,  280.6667,  279.3333, -278.0000, -276.6667,  275.3333].sliced(8, 8);
import mir.math.common: approxEqual;
import mir.algorithm.iteration: all;
assert(c.all!((a, b) => approxEqual(a, b, 1e-5, 1e-5))(result));

Meta