diff --git a/Project.toml b/Project.toml index 1ce28c3..d8e2430 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PersistenceDiagramsBase" uuid = "b1ad91c1-539c-4ace-90bd-ea06abc420fa" authors = ["mtsch "] -version = "0.1.0" +version = "0.1.1" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" diff --git a/src/PersistenceDiagramsBase.jl b/src/PersistenceDiagramsBase.jl index fccd53a..8687385 100644 --- a/src/PersistenceDiagramsBase.jl +++ b/src/PersistenceDiagramsBase.jl @@ -8,6 +8,7 @@ export PersistenceDiagram, birth, death, persistence, + midlife, dim, threshold, birth_simplex, diff --git a/src/diagrams.jl b/src/diagrams.jl index dc4116e..f0d81c0 100644 --- a/src/diagrams.jl +++ b/src/diagrams.jl @@ -1,12 +1,13 @@ """ - PersistenceDiagram{P<:PersistenceInterval} <: AbstractVector{P} + PersistenceDiagram <: AbstractVector{PersistenceInterval} Type for representing persistence diagrams. Behaves exactly like a vector of -`PersistenceInterval`s, but is can have metadata attached to it and supports pretty printing -and plotting. +`PersistenceInterval`s, but can have additional metadata attached to it. It supports pretty +printing and plotting. Can be used as a table with any function that uses the -[`Tables.jl`](https://github.com/JuliaData/Tables.jl) interface. +[`Tables.jl`](https://github.com/JuliaData/Tables.jl) interface. Note that using it as a +table will only keep interval endpoints and the `dim` and `threshold` attributes. # Example diff --git a/src/intervals.jl b/src/intervals.jl index 8629cf6..efcc552 100644 --- a/src/intervals.jl +++ b/src/intervals.jl @@ -1,9 +1,9 @@ """ PersistenceInterval -The type that represents a persistence interval. It behaves exactly like a `Tuple{Float64, -Float64}`, but can have meta data attached to it. The metadata is accessible -with `getproperty`. +Type for representing persistence intervals. It behaves exactly like a `Tuple{Float64, +Float64}`, but can have meta data attached to it. The metadata is accessible with +`getproperty` or the dot syntax. # Example @@ -63,6 +63,13 @@ Get the persistence of `interval`, which is equal to `death - birth`. """ persistence(int::PersistenceInterval) = death(int) - birth(int) +""" + midlife(interval) + +Get the midlife of the `interval`, which is equal to `(birth + death) / 2`. +""" +midlife(int::PersistenceInterval) = (birth(int) + death(int)) / 2 + Base.isfinite(int::PersistenceInterval) = isfinite(death(int)) ### diff --git a/test/diagrams.jl b/test/diagrams.jl index 1c90e1e..4dd7fdf 100644 --- a/test/diagrams.jl +++ b/test/diagrams.jl @@ -36,6 +36,8 @@ using Test @test !isfinite(int2) @test persistence(int1) == 1 @test persistence(int2) == Inf + @test midlife(int1) == 1.5 + @test midlife(int2) == Inf @test eltype(int1) ≡ Float64 @test eltype(PersistenceInterval) ≡ Float64