finiteMixture

finiteMixture
(
FRange
T
)
(
FRange funcs
,
const(T)[] weights
)
if (
isForwardRange!FRange &&
isCallable!(ElementType!FRange)
&&
isFloatingPoint!T
)

Parameters

funcs FRange

input range of functions

weights const(T)[]

mixture weights

Return Value

Type: auto

Callable structure

Examples

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

Meta