Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimization 1st pass include the following modifications:
Changes made
src/distributions/Power.jl — Direct closed-form math
Replaced delegation through Beta(κ, 1) wrapper with direct formulas: cdf = x^κ, logpdf = log(κ) + (κ-1)log(x), quantile = p^(1/κ), rand = u^(1/κ). Also added a specialized logcdf = κ·log(x).
src/distributions/TruncatedNormal.jl — Cached underlying distribution
The Truncated(Normal(...)) wrapper was being recreated on every pdf/cdf/quantile/rand call. Now precomputed once at construction and stored in a _dist field.
src/distributions/TruncatedBeta.jl — Same caching strategy
The LocationScale(Truncated(Beta(...))) triple-nested wrapper is now built once at construction.
src/distributions/ExtendedGeneralizedPareto.jl — @inline hints + logcdf
Added @inline on hot methods and a specialized logcdf that avoids log(cdf(...)).
src/parameterestimation.jl — Allocation-free hot loop
Replaced sum(logpdf.(pd, y⁺)) (allocates temp array) with an explicit @inbounds loop
Avoids constructing EGP in the uncensored path — uses V and G directly
Replaced count(y .< threshold) (allocates BitArray) with count(v -> v < threshold, y)
Used expm1(ν) for better numerics
Construction of TNormal/TBeta is slower (they now precompute the cached distribution), but this is amortized away by the dramatic speedups on all subsequent operations.
Optimization 2nd pass - MVector include the following changes:
Changes made
MVector{3} for Optim.jl: The optimizer initial point is now MVector(ν₀, ϕ₀, ξ₀) instead of [ν₀, ϕ₀, ξ₀]. The fixed size lets the compiler unroll simplex operations and avoids dynamic-size array overhead. (SVector isn't compatible with Optim v1.13.3's use of fill!.)
_gp_cdf_logpdf fused helper: Both cdf(GP, x) and logpdf(GP, x) internally compute z = 1 + ξ·x/σ and log(z). The new helper computes both in a single pass, eliminating the redundant computation per data point per optimizer iteration.
log(σ) = ϕ identity: Since σ = exp(ϕ), we skip computing log(σ) entirely.
Allocations dropped from 1,420 → 588 (58% fewer) and 34.2 KiB → 19.2 KiB (44% less memory).
src/distributions/TruncatedNormal.jl & TruncatedBeta.jl — added logcdf delegates
src/ExtendedExtremes.jl — added StaticArrays dependency
Results vs previous round (additional speedups)
Cumulative results vs original code