Params a = input slice
Params a = input slice b = scaling factor slice for exp(a) must have the same shape to b
template arguments to pass to mir.math.sum (to compute the mean & standard deviation of the slice)
// logsumexp example from doctest https://github.com/scipy/scipy/blob/maintenance/1.0.x/scipy/special/_logsumexp.py import mir.ndslice : iota, map, sliced, as; import mir.math.common : log, exp; import mir.math.sum; import std.math : approxEqual; { auto x = iota(10).as!double; assert(logsumexp(x).approxEqual(9.4586297444267107)); assert(log(sum(map!exp(x))).approxEqual(logsumexp(x))); } { auto x = iota(0).as!double; assert(sum(x) == 0); assert(logsumexp(x) == -double.infinity); assert(log(sum(map!exp(x))).approxEqual(logsumexp(x))); } { auto a = iota(10).as!double; auto b = iota([10], 10, -1).as!double; assert(logsumexp(a, b).approxEqual(9.9170178533034665)); assert(log(sum(map!exp(a) * b)).approxEqual(logsumexp(a, b))); } { auto a = iota(0).as!double; auto b = iota(0).as!double; assert(logsumexp(a, b) == -double.infinity); assert(log(sum(map!exp(a) * b)).approxEqual(logsumexp(a, b))); }
Computes the log of the sum of exponentials of input elements.