Skip to content

Local correlation dimension #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.9

- New function `local_correlation_dimension`.
- Functions that were already exported as public are now also in the documentation:
`pointwise_dimensions, pointwise_correlationsums`

# 1.8

- New way to estimate extreme value theory dimensions based on block maxima.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FractalDimensions"
uuid = "4665ce21-e117-4649-aed8-08bbe5ccbead"
authors = ["George Datseris <datseris.george@gmail.com>", "Ignacio Del Amo <@PythagoreanCult>", "Anton P Braun"]
version = "1.8.2"
version = "1.9.0"

[deps]
ComplexityMeasures = "ab4b797d-85ee-42ba-b621-05d793b346a2"
Expand Down
14 changes: 14 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ The whole above pipeline we went through is bundled in [`grassberger_proccacia_d
They are more like convenient bundles with on-average good defaults, rather than precise functions. You should be careful
when considering the validity of the returned number!


## Index (contents)

```@index
```

## Linear scaling regions

```@docs
Expand Down Expand Up @@ -145,6 +151,14 @@ fixedmass_correlationsum
takens_best_estimate_dim
```

## Pointwise (local) correlation dimensions

```@docs
pointwise_dimensions
local_correlation_dimension
```


## Kaplan-Yorke dimension

```@docs
Expand Down
51 changes: 48 additions & 3 deletions src/corrsum_based/correlationsum_vanilla.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Distances: evaluate, Euclidean, pairwise, Metric

export correlationsum, boxed_correlationsum
export grassberger_proccacia_dim
export pointwise_dimensions, pointwise_correlationsums
export pointwise_dimensions, pointwise_correlationsums, local_correlation_dimension

"""
grassberger_proccacia_dim(X::AbstractStateSpaceSet, εs = estimate_boxsizes(data); kwargs...)
Expand Down Expand Up @@ -163,7 +163,7 @@ versus ``\\epsilon``. `Δloc[i]` is the exponential scaling (deduced by a call t

Keywords are the same as in [`correlationsum`](@ref).
To obtain the inner correlation sums without doing the exponential scaling fit
use `pointwise_correlationsums`.
use `FractalDimensions.pointwise_correlationsums` with same inputs.
"""
function pointwise_dimensions(X, εs::AbstractVector = estimate_boxsizes(X); kw...)
Cs = pointwise_correlationsums(X, εs; kw...)
Expand Down Expand Up @@ -218,4 +218,49 @@ end
out[j+lr1] = norm(v, X[ξ])
end
return out
end
end

"""
local_correlation_dimension(X, ζ [, εs]; kw...) → Δ_ζ

Return the local dimension `Δ_ζ` around state space point `ζ` given a set of state space
points `X` which is assumed to surround (or be sufficiently near to) `ζ`.
The local dimension is the exponential scaling of the correlation sum for point `ζ` versus
some radii `εs`. `εs` can be a vector of reals, or it can be an integer,
in which space that many points are equi-spaced logarithmically between the minimum and
maximum distance of `X` to `ζ`.

## Keyword arguments

- `q = 2, norm = Euclidean()`: same as in [`correlationsum`](@ref).
- `fit = LinearRegression()`: given to [`slopefit`](@ref) to estimate the dimension.
This default assumes that the set `X` is already sufficiently close to `ζ`.
"""
function local_correlation_dimension(args...; fit = LinearRegression(), kw...)
C, es = local_correlation_sum(args...; kw...)
ΔGP = slopefit(log2.(es), log2.(C), fit)[1]
return ΔGP
end

function local_correlation_sum(X, ζ, k = 8; norm = Euclidean(), q = 2)
# First estimate distances
dists = map(x -> norm(x, ζ), X)
εs = _generate_boxsizes(k, dists)
C = zeros(Int, length(εs))
# Then convert to correlation sum
for i in eachindex(εs)
C[i] = count(<(εs[i]), dists)^(q-1)
end
return C/length(dists), εs
end

function _generate_boxsizes(k::Int, dists)
dmax = maximum(dists)
dmin = partialsort!(dists, 2) # second smallest
base = MathConstants.e
lower = log(base, dmin)
upper = log(base, dmax)
return float(base) .^ range(lower, upper; length = k)
end

_generate_boxisizes(es::AbstractVector, dists) = es
8 changes: 8 additions & 0 deletions test/correlationdim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,11 @@ end
@test all(c -> c[end] > 0, Csums)

end

@testset "local corrsum dimension" begin
rng = Xoshiro(1234)
F = [0.5rand(rng, 2) .+ [0.25, 0.25] for _ in 1:10_000]
z = SVector(0.5, 0.5)
d = local_correlation_dimension(F, z)
test_value(d, 1.9, 2.1)
end
Loading