/
test.py
79 lines (68 loc) · 2.89 KB
/
test.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import matplotlib.pyplot as pyplot
import generators.poisson
import generators.matern
import generators.thomas
import geom.vert
import geom.persistence.filtration
import geom.persistence.persistence
import triangle
import numpy as np
def get_persistence(points):
"""
Вычисление диаграммы персистентности для 1-циклов по набору точек.
Строится фильтрация Чеха, по которой вычисляется диаграмма персистентности.
:param points: список точек из R^2
:return:
"""
f = geom.persistence.filtration.Filtration(points)
pers = geom.persistence.persistence.Persistence(f)
return pers
def test_easy():
points = [[1.0, 2.0, 2.0, 5.0, 9.0, 10.0, -1.0], [1.0, 1.0, 2.0, 7.0, 11.0, 11.0, 8.0]]
d = triangle.delaunay([(points[0][i], points[1][i]) for i in range(len(points[0]))])
diagram = get_persistence([[points[0][i], points[1][i]] for i in range(len(points[0]))]).get_diagram()
print(diagram)
pyplot.scatter(points[0], points[1], marker='o')
pyplot.triplot(points[0], points[1], d)
pyplot.show()
def test_hard():
points = generators.poisson.poisson_homogeneous_point_process(1, 50)
d = triangle.delaunay(points)
diagram = get_persistence(points).get_diagram()
pyplot.figure(1)
pyplot.triplot([points[i][0] for i in range(len(points))], [points[i][1] for i in range(len(points))], d)
pyplot.figure(2)
pyplot.scatter([diagram[i][0] for i in range(len(diagram))], [diagram[i][1] for i in range(len(diagram))], marker='o')
pyplot.show()
tim = []
for i in range(2):
points = generators.poisson.poisson_homogeneous_point_process(1, 5000)
d = triangle.delaunay(points)
pers = get_persistence(points)
#pyplot.figure(1)
pyplot.plot(range(len(pers.numOfComponents)), pers.numOfComponents, '-b',
range(len(pers.numOfBigComponents)), pers.numOfBigComponents, '-r',
range(len(pers.numOfCycles)), pers.numOfCycles, '-g',)
#pyplot.show()
b_1 = max(pers.numOfCycles)
n_a = max(pers.numOfBigComponents)
tim.append(b_1 / n_a)
print(np.mean(tim))
print(np.sqrt(np.var(tim)))
tim.clear()
for i in range(2):
points = generators.matern.matern_point_process(280, 0.05, 17, 1)
print(len(points))
d = triangle.delaunay(points)
pers = get_persistence(points)
#pyplot.figure(1)
pyplot.plot(range(len(pers.numOfComponents)), pers.numOfComponents, '--b',
range(len(pers.numOfBigComponents)), pers.numOfBigComponents, '--r',
range(len(pers.numOfCycles)), pers.numOfCycles, '--g',)
#pyplot.show()
b_1 = max(pers.numOfCycles)
n_a = max(pers.numOfBigComponents)
tim.append(b_1 / n_a)
pyplot.show()
print(np.mean(tim))
print(np.sqrt(np.var(tim)))