From 9c0bf5b3b7831bd4ad6cd943b1139bdcb7514692 Mon Sep 17 00:00:00 2001 From: Jonas Koziorek Date: Sat, 8 Jun 2024 20:26:51 +0200 Subject: [PATCH 1/3] test typo --- test/periodicity/davidchacklai.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/periodicity/davidchacklai.jl b/test/periodicity/davidchacklai.jl index 290ae908..06bf9831 100644 --- a/test/periodicity/davidchacklai.jl +++ b/test/periodicity/davidchacklai.jl @@ -40,7 +40,7 @@ end sort!(fps[3]) fps[3] = [round.(x, digits=7) for x in fps[3]] @test length(fps[3]) == 5 - @test isapprox(SVector(0.0), fps[1][1]; atol = tol) + @test isapprox(SVector(0.0), fps[3][1]; atol = tol) @test isapprox(SVector(0.1599288), fps[3][2]; atol = tol) @test isapprox(SVector(0.5143553), fps[3][3]; atol = tol) @test isapprox(SVector(0.7387961), fps[3][4]; atol = tol) From bbc3b04acba2f3ae761dfd54d969874756053e47 Mon Sep 17 00:00:00 2001 From: Jonas Koziorek Date: Sat, 8 Jun 2024 21:09:48 +0200 Subject: [PATCH 2/3] changing upo data structure --- src/ChaosTools.jl | 2 +- src/periodicity/custombintree.jl | 57 ---------------------------- src/periodicity/davidchacklai.jl | 14 +++---- src/periodicity/periodicorbits.jl | 8 ++-- src/periodicity/upo_datastructure.jl | 12 ++++++ 5 files changed, 24 insertions(+), 69 deletions(-) delete mode 100644 src/periodicity/custombintree.jl create mode 100644 src/periodicity/upo_datastructure.jl diff --git a/src/ChaosTools.jl b/src/ChaosTools.jl index a59bb4e1..713e9bc9 100644 --- a/src/ChaosTools.jl +++ b/src/ChaosTools.jl @@ -18,7 +18,7 @@ include("dimreduction/dyca.jl") include("stability/fixedpoints.jl") include("periodicity/period.jl") include("periodicity/yin.jl") -include("periodicity/custombintree.jl") +include("periodicity/upo_datastructure.jl") include("periodicity/lambdamatrix.jl") include("periodicity/periodicorbits.jl") include("periodicity/davidchacklai.jl") diff --git a/src/periodicity/custombintree.jl b/src/periodicity/custombintree.jl deleted file mode 100644 index d47a8d46..00000000 --- a/src/periodicity/custombintree.jl +++ /dev/null @@ -1,57 +0,0 @@ -using DataStructures: RBTree, search_node -import Base: <, == - -# This structure is used to overload the behavior of < and == for the use in a binary tree. -# This way binary tree will store inserted values only if they are at least `eps` away from each other. -# For example if the root is 0.0 and `eps` is 1.0 then 1.1 will be stored as a child on the right. -# However, 0.9 won't be stored because it is in the `eps` neighborhood of 0.0. -struct VectorWithEpsRadius{T} - value::T - eps::Float64 -end - -function <(a::VectorWithEpsRadius, b::VectorWithEpsRadius) - abs_diff = norm(a.value - b.value) - return abs_diff > a.eps && a.value < b.value -end - -function ==(a::VectorWithEpsRadius, b::VectorWithEpsRadius) - return norm(a.value - b.value) <= a.eps -end - -function tovector(tree::RBTree{VectorWithEpsRadius{T}}) where T - len = length(tree) - type = typeof(tree).parameters[1].parameters[1] - vect = Vector{type}(undef, len) - index = 1 - _tovector!(tree.root, vect, index) - return vect -end - -function _tovector!(node, vect::Vector{T}, index::Int64) where T - if !isnothing(node.data) - index = _tovector!(node.leftChild, vect, index) - vect[index] = node.data.value - index += 1 - index = _tovector!(node.rightChild, vect, index) - end - return index -end - -# gererates datastructure for storing fixed points -function fpcollection(type) - # Binary tree is used for fast insertion and searching of fixed points. - # VectorWithEpsRadius wrapper ensures that each point in the binary - # tree is at least `abstol` away from each other. This eliminated duplicate - # fixed points in the output. - collection = RBTree{VectorWithEpsRadius{type}}() - return collection -end - -function storefp!(collection, fp, abstol) - push!(collection, VectorWithEpsRadius{typeof(fp)}(fp, abstol)) -end - -function previously_detected(tree, fp, abstol) - return !isnothing(search_node(tree, VectorWithEpsRadius{typeof(fp)}(fp, abstol)).data) -end \ No newline at end of file diff --git a/src/periodicity/davidchacklai.jl b/src/periodicity/davidchacklai.jl index a69bc475..fe1f0e67 100644 --- a/src/periodicity/davidchacklai.jl +++ b/src/periodicity/davidchacklai.jl @@ -157,7 +157,7 @@ end function detect_orbits( - fps::RBTree{VectorWithEpsRadius{T}}, + fps::Set{T}, ds::DeterministicIteratedMap, n::Integer, seed::AbstractVector{D}, @@ -171,16 +171,16 @@ function detect_orbits( end function detect_orbits( - fps::RBTree{VectorWithEpsRadius{T}}, + fps::Set{T}, ds::DeterministicIteratedMap, n::Integer, - seed::RBTree{VectorWithEpsRadius{T}}, + seed::Set{T}, β, C_matrices; kwargs... ) where {T} for C in C_matrices - _detect_orbits!(fps, ds, n, tovector(seed), C, β; kwargs...) + _detect_orbits!(fps, ds, n, collect(seed), C, β; kwargs...) end end @@ -204,15 +204,15 @@ end function output(fps, type, n) output = Vector{Vector{type}}(undef, n) for i in 1:n # not including periodic orbit n+1 because it may be incomplete - output[i] = tovector(fps[i]) + output[i] = collect(fps[i]) end return output end function storage(type, n) - storage = Vector{RBTree{VectorWithEpsRadius{type}}}(undef, n+1) + storage = Vector{Set{type}}(undef, n+1) for i in 1:n+1 - storage[i] = fpcollection(type) + storage[i] = Set{type}() end return storage end \ No newline at end of file diff --git a/src/periodicity/periodicorbits.jl b/src/periodicity/periodicorbits.jl index 66dfc4e1..7bd17ea7 100644 --- a/src/periodicity/periodicorbits.jl +++ b/src/periodicity/periodicorbits.jl @@ -73,12 +73,12 @@ function periodicorbits( end type = typeof(current_state(ds)) - FP = fpcollection(type) + FP = Set{type}() for λ in λs, inds in indss, sings in singss Λ = lambdamatrix(λ, inds, sings) _periodicorbits!(FP, ds, o, ics, Λ, maxiters, disttol, inftol, abstol) end - return Dataset(tovector(FP)) + return Dataset(collect(FP)) end function periodicorbits( @@ -96,10 +96,10 @@ function periodicorbits( end type = typeof(current_state(ds)) - FP = fpcollection(type) + FP = Set{type}() Λ = lambdamatrix(0.001, dimension(ds)) _periodicorbits!(FP, ds, o, ics, Λ, maxiters, disttol, inftol, abstol) - return Dataset(tovector(FP)) + return Dataset(collect(FP)) end function _periodicorbits!(FP, ds, o, ics, Λ, maxiter, disttol, inftol, abstol) diff --git a/src/periodicity/upo_datastructure.jl b/src/periodicity/upo_datastructure.jl new file mode 100644 index 00000000..14e7a13a --- /dev/null +++ b/src/periodicity/upo_datastructure.jl @@ -0,0 +1,12 @@ +function storefp!(set, fp, abstol) + previously_detected(set, fp, abstol) ? nothing : push!(set, fp) +end + +function previously_detected(set, fp, abstol) + for elem in set + if norm(fp - elem) <= abstol + return true + end + end + return false +end \ No newline at end of file From b95d95573f670f9ab5b784c775bb4390a815b2bc Mon Sep 17 00:00:00 2001 From: Jonas Koziorek Date: Mon, 10 Jun 2024 18:55:17 +0200 Subject: [PATCH 3/3] renaming upo to po --- src/ChaosTools.jl | 2 +- src/periodicity/{upo_datastructure.jl => po_datastructure.jl} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/periodicity/{upo_datastructure.jl => po_datastructure.jl} (100%) diff --git a/src/ChaosTools.jl b/src/ChaosTools.jl index 713e9bc9..8012283e 100644 --- a/src/ChaosTools.jl +++ b/src/ChaosTools.jl @@ -18,7 +18,7 @@ include("dimreduction/dyca.jl") include("stability/fixedpoints.jl") include("periodicity/period.jl") include("periodicity/yin.jl") -include("periodicity/upo_datastructure.jl") +include("periodicity/po_datastructure.jl") include("periodicity/lambdamatrix.jl") include("periodicity/periodicorbits.jl") include("periodicity/davidchacklai.jl") diff --git a/src/periodicity/upo_datastructure.jl b/src/periodicity/po_datastructure.jl similarity index 100% rename from src/periodicity/upo_datastructure.jl rename to src/periodicity/po_datastructure.jl