moment

Computes the n-th central moment of a slice.

  1. auto moment(S slice, Order order)
    template moment(sumTemplateArgs...)
    nothrow @nogc pure nothrow @nogc
    moment
    (
    S
    Order
    )
    (,
    in Order order
    )
    if (
    isSlice!S
    )
  2. auto moment(S slice, Order order, Seed seed)

Members

Functions

moment
auto moment(S slice, Order order)
moment
deprecated auto moment(S slice, Order order, Seed seed)
Undocumented in source. Be warned that the author may not have intended to support it.

Parameters

sumTemplateArgs

template arguments to pass to mir.math.sum (to compute the mean of the slice and the relevant moment)

Examples

2nd central moment of vector

import std.math : approxEqual;
import mir.ndslice.slice : sliced;

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];

// FIXME assert(approxEqual(x.sliced.moment(2), 54.76563 / 12));
assert(approxEqual(x.sliced.moment(2.0), 54.76563 / 12));

2nd central moment 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];

assert(approxEqual(x.sliced(2, 6).moment(2.0), 54.76563 / 12));

Row 2nd central moment of matrix

import mir.ndslice.slice : sliced;
import mir.ndslice.topology : byDim, alongDim, map;
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 y = [2.092014, 6.722222];

// Use byDim or alongDim with map to compute moment of row/column.
assert(approxEqual(x.sliced(2, 6).byDim!0.map!(a => a.moment(2.0)), y.sliced));
assert(approxEqual(x.sliced(2, 6).alongDim!1.map!(a => a.moment(2.0)), y.sliced));

See Also

$(MATHREF sum, sum)

Meta