template arguments to pass to mir.math.sum (to compute the mean & variance of the slice)
Standard deviation of vector
import std.math : approxEqual; import mir.ndslice.slice : sliced; import mir.math.common : sqrt; 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]; assert(approxEqual(x.sliced.std, sqrt(54.76563 / 12))); assert(approxEqual(x.sliced.std(false), sqrt(54.76563 / 11))); assert(approxEqual(x.sliced.std(true), sqrt(54.76563 / 12)));
Standard deviation of matrix
import mir.ndslice.slice : sliced; import std.math : approxEqual; import mir.math.common : sqrt; 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]; assert(approxEqual(x.sliced(2, 6).std, sqrt(54.76563 / 12))); assert(approxEqual(x.sliced(2, 6).std(false), sqrt(54.76563 / 11))); assert(approxEqual(x.sliced(2, 6).std(true), sqrt(54.76563 / 12)));
Row standard deviation of matrix
import mir.ndslice.slice : sliced; import mir.ndslice.topology : alongDim, byDim, map; import mir.math.common : sqrt; import numir : 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 y = [sqrt(2.092014), sqrt(6.722222)]; // Use byDim or alongDim or alongDim with map to compute variance of row/column. assert(approxEqual(x.sliced(2, 6).byDim!0.map!(a => a.std(true)), y.sliced)); assert(approxEqual(x.sliced(2, 6).alongDim!1.map!(a => a.std(true)), y.sliced));
$(MATHREF sum, sum)
Computes the standard deviation of a slice.