The OpenD Programming Language

categoricalLPMF

Computes the Categorical log probability mass function (LPMF).

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

Parameters

x size_t

value to evaluate LPMF

p Slice!(Iterator, 1, kind)

slice containing the probability associated with the Categorical Distribution

Examples

import mir.math.common: log;
import mir.ndslice.slice: sliced;
import mir.test: shouldApprox;

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

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

Can also use dynamic array

import mir.math.common: log;
import mir.test: shouldApprox;

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

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

See Also

Meta