Skip to content

Commit 5b387cf

Browse files
committed
Minor fix in Quantile transform
1 parent 56917f6 commit 5b387cf

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/distributions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ EmpiricalDistribution(values) = EmpiricalDistribution{eltype(values)}(values)
2020

2121
quantile(d::EmpiricalDistribution, p::Real) = quantile(d.values, p, sorted=true)
2222

23-
function cdf(d::EmpiricalDistribution{T}, x::T) where {T}
23+
function cdf(d::EmpiricalDistribution, x)
2424
v = d.values
2525
n = length(v)
2626

@@ -37,9 +37,9 @@ function cdf(d::EmpiricalDistribution{T}, x::T) where {T}
3737
l, u = v[head], v[tail]
3838

3939
if x < l
40-
return T(0)
40+
return 0.0
4141
elseif x > u
42-
return T(1)
42+
return 1.0
4343
else
4444
if l == u
4545
return tail / n

src/transforms/quantile.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ end
6666
# transform samples from original to target distribution
6767
function qtransform(samples, origin, target)
6868
# avoid evaluating the quantile at 0 or 1
69-
T = eltype(samples)
70-
pmin = T(0) + T(1e-3)
71-
pmax = T(1) - T(1e-3)
69+
pmin = 0.0 + 1e-3
70+
pmax = 1.0 - 1e-3
7271
map(samples) do sample
7372
prob = cdf(origin, sample)
7473
quantile(target, clamp(prob, pmin, pmax))

0 commit comments

Comments
 (0)