Skip to content

Commit af14853

Browse files
committed
fix again
1 parent efc81a1 commit af14853

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

src/stats/histograms.jl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -396,29 +396,32 @@ end
396396

397397
# based on linear interpolation
398398
function pdf(o::KHist, x::Number)
399-
if x minimum(o.ex)
400-
return 0.0
401-
elseif x maximum(o.ex)
402-
return 0.0
403-
else
404-
i = searchsortedfirst(o.bins, KHistBin(x, 0)) - 1
399+
a, b = extrema(o.ex)
400+
if a < x < b
401+
i = searchsortedfirst(o.bins, KHistBin(x, 0))
405402
x1, y1 = xy(o.bins[i - 1])
406403
x2, y2 = xy(o.bins[i])
407404
return smooth(y1, y2, (x - x1) / (x2 - x1)) / area(o)
405+
else
406+
x == a && return o.bins[1].count / area(o)
407+
x == b && return o.bins[end].count / area(o)
408+
return 0.0
408409
end
409410
end
410411

411412
function cdf(o::KHist, x::Number)
412-
if x minimum(o.ex)
413-
return 0.0
414-
elseif x maximum(o.ex)
415-
return 1.0
413+
a, b = extrema(o.ex)
414+
if x < a
415+
return 0.0
416+
elseif x == a
417+
return o.bins[1].count / area(o)
418+
elseif x b
419+
return 1.0
416420
else
417-
i = searchsortedfirst(o.bins, KHistBin(x, 0)) - 1
418-
x1, y1 = o.bins[i - 1].loc, o.bins[i-1].count
419-
x2, y2 = o.bins[i].loc, o.bins[i].count
420-
w = x - x1
421+
i = searchsortedfirst(o.bins, KHistBin(x, 0))
422+
x1, y1 = xy(o.bins[i - 1])
423+
x2, y2 = xy(o.bins[i])
421424
h = smooth(y1, y2, (x2 - x) / (x2 - x1))
422-
return (area(o, i-2) + w * h) / area(o)
425+
return (area(o, i - 2) + (x - x1) * h) / area(o)
423426
end
424427
end

0 commit comments

Comments
 (0)