std

Computes the standard deviation of a slice.

  1. auto std(S slice, bool isPopulation)
    template std(sumTemplateArgs...)
    nothrow @nogc deprecated pure nothrow @nogc
    std
    (
    S
    )
    (,
    bool isPopulation = true
    )
    if (
    isSlice!S
    )
  2. auto std(S slice, Seed seed, bool isPopulation)

Members

Functions

std
deprecated auto std(S slice, bool isPopulation)
std
deprecated auto std(S slice, Seed seed, bool isPopulation)
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 & variance of the slice)

Examples

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

See Also

$(MATHREF sum, sum)

Meta