Skip to content

Conversation

@elavallee
Copy link
Contributor

Please review my change to add a threshold to the PowerSpectrum estimator. The optional threshold is named: $\delta$. I updated the docstring, and I was able to pass all the tests locally. However, I did not add any new tests, which is more challenging. For an example of how to use the new feature, please see the code below.
`

using DynamicalSystems, ComplexityMeasures

N1, N2, a = 101, 100001, 10

for N in (N1, N2)
    println("N: $(N)")
    t = LinRange(0, 2*a*π, N)
    x = sin.(t) # periodic
    y = sin.(t .+ cos.(t/0.5)) # periodic, complex spectrum
    z = sin.(rand(1:15, N) ./ rand(1:10, N)) # random
    w, t = trajectory(Systems.lorenz(), N÷10; Δt = 0.1, Ttr = 100) # chaotic
    w    = w[:, 1]

    for q in (x, y, z, w)
        p, ~ = probabilities_and_outcomes(PowerSpectrum(100.0), q)
        h = entropy(p)
        println("entropy: $(h).")
    end
end

that adds a threshold for "small" amplitudes.

See Issue JuliaDynamics#104.
feature.

* Changed the default threshold from 5.0 to 0.0

* Renamed y to amp_squared to make it more clear

* Vectorized the setting of amplitudes to zero
Copy link
Member

@Datseris Datseris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some simplifying and performance comments

if !(x isa AbstractVector{<:Real})
throw(ArgumentError("`PowerSpectrum` only works for timeseries input!"))
end
δ = getfield.(Ref(P), (:δ))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
δ = getfield.(Ref(P), (:δ))

f = FFTW.rfft(x)
probs = Probabilities(abs2.(f))
amp_squared = abs2.(f)
amp_squared[0.0 .< amp_squared .< δ] .= 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
amp_squared[0.0 .< amp_squared .< δ] .= 0.0
if P.δ > 0
amp_squared[amp_squared .< P.δ] .= 0.0
end

@Datseris
Copy link
Member

Datseris commented Jan 9, 2026

Thanks for the PR @elavallee , in addition please increment the minor version (middle number) at Project.toml file by 1 and add an entry about this change in the CHANGELOG.md file!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants