Skip to content

Commit

Permalink
Faster normal cdf encoding (#399)
Browse files Browse the repository at this point in the history
* Remove QuadGK, add StatsFuns instead

For computing normal cdf

* QuadGK is still needed for Schurmann estimator
  • Loading branch information
kahaaga authored Apr 7, 2024
1 parent eed8b71 commit 70c4ab0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "ComplexityMeasures"
uuid = "ab4b797d-85ee-42ba-b621-05d793b346a2"
authors = "Kristian Agasøster Haaga <[email protected]>, George Datseries <[email protected]>"
repo = "https://github.com/juliadynamics/ComplexityMeasures.jl.git"
version = "3.4.2"
version = "3.4.3"

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

[compat]
Expand All @@ -28,12 +29,13 @@ DelayEmbeddings = "2.6"
Distances = "0.9, 0.10"
FFTW = "1"
Neighborhood = "0.2.4"
QuadGK = "2"
QuadGK = "2.9"
Reexport = "1"
SpecialFunctions = "0.10, 1.0, 2"
StateSpaceSets = "1.0.4"
StaticArrays = "0.12, 1.0"
Statistics = "1"
StatsBase = "0.33, 0.34"
StatsFuns = "1.3"
Wavelets = "0.10"
julia = "1.5"
15 changes: 5 additions & 10 deletions src/encoding_implementations/gaussian_cdf.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Statistics, QuadGK
using Statistics
using StatsFuns: normcdf

export GaussianCDFEncoding

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

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

return encode(binencoder, normcdf(μ, σ, x))
end

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

0 comments on commit 70c4ab0

Please sign in to comment.