The OpenD Programming Language

categoricalInvCDF

Computes the Categorical inverse cumulative distribution function (InvCDF).

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

Parameters

q T

value to evaluate InvCDF

p T[]

slice containing the probability associated with the Categorical Distribution

Examples

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

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

categoricalInvCDF(0.0, p).should == 0;
categoricalInvCDF(0.1, p).should == 0;
categoricalInvCDF(0.2, p).should == 1;
categoricalInvCDF(0.3, p).should == 1;
categoricalInvCDF(0.4, p).should == 1;
categoricalInvCDF(0.5, p).should == 1;
categoricalInvCDF(0.6, p).should == 1;
categoricalInvCDF(0.7, p).should == 2;
categoricalInvCDF(0.8, p).should == 2;
categoricalInvCDF(0.9, p).should == 2;
categoricalInvCDF(1.0, p).should == 2;

Can also use dynamic array

import mir.test: should;

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

categoricalInvCDF(0.5, p).should == 1;

See Also

Meta