The OpenD Programming Language

dstats.base

Relatively low-level primitives on which to build higher-level math/stat * functionality. Some are used internally, some are just things that may be * useful to users of this library. This module is starting to take on the * appearance of a small utility library. * * Note: In several functions in this module that return arrays, the last * parameter is an optional buffer for storing the return value. If this * parameter is ommitted or the buffer is not large enough, one will be * allocated on the GC heap. * * Author: David Simcha

Members

Classes

DstatsArgumentException
class DstatsArgumentException

This is the exception that is thrown on invalid arguments to a dstats function.

Functions

auroc
double auroc(R1 classATs, R2 classBTs)

Finds the area under the ROC curve (a curve with sensitivity on the Y-axis and 1 - specificity on the X-axis). This is a useful metric for determining how well a test statistic discriminates between two classes. The following assumptions are made in this implementation:

bin
Ret[] bin(T data, uint nbin, Ret[] buf)

Bins data into nbin equal width bins, indexed from * 0 to nbin - 1, with 0 being the smallest bin, etc. * The values returned are the bin index for each element. * * Default return type is ubyte, because in the dstats.infotheory, * entropy() and related functions specialize on ubytes, and become * substandially faster. However, if you're using more than 255 bins, * you'll have to provide a different return type as a template parameter.

binCounts
Ret[] binCounts(T data, uint nbin, Ret[] buf)

Bins data into nbin equal width bins, indexed from 0 to nbin - 1, with 0 being the smallest bin, etc. The values returned are the counts for each bin.

byCategory
ElementType!(V)[][ElementType!(C)] byCategory(V values, C categories)

Given a range of values and a range of categories, separates values by category. This function also guarantees that the order within each category will be maintained.

byCategory
ElementType!(V)[][2] byCategory(V values, C categories)

Special case implementation for when ElementType!C is boolean.

comb
auto comb(T stuff, uint r)

Create a Comb struct from a range or of a set of bounds.

frequency
uint[ForeachType!(T)] frequency(T input)

Returns an associative array of counts of every element in input. * Works w/ any iterable. * * Examples: * --- * int[] foo = [1,2,3,1,2,4]; * uintint frq = frequency(foo); * assert(frq.length == 4); * assert(frq[1] == 2); * assert(frq[4] == 1); * ---

frqBin
Ret[] frqBin(T data, uint nbin, Ret[] buf)

Bins data into nbin equal frequency bins, indexed from * 0 to nbin - 1, with 0 being the smallest bin, etc. * The values returned are the bin index for each element. * * Default return type is ubyte, because in the dstats.infotheory, * entropy() and related functions specialize on ubytes, and become * substandially faster. However, if you're using more than 256 bins, * you'll have to provide a different return type as a template parameter.

logFactorial
double logFactorial(ulong n)
logNcomb
double logNcomb(ulong n, ulong k)

Log of (n choose k).

perm
auto perm(T stuff)

Create a Perm struct from a range or of a set of bounds.

rank
Ret[] rank(T input, Ret[] buf)

Given an input array, outputs an array containing the rank from * [1, input.length] corresponding to each element. Ties are dealt with by * averaging. This function does not reorder the input range. * Return type is float[] by default, but if you are sure you have no ties, * ints can be used for efficiency (in which case ties will not be averaged), * and if you need more precision when averaging ties, you can use double or * real. * * Works with any input range. * * Examples: * --- * uint[] test = [3, 5, 3, 1, 2]; * assert(rank!("a < b", float)(test) == [3.5f, 5f, 3.5f, 1f, 2f]); * assert(test == [3U, 5, 3, 1, 2]); * ---

rankSort
Ret[] rankSort(T input, Ret[] buf)

Same as rank(), but also sorts the input range. The array returned will still be identical to that returned by rank(), i.e. the rank of each element will correspond to the ranks of the elements in the input array before sorting.

saveAll
Tuple!T saveAll(T args)

Given a tuple possibly containing forward ranges, returns a tuple where save() has been called on all forward ranges.

seq
CommonType!(T, U)[] seq(T start, U end, V increment)

Generates a sequence from start..end by increment. Includes start, excludes end. Does so eagerly as an array.

sign
T sign(T num)
toNumericRange
ToNumericRange!R toNumericRange(R rangeIn)

Converts a range with arbitrary element types (usually strings) to a range of reals lazily. Ignores any elements that could not be successfully converted. Useful for creating an input range that can be used with this lib out of a File without having to read the whole file into an array first. The advantages to this over just using std.algorithm.map are that it's less typing and that it ignores non-convertible elements, such as blank lines.

Structs

Comb
struct Comb(T)

Generates every possible combination of r elements of the given sequence, or array indices from zero to N, depending on which c'tor is called. Uses an input range interface.

Perm
struct Perm(T)

A struct that generates all possible permutations of a sequence.

ToNumericRange
struct ToNumericRange(R)

Templates

doubleInput
template doubleInput(T)

Tests whether T is an input range whose elements can be implicitly converted to doubles.

doubleIterable
template doubleIterable(T)

Tests whether T is iterable and has elements of a type implicitly * convertible to double.

Meta