Skip to content

Commit 70c4ab0

Browse files
authored
Faster normal cdf encoding (#399)
* Remove QuadGK, add StatsFuns instead For computing normal cdf * QuadGK is still needed for Schurmann estimator
1 parent eed8b71 commit 70c4ab0

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "ComplexityMeasures"
22
uuid = "ab4b797d-85ee-42ba-b621-05d793b346a2"
33
authors = "Kristian Agasøster Haaga <kahaaga@gmail.com>, George Datseries <datseris.george@gmail.com>"
44
repo = "https://github.com/juliadynamics/ComplexityMeasures.jl.git"
5-
version = "3.4.2"
5+
version = "3.4.3"
66

77
[deps]
88
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
@@ -20,6 +20,7 @@ StateSpaceSets = "40b095a5-5852-4c12-98c7-d43bf788e795"
2020
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2121
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2222
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
23+
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
2324
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"
2425

2526
[compat]
@@ -28,12 +29,13 @@ DelayEmbeddings = "2.6"
2829
Distances = "0.9, 0.10"
2930
FFTW = "1"
3031
Neighborhood = "0.2.4"
31-
QuadGK = "2"
32+
QuadGK = "2.9"
3233
Reexport = "1"
3334
SpecialFunctions = "0.10, 1.0, 2"
3435
StateSpaceSets = "1.0.4"
3536
StaticArrays = "0.12, 1.0"
3637
Statistics = "1"
3738
StatsBase = "0.33, 0.34"
39+
StatsFuns = "1.3"
3840
Wavelets = "0.10"
3941
julia = "1.5"

src/encoding_implementations/gaussian_cdf.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Statistics, QuadGK
1+
using Statistics
2+
using StatsFuns: normcdf
23

34
export GaussianCDFEncoding
45

@@ -120,15 +121,9 @@ end
120121
gaussian(x, μ, σ) = exp((-(x - μ)^2)/(2σ^2))
121122

122123
function encode(encoding::GaussianCDFEncoding, x::Real)
123-
σ, μ = encoding.σ, encoding.μ
124-
# We only need the value of the integral (not the error), so
125-
# index first element returned from quadgk
126-
k = 1/*sqrt(2π))
127-
y = k * first(quadgk(x -> gaussian(x, μ, σ), -Inf, x))
128-
# The integral estimate sometime returns a value slightly above 1.0, so we need
129-
# to adjust to be sure that all points fall within the FixedRectangularBinning.
130-
y_corrected = min(y, 1.0)
131-
return encode(encoding.binencoder, y_corrected)
124+
binencoder, σ, μ = encoding.binencoder, encoding.σ, encoding.μ
125+
126+
return encode(binencoder, normcdf(μ, σ, x))
132127
end
133128

134129
function encode(encoding::GaussianCDFEncoding{m}, x::AbstractVector) where m

0 commit comments

Comments
 (0)