The OpenD Programming Language

categoricalPMF

Computes the Categorical probability mass function (PMF).

  1. elementType!(Slice!(Iterator, 1, kind)) categoricalPMF(size_t x, Slice!(Iterator, 1, kind) p)
    @safe pure nothrow @nogc
    elementType!(Slice!(Iterator, 1, kind))
    categoricalPMF
    (
    Iterator
    SliceKind kind
    )
    (
    const size_t x
    ,
    scope const Slice!(Iterator, 1, kind) p
    )
    if (
    isFloatingPoint!(elementType!(Slice!(Iterator, 1, kind)))
    )
  2. T categoricalPMF(size_t x, T[] p)

Parameters

x size_t

value to evaluate PMF

p Slice!(Iterator, 1, kind)

slice containing the probability associated with the Categorical Distribution

Examples

import mir.ndslice.slice: sliced;
import mir.test: shouldApprox;

static immutable x = [0.1, 0.5, 0.4];
auto p = x.sliced;

0.categoricalPMF(p).shouldApprox == 0.1;
1.categoricalPMF(p).shouldApprox == 0.5;
2.categoricalPMF(p).shouldApprox == 0.4;

Can also use dynamic array

import mir.test: shouldApprox;

double[] p = [0.1, 0.5, 0.4];

0.categoricalPMF(p).shouldApprox == 0.1;
1.categoricalPMF(p).shouldApprox == 0.5;
2.categoricalPMF(p).shouldApprox == 0.4;
import mir.math.sum: sum;
import mir.ndslice.slice: sliced;
import mir.test: shouldApprox;

static immutable x = [1.0, 5, 4];
auto p = x.sliced;
auto q = p / sum(p);

0.categoricalPMF(q).shouldApprox == 0.1;
1.categoricalPMF(q).shouldApprox == 0.5;
2.categoricalPMF(q).shouldApprox == 0.4;

See Also

Meta