From db1fc539706476a07b8f10ab8f2da20e6da38d1d Mon Sep 17 00:00:00 2001 From: mtsch Date: Thu, 19 Dec 2024 21:43:13 +1300 Subject: [PATCH 1/3] Improve perfomance of cycle reconstruction --- src/extra/cycles.jl | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/extra/cycles.jl b/src/extra/cycles.jl index 97acfcfc..3cc479e3 100644 --- a/src/extra/cycles.jl +++ b/src/extra/cycles.jl @@ -23,6 +23,10 @@ function OneSkeleton( return OneSkeleton{T,F,S,typeof(weights)}(filtration, thresh, weights, removed) end +function Graphs.SimpleGraph(g::OneSkeleton) + SimpleGraph(edges(g)) +end + _birth_or_value(σ::AbstractCell) = birth(σ) _birth_or_value(σ) = σ _in(σ::S, g::OneSkeleton{S}) where {S} = !isnothing(σ) && σ ≤ g.threshold && σ ∉ g.removed @@ -97,19 +101,21 @@ end Find the shortest cycle in `g` that has exactly one edge from `g.removed`. """ -function _find_cycle(g, dists) +function _find_cycle(skeleton, dists) # Idea: # best_weight is the current best length of shortest cycle. # best_path is the current best candidate for shortest cycle. # best_simplex completes best_path to a cycle. - # We go through all edges in g.removed and find the shortest path through its + # We go through all edges in skeleton.removed and find the shortest path through its # endpoints. The shortest among those is the shortest cycle. + graph = SimpleGraph(skeleton) + best_weight = missing - best_path = edgetype(g)[] - best_sx = first(g.removed) - for sx in g.removed - u, v = _linear.(Ref(g), sx) - path = a_star(g, u, v, dists, _heuristic(g.filtration, v, dists)) + best_path = edgetype(skeleton)[] + best_sx = first(skeleton.removed) + for sx in skeleton.removed + u, v = _linear.(Ref(skeleton), sx) + path = a_star(graph, u, v, dists, _heuristic(skeleton.filtration, v, dists)) weight = _path_length(dists, path) + dists[u, v] if !isempty(path) && isless(weight, best_weight) best_weight = weight @@ -123,8 +129,8 @@ function _find_cycle(g, dists) result = [best_sx] # Convert the type of best_path from `Edge`s to the simplex type of the filtration. for e in best_path - u, v = _inv_linear.(Ref(g), (src(e), dst(e))) - push!(result, simplex(g.filtration, Val(1), (u, v))) + u, v = _inv_linear.(Ref(skeleton), (src(e), dst(e))) + push!(result, simplex(skeleton.filtration, Val(1), (u, v))) end return result end From 6f6587ad224e860fb48738d43fad91fb10d46818 Mon Sep 17 00:00:00 2001 From: mtsch Date: Thu, 19 Dec 2024 21:43:48 +1300 Subject: [PATCH 2/3] update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 86605ebe..5b44aaa5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Ripserer" uuid = "aa79e827-bd0b-42a8-9f10-2b302677a641" authors = ["mtsch "] -version = "0.16.12" +version = "0.16.13" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" From 1a55b615a0d8634260532a9619f39f477f18de8e Mon Sep 17 00:00:00 2001 From: mtsch Date: Thu, 19 Dec 2024 21:49:49 +1300 Subject: [PATCH 3/3] Update src/extra/cycles.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/extra/cycles.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extra/cycles.jl b/src/extra/cycles.jl index 3cc479e3..f9bb0acd 100644 --- a/src/extra/cycles.jl +++ b/src/extra/cycles.jl @@ -24,7 +24,7 @@ function OneSkeleton( end function Graphs.SimpleGraph(g::OneSkeleton) - SimpleGraph(edges(g)) + return SimpleGraph(edges(g)) end _birth_or_value(σ::AbstractCell) = birth(σ)