Skip to content

Repository files navigation

LogStatFunctions.jl

CI Documentation (stable) Documentation (dev) codecov

Numerically stable logarithms of the mean, variance, and standard deviation of exponentials.

Given an array A, these compute log-of-a-statistic-of-exp.(A) without ever forming exp.(A) (which would overflow for large entries):

function computes
logmeanexp(A; dims=:) log.(mean(exp.(A); dims))
logvarexp(A; dims=:, corrected=true) log.(var(exp.(A); dims, corrected))
logstdexp(A; dims=:, corrected=true) log.(std(exp.(A); dims, corrected))
using LogStatFunctions

A = 1000 .* randn(10^4)      # exp.(A) would overflow Float64
logmeanexp(A)                # finite and accurate
logstdexp(A; corrected=false)

logvarexp and logstdexp also accept logmean to reuse a precomputed logmeanexp(A; dims).

About

Numerically stable log(mean(exp(x))), log(var(exp(x))), log(std(exp(x)))

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages