Skip to content

Commit

Permalink
Computing distances between two empty PersistenceDiagrams (#54)
Browse files Browse the repository at this point in the history
* Added unit test for distances between two empty persistence diagrams

* Distances between empty persistence diagrams return zero instantaneously

* Update test/matching.jl

Co-authored-by: mtsch <matijacufar@gmail.com>

* Update src/matching.jl

Co-authored-by: mtsch <matijacufar@gmail.com>

* Update src/matching.jl

Co-authored-by: mtsch <matijacufar@gmail.com>

Co-authored-by: mtsch <matijacufar@gmail.com>
  • Loading branch information
mbudisic and mtsch authored Nov 26, 2022
1 parent e761e58 commit 73ba367
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/matching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ function (::Bottleneck)(left::PersistenceDiagram, right::PersistenceDiagram; mat
end
end

if length(left) == 0 & length(right) == 0
if matching
return Matching(left, right, 0, Pair{Int,Int}[], true)
else
return 0.0
end
end

graph = BottleneckGraph(left, right)
edges = graph.edges

Expand Down Expand Up @@ -494,6 +502,15 @@ end
function (w::Wasserstein)(
left::PersistenceDiagram, right::PersistenceDiagram; matching=false
)

if length(left) == 0 & length(right) == 0
if matching
return Matching(left, right, 0, Pair{Int,Int}[], false)
else
return 0.0
end
end

if count(!isfinite, left) == count(!isfinite, right)
adj = _adjacency_matrix(right, left, w.q)
match = collect(i => j for (i, j) in enumerate(hungarian(adj)[1]))
Expand Down
8 changes: 8 additions & 0 deletions test/matching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ end
@test weight(Wasserstein(), diag1, diag1) 0.0
end

@testset "Empty diagrams" begin
diag = PersistenceDiagram([])

@test Wasserstein()(diag,diag; matching = false) 0.0
@test Bottleneck()(diag,diag; matching = false) 0.0

end

@testset "Infinite intervals" begin
diag1 = PersistenceDiagram([(1, 2), (5, 8), (1, Inf)])
diag2 = PersistenceDiagram([(1, 2), (3, 4), (5, 10)])
Expand Down

0 comments on commit 73ba367

Please sign in to comment.