import mir.stat.transform: center; import mir.math.sum: Summation; import mir.ndslice.slice: sliced; import mir.test: shouldApprox; auto a = [ 0.0, 1.0, 1.5, 2.0, 3.5, 4.25, 2.0, 7.5, 5.0, 1.0, 1.5, 0.0].sliced; auto b = [-0.75, 6.0, -0.25, 8.25, 5.75, 3.5, 9.25, -0.75, 2.5, 1.25, -1, 2.25].sliced; auto x = a.center; auto y = b.center; CovarianceAccumulator!(double, CovarianceAlgo.assumeZeroMean, Summation.naive) v; v.put(x, y); v.covariance(true).shouldApprox == -5.5 / 12; v.covariance(false).shouldApprox == -5.5 / 11; v.put(4.0, 3.0); v.covariance(true).shouldApprox == 6.5 / 13; v.covariance(false).shouldApprox == 6.5 / 12;