Skip to content

Commit

Permalink
added persistance plots
Browse files Browse the repository at this point in the history
  • Loading branch information
wildart committed Jan 4, 2019
1 parent ee0afb1 commit edfda5e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Art
Copyright (c) 2019 Art Wild

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 21 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name = "TDA"
uuid = "fe47203d-f35f-412c-997c-af2409ec39e9"
keywords = ["topological data analysis", "data science", "persistance"]
license = "MIT"
desc = "A Julia package for topological data analysis"
repository = "https://github.com/wildart/TDA.jl.git"
version = "0.1.0"

[deps]
ComputationalHomology = "9393a4d0-be1e-45b0-9991-b60434c721e6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]

8 changes: 8 additions & 0 deletions src/TDA.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module TDA

using ComputationalHomology
using RecipesBase

include("pdiag.jl")

end
64 changes: 64 additions & 0 deletions src/pdiag.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Plot intervals as a persistance diagram or barcode
@recipe function f(ints::Vector{Vector{T}}; skipzero = false) where {T<:Interval}
seriestype --> :diagram

maxval = mapreduce(l->maximum(filter(!isinf, map(i->i.d,l))), max, ints)
minval = mapreduce(l->minimum(filter(!isinf, map(i->i.b,l))), min, ints)
#col = vcat(map(l->map(i->isinf(i.d) ? :red : :auto ,l), ints)...)

if plotattributes[:seriestype] == :barcode # Persistance Barcode
xticks := minval:maxval
xlims := (minval, maxval+0.05)
yticks := nothing
ylims := (0.0, 1.05)
legend := :none
layout := (length(ints),1)
for d in 1:length(ints)
points = map(i -> i.b == i.d, ints[d])
step = 1 / (skipzero ? sum(.!points) : length(ints[d]))
y = step
for (i, ispoint) in zip(ints[d], points)
xs, ys = [i.b, isinf(i.d) ? maxval : i.d], [y, y]
println("ispoint: $ispoint")
println(!ispoint && skipzero)
ispoint && skipzero && continue
@series begin
title := "Degree $(d-1)"
linewidth --> 2
subplot := d
primary := true
arrow := isinf(i.d)
seriescolor --> :blue
seriestype := ispoint ? :scatter : :path
markersize --> 2
xs, ys
end
y += step
end
end
else # Persistance Diagram
xs = map(l->map(i->i.b,l), ints)
ys = map(l->map(i->isinf(i.d) ? maxval : i.d,l), ints)
mkr = vcat(map(l->map(i->isinf(i.d) ? :rect : :circle,l), ints)...)
legend --> :bottomright
legendtitle --> "Homology"
label --> ["Degree $(i-1)" for i in 1:length(ints)]
xticks := minval:maxval
xlims := (minval-0.3, maxval+0.3)
xlabel := "birth"
yticks := 0:maxval
ylabel := "death"
ylims := (minval, maxval+0.3)
@series begin
primary := false
seriestype := :path
linecolor := :black
[0, maxval], [0, maxval]
end

seriestype := :scatter
markershape := mkr
#markerstrokecolor := col
xs, ys
end
end

0 comments on commit edfda5e

Please sign in to comment.