-
Notifications
You must be signed in to change notification settings - Fork 0
/
ballmapper.qmd
63 lines (40 loc) · 2.26 KB
/
ballmapper.qmd
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
# Ball mapper
## The Vietoris-Rips complex
Another way to reduce the complexity of a metric space is to approximate it by a [simplicial complex](https://en.wikipedia.org/wiki/Simplicial_complex). Simplicial complexes are like small building blocks glued together, each of these blocks a small representative of an $n$-dimensional space: points, line segments, triangles, tetrahedrons, and so on.
The [Vietoris-Rips complex](https://en.wikipedia.org/wiki/Vietoris%E2%80%93Rips_complex) is build as follows: given a metric space $(X, d)$ and an $\epsilon > 0$, define the following simplicial complex:
$$
VR(X, \epsilon) = \{ [ x_1, \ldots, x_n ] \; d(x_i, x_j) < \epsilon, \forall i, j \}
$$
that is: the points of $X$ are our vertices, and we have an $n$-simplex $[x_1, \ldots, x_n]$ whenever the pairwise distance between $x_1, \ldots, x_n$ is less than $\epsilon$. This condition is equivalent to ask that
$$
\cap_i B(x_i, \epsilon) \neq \emptyset
$$
where $B(x, \epsilon)$ is the ball of center $x$ and radius $\epsilon$.
![The black dots are points in a metric space; the pink circles are $\epsilon$ balls around the points; in green, we have the Vietoris-Rips complex. Source: https://www.researchgate.net/publication/331739415_Topological_data_analysis_for_the_string_landscape
](images/vr.png)
## The ball mapper
The ball mapper is clearly inspired by the Vietoris-Rips complex. Given a metric space $(X, d)$ with $X = \{x_1, \ldots, x_n\}$, select a subset of indexes $L \subseteq \{1, \ldots, n\}$ and define the ball mapper graph G as follows: the set of vertices of $G$ is $L$, and set of edges $E$ given by
$$
(i, j) \in E \Leftrightarrow B(x_i, \epsilon) \cap B(x_j, \epsilon) \neq \emptyset
$$
The ball mapper then can be seen as the 1-skeleton of the Vietoris-Rips, but create using balls whose center can only be the elements indexed by $L$.
To exemplify, consider a circle
```{julia}
using TDAmapper
import GeometricDatasets as gd
X = gd.sphere(1000, dim = 2);
```
Check that it is indeed a circle:
```{julia}
using CairoMakie
scatter(X)
```
Now take $L$ as a hundred random points and let's create the ball mapper of $X$ with radius $\epsilon = 0.1$:
```{julia}
L = rand(1:1000, 100)
mp = ball_mapper(X, L, ϵ = 0.5);
```
```{julia}
mapper_plot(mp)
```
That's quite a circle!