Skip to content

Commit

Permalink
Update docs, add midlife function (#6)
Browse files Browse the repository at this point in the history
* Update docs, add midlife function

* add tests for midlife

* fix formatting
  • Loading branch information
mtsch committed Dec 11, 2020
1 parent 68e2cf9 commit 833dfb0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PersistenceDiagramsBase"
uuid = "b1ad91c1-539c-4ace-90bd-ea06abc420fa"
authors = ["mtsch <matijacufar@gmail.com>"]
version = "0.1.0"
version = "0.1.1"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
1 change: 1 addition & 0 deletions src/PersistenceDiagramsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export PersistenceDiagram,
birth,
death,
persistence,
midlife,
dim,
threshold,
birth_simplex,
Expand Down
9 changes: 5 additions & 4 deletions src/diagrams.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/intervals.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))

###
Expand Down
2 changes: 2 additions & 0 deletions test/diagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit 833dfb0

@mtsch
Copy link
Owner Author

@mtsch mtsch commented on 833dfb0 Dec 11, 2020

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/26215

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" 833dfb0d5aa32772aa6c51915f3911e9d04173e6
git push origin v0.1.1

Please sign in to comment.