Skip to content

Commit

Permalink
Merge pull request #18 from devmotion/patch-1
Browse files Browse the repository at this point in the history
Prepare handling of truncated distribution for changes in Distributions
  • Loading branch information
pranay-gundam authored Jul 9, 2024
2 parents 3c8e6eb + 74b42a6 commit 74178a9
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/distributions_ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,16 @@ Thanks, dude!
"""
function truncmean(Dist::Truncated)
F(x) = x*pdf(Dist,x)
y = 0.0;

lower, upper = extrema(Dist)
if typeof(Dist) <: ContinuousDistribution # Continuous distribution
y = quadgk(F, Dist.lower, Dist.upper)[1]

y = quadgk(F, lower, upper)[1]
else # Discrete distriubtion
x = ceil(Dist.lower)
x = ceil(lower)
q_max = 1 - 1E-9;
x_max = min(Dist.upper, quantile(Dist.untruncated, q_max))

while x < x_max
x_max = min(upper, quantile(Dist.untruncated, q_max))
y = F(x)
while (x += 1) <= x_max
y += F(x)
x += 1
end
end
return y
Expand Down

0 comments on commit 74178a9

Please sign in to comment.