push
travis-ci
1 of 1 new or added line in 1 file covered. (100.0%)
1249 of 2001 relevant lines covered (62.42%)
183705.98 hits per line
1 |
# Empirical estimation of CDF and PDF |
|
2 |
|
|
3 |
|
|
4 |
## Empirical CDF |
|
5 |
""" |
|
6 |
ecdf(X) |
|
7 |
|
|
8 |
Return an empirical cumulative distribution function (ECDF) based on a vector of samples |
|
9 |
given in `X`. |
|
10 |
|
|
11 |
Note: this is a higher-level function that returns a function, which can then be applied |
|
12 |
to evaluate CDF values on other samples. |
|
13 |
""" |
|
14 |
function ecdf(X::RealVector{T}) where T<:Real |
|
15 |
Xs = sort(X) |
8✔ |
16 |
n = length(X) |
× |
17 |
|
|
18 |
ef(x::Real) = searchsortedlast(Xs, x) / n |
66✔ |
19 |
|
|
20 |
function ef(v::RealVector) |
× |
21 |
ord = sortperm(v) |
12✔ |
22 |
m = length(v) |
× |
23 |
r = Vector{T}(undef, m) |
× |
24 |
r0 = 0
|
× |
25 |
|
|
26 |
i = 1
|
× |
27 |
for x in Xs
|
12✔ |
28 |
while i <= m && x > v[ord[i]]
|
117,026,120✔ |
29 |
r[ord[i]] = r0 |
× |
30 |
i += 1
|
10,036✔ |
31 |
end |
|
32 |
r0 += 1
|
× |
33 |
if i > m
|
38,998,672✔ |
34 |
break
|
38,998,672✔ |
35 |
end |
|
36 |
end |
|
37 |
while i <= m
|
20,012✔ |
38 |
r[ord[i]] = n |
10,000✔ |
39 |
i += 1
|
10,000✔ |
40 |
end |
|
41 |
return r / n
|
12✔ |
42 |
end |
|
43 |
|
|
44 |
return ef
|
4✔ |
45 |
end |
|
46 |
|
|
47 |
|