finiteMixture

finiteMixture
(
FRange
T
)
(
FRange funcs
,
const(T)[] weights
)
if (
isForwardRange!FRange &&
isCallable!(ElementType!FRange)
&&
isFloatingPoint!T
)
in { assert (weights.length); static if (hasLength!FRange) assert (funcs.length == weights.length); }

Parameters

funcs
Type: FRange

input range of functions

weights
Type: const(T)[]

mixture weights

Return Value

Type: auto

Callable structure

Examples

1 import std.algorithm : map;
2 import std.range : sequence;
3 import atmosphere.pdf;
4 import atmosphere.utilities;
5 auto pdfs = sequence!"n+1"().map!(shape => GammaSPDF!real(shape, 1));
6 double[] weights = [0.25, 0.5, 0.125, 0.125];
7 auto pdf0 = finiteMixture(pdfs, weights);           //struct
8 auto pdf1 = finiteMixture(pdfs[3..4].chain(pdfs[0..3]), [0.125, 0.25, 0.5, 0.125]); //struct
9 PDF!double pdf2 = toPDF(pdf0);                      //object
10 foreach(x; iota(1, 4))
11 	assert(approxEqual(pdf1(x), pdf2(x)));

Meta