-
Notifications
You must be signed in to change notification settings - Fork 0
/
clustering.jl
64 lines (41 loc) · 1.3 KB
/
clustering.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using ToMATo
import GeometricDatasets as gd
using AlgebraOfGraphics
# usar distance to measure aqui?
X = hcat(randn(2, 800), randn(2, 800) .* 0.8 .+ 4, randn(2, 100) .* 0.3 .- 2)
k = x -> exp(-(x / 0.8)^2)
ds = gd.density_estimation(X, h = 0.5)
# ds = gd.distance_to_measure(X, k = 1500)
# ds .= maximum(ds) .- ds
df = (x1 = X[1, :], x2 = X[2, :], ds = ds)
plt = data(df) * mapping(:x1, :x2)
draw(plt)
df = (x1 = X[1, :], x2 = X[2, :], ds = ds)
plt = data(df) * mapping(:x1, :x2, color = :ds)
draw(plt)
g = proximity_graph(X, 0.2, max_k_ball = 6, k_nn = 4, min_k_ball = 2)
fig, ax, plt = graph_plot(X, g, ds)
fig
X2 = vcat(X, ds')
fig, ax, plt = graph_plot(X2, g, ds)
fig
clusters, births_and_deaths = tomato(X, g, ds, 0)
plot_births_and_deaths(births_and_deaths)
fig, ax, plt = graph_plot(X, g, clusters .|> string)
fig
fig, ax, plt = graph_plot(X2, g, clusters .|> string)
fig
τ = 0.02
clusters, _ = tomato(X, g, ds, τ, max_cluster_height = τ)
df = (x1 = X[1, :], x2 = X[2, :], ds = clusters .|> string)
plt = data(df) * mapping(:x1, :x2, color = :ds)
draw(plt)
fig, ax, plt = graph_plot(X, g, clusters .|> string)
fig
fig, ax, plt = graph_plot(X2, g, clusters .|> string)
fig
# datasets
using DelimitedFiles
X = readdlm("clustering datasets/spiral with density.txt") |>
transpose |>
collect