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

Contracts

in
{
    assert (weights.length);
    
static if (hasLength!FRange)
        assert (funcs.length == weights.length);
}

Returns

Callable structure

Parameters

funcs

input range of functions

weights

mixture weights

Example

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)));

Copyright

© 2014-2015 Ilya Yaroshenko

License

MIT

Functions

autofiniteMixtureReturns: