using ToMATo
import GeometricDatasets as gd
using AlgebraOfGraphics
using Makie
Examples
Let’s play with some datasets and choices of the parameter \(\tau\) and the proximity graph \(g\).
Load some packages
Two normals in the plane
Define \(X\) as the union of two normal distributions
= hcat(randn(2, 800), randn(2, 800) .+ 4)
X = x -> exp(-(x / 2)^2)
k = gd.Filters.density(X, kernel_function = X -> X .|> k |> sum)
ds
= (x1 = X[1, :], x2 = X[2, :], ds = ds)
df = data(df) * mapping(:x1, :x2, color = :ds)
plt draw(plt)
Create its proximity graph
= proximity_graph(X, 0.2, max_k_ball = 6, k_nn = 4, min_k_ball = 2)
g
= graph_plot(X, g, ds)
fig, ax, plt fig
┌ Warning: Axis got passed, but also axis attributes. Ignoring axis attributes (type = Axis, width = 600, height = 600).
└ @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/yhdjr/src/draw.jl:19
and plot its 0-dimensional persistence diagram
= tomato(X, g, ds, Inf)
_clusters_, births_and_deaths plot_births_and_deaths(births_and_deaths)
Setting \(\tau\) to 0.1 seems a good choice.
= 0.1
τ = tomato(X, g, ds, τ, max_cluster_height = τ)
clusters, births_and_deaths
= graph_plot(X, g, clusters .|> string)
fig, ax, plt fig
┌ Warning: Axis got passed, but also axis attributes. Ignoring axis attributes (type = Axis, width = 600, height = 600).
└ @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/yhdjr/src/draw.jl:19
Three normals in the plane
= hcat(randn(2, 500), randn(2, 500) .+ 4, randn(2, 600) .*0.8 .+ (-3, 3))
X = x -> exp(-(x)^2)
k = gd.Filters.density(X, kernel_function = X -> X .|> k |> sum)
ds
= (x1 = X[1, :], x2 = X[2, :], ds = ds)
df = data(df) * mapping(:x1, :x2, color = :ds)
plt draw(plt)
= proximity_graph(X, 0.2, max_k_ball = 10, k_nn = 5, min_k_ball = 5)
g
= graph_plot(X, g, ds)
fig, ax, plt fig
┌ Warning: Axis got passed, but also axis attributes. Ignoring axis attributes (type = Axis, width = 600, height = 600).
└ @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/yhdjr/src/draw.jl:19
= tomato(X, g, ds, Inf)
_, births_and_deaths plot_births_and_deaths(births_and_deaths)
= 0.05
τ = tomato(X, g, ds, τ, max_cluster_height = τ)
clusters, _
= graph_plot(X, g, clusters .|> string)
fig, ax, plt fig
┌ Warning: Axis got passed, but also axis attributes. Ignoring axis attributes (type = Axis, width = 600, height = 600).
└ @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/yhdjr/src/draw.jl:19
Two normals in \(\mathbb{R}^3\)
= hcat(randn(3, 800), randn(3, 800) .+ 4)
X = x -> exp(-(x / 2)^2)
k = gd.Filters.density(X, kernel_function = X -> X .|> k |> sum)
ds
= proximity_graph(X, 0.2, max_k_ball = 10, k_nn = 5, min_k_ball = 4)
g = graph_plot(X, g, ds)
fig, ax, plt fig
┌ Warning: Axis got passed, but also axis attributes. Ignoring axis attributes (type = Axis3, width = 600, height = 600).
└ @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/yhdjr/src/draw.jl:19
= tomato(X, g, ds, Inf)
_, births_and_deaths plot_births_and_deaths(births_and_deaths)
= 0.1
τ = tomato(X, g, ds, τ, max_cluster_height = τ)
clusters, _
= graph_plot(X, g, clusters .|> string)
fig, ax, plt fig
┌ Warning: Axis got passed, but also axis attributes. Ignoring axis attributes (type = Axis3, width = 600, height = 600).
└ @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/yhdjr/src/draw.jl:19
Three normals in \(\mathbb{R}^3\)
= hcat(randn(3, 800), randn(3, 800) .+ 4, randn(3, 1000) .+ (3, -3, 3))
X = x -> exp(-(x / 2)^2)
k = gd.Filters.density(X, kernel_function = X -> X .|> k |> sum)
ds
= (type = Axis3, width = 600, height = 600)
axis = (x1 = X[1, :], x2 = X[2, :], x3 = X[3, :], ds = ds)
df = data(df) * mapping(:x1, :x2, :x3, color = :ds)
plt draw(plt, axis = axis)
= proximity_graph(X, 0.2, max_k_ball = 10, k_nn = 5, min_k_ball = 5)
g
= graph_plot(X, g, ds)
fig, ax, plt fig
┌ Warning: Axis got passed, but also axis attributes. Ignoring axis attributes (type = Axis3, width = 600, height = 600).
└ @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/yhdjr/src/draw.jl:19
= tomato(X, g, ds, Inf)
_, births_and_deaths plot_births_and_deaths(births_and_deaths)
= 0.05
τ = tomato(X, g, ds, τ, max_cluster_height = τ)
clusters, _
= graph_plot(X, g, clusters .|> string)
fig, ax, plt fig
┌ Warning: Axis got passed, but also axis attributes. Ignoring axis attributes (type = Axis3, width = 600, height = 600).
└ @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/yhdjr/src/draw.jl:19