geometric mean of slice
Geometric mean of vector
import mir.ndslice.slice : sliced; import std.math : approxEqual; static immutable x = [1.1, 0.99, 1.01, 1.2, 0.9, 1.05]; auto y = x.sliced.gmean; assert(approxEqual(y, 1.037513));
Geometric mean of matrix
import mir.ndslice.slice : sliced; import std.math : approxEqual; static immutable x = [1.1, 0.99, 1.01, 1.2, 0.9, 1.05]; auto y = x.sliced(2, 3).gmean; assert(approxEqual(y, 1.037513));
Column geometric mean of matrix
import mir.ndslice.slice : sliced; import mir.ndslice.topology : alongDim, byDim, map; import numir : approxEqual; static immutable x = [1.1, 0.99, 1.01, 1.2, 0.9, 1.05]; static immutable y = [1.148913, 0.943928, 1.029806]; // Use byDim or alongDim with map to compute mean of row/column. assert(approxEqual(x.sliced(2, 3).byDim!1.map!gmean, y.sliced)); assert(approxEqual(x.sliced(2, 3).alongDim!0.map!gmean, y.sliced));
Geometric mean of vector with seed
import mir.ndslice.slice : sliced; import std.math : approxEqual; enum l = 2.0 ^^ (double.max_exp - 1); enum s = 2.0 ^^ -(double.max_exp - 1); static immutable x = [l, l, l, s, s, s, 0.8 * 2.0 ^^ 10]; real seed = 1; auto y = x.sliced.gmean(seed); assert(approxEqual(y, (0.8 * 2.0 ^^ 10) ^^ (1.0 / 7.0)));
Computes the geometric mean of a slice.