template arguments to pass to mir.math.sum (to compute the mean & standard deviation of the slice)
Z-score of vector
import mir.ndslice.slice : sliced; import std.math : approxEqual; static immutable x = [0.0, 1.0, 1.5, 2.0, 3.5, 4.25, 2.0, 7.5, 5.0, 1.0, 1.5, 0.0]; static immutable resultSample = [-1.09241, -0.64424, -0.42016, -0.19607, 0.47618, 0.812307, -0.19607, 2.268858, 1.148434, -0.64424, -0.42016, -1.09241]; static immutable resultPop = [-1.14099, -0.67289, -0.43884, -0.20479, 0.497354, 0.848427, -0.20479, 2.369745, 1.199501, -0.67289, -0.43884, -1.14099]; assert(approxEqual(x.sliced.zscore, resultPop.sliced)); assert(approxEqual(x.sliced.zscore(false), resultSample.sliced)); assert(approxEqual(x.sliced.zscore(true), resultPop.sliced));
Z-score of matrix
import mir.ndslice.slice : sliced; import std.math : approxEqual; static immutable x = [0.0, 1.0, 1.5, 2.0, 3.5, 4.25, 2.0, 7.5, 5.0, 1.0, 1.5, 0.0]; static immutable _resultSample = [-1.09241, -0.64424, -0.42016, -0.19607, 0.47618, 0.812307, -0.19607, 2.268858, 1.148434, -0.64424, -0.42016, -1.09241]; auto resultSample = _resultSample.sliced(2, 6); static immutable _resultPop = [-1.14099, -0.67289, -0.43884, -0.20479, 0.497354, 0.848427, -0.20479, 2.369745, 1.199501, -0.67289, -0.43884, -1.14099]; auto resultPop = _resultPop.sliced(2, 6); auto y1 = x.sliced(2, 6).zscore; assert(approxEqual(y1[0], resultPop[0])); assert(approxEqual(y1[1], resultPop[1])); auto y2 = x.sliced(2, 6).zscore(false); assert(approxEqual(y2[0], resultSample[0])); assert(approxEqual(y2[1], resultSample[1])); auto y3 = x.sliced(2, 6).zscore(true); assert(approxEqual(y3[0], resultPop[0])); assert(approxEqual(y3[1], resultPop[1]));
$(MATHREF sum, sum)
Computes the zscore of a slice.