Skip to content

Commit

Permalink
make mean(::Chi) more robust (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 authored Apr 20, 2021
1 parent df5aee3 commit 093e876
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/univariate/continuous/chi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ params(d::Chi) = (d.ν,)

#### Statistics

mean(d::Chi) = (h = d.ν/2; sqrt2 * gamma(h + 1//2) / gamma(h))
mean(d::Chi) = (h = d.ν/2; sqrt2 * exp(loggamma(h + 1//2) - loggamma(h)))

var(d::Chi) = d.ν - mean(d)^2
_chi_skewness::Real, σ::Real) = (σ2 = σ^2; σ3 = σ2 * σ; (μ / σ3) * (1 - 2σ2))
Expand Down
2 changes: 2 additions & 0 deletions test/chi.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# see #1305
@test isfinite(mean(Chi(1000)))
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const tests = [
"bernoulli",
"soliton",
"skewnormal",
"chi",
]

printstyled("Running tests:\n", color=:blue)
Expand Down

0 comments on commit 093e876

Please sign in to comment.