-
Notifications
You must be signed in to change notification settings - Fork 3
/
geom_stat.py
89 lines (79 loc) · 2.32 KB
/
geom_stat.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
80
81
82
83
84
85
86
87
88
89
#! /usr/bin/python2
# vim: set fileencoding=utf-8
POINTS = [
[-122.381388, 37.775833],
[-122.382084, 37.7771],
[-122.382084, 37.7771],
[-122.3825, 37.777777],
[-122.382851, 37.776382],
[-122.384166, 37.776666],
[-122.381388, 37.775833],
[-122.382084, 37.7771],
[-122.382084, 37.7771],
[-122.3825, 37.777777],
[-122.382851, 37.776382],
[-122.384166, 37.776666],
[-122.381388, 37.775833],
[-122.382084, 37.7771],
[-122.382084, 37.7771],
[-122.3825, 37.777777],
[-122.382851, 37.776382],
[-122.384166, 37.776666],
[-122.381388, 37.775833],
[-122.382084, 37.7771],
[-122.382084, 37.7771],
[-122.3825, 37.777777],
[-122.382851, 37.776382],
[-122.384166, 37.776666],
[-122.381388, 37.775833],
[-122.382084, 37.7771],
[-122.382084, 37.7771],
[-122.3825, 37.777777],
[-122.382851, 37.776382],
[-122.384166, 37.776666],
[-122.381388, 37.775833],
[-122.382084, 37.7771],
[-122.382084, 37.7771],
[-122.3825, 37.777777],
[-122.382851, 37.776382],
[-122.384166, 37.776666],
[-122.381388, 37.775833],
[-122.382084, 37.7771],
[-122.382084, 37.7771],
[-122.3825, 37.777777],
[-122.382851, 37.776382],
[-122.384166, 37.776666],
[-122.385657, 37.777122]
]
from shapely import speedups
import shapely
from timeit import default_timer as clock
# TODO: generate 10000 random points in San Fransisco and save them in a disk
# matrix. Then benchmark shapely, scipy.spatial and matlab/octave in the three
# problems:
# - distribution from gravity
# - distribution of pairwise distance
# - distribution of nearest neighbour distance
def dst_to_gravity(points):
centroid = points.centroid
return map(lambda p: p.distance(centroid), list(points))
def pairwise_distance(points):
dst = []
for i, p in enumerate(points):
dst.extend(map(lambda q: q.distance(p), points[i+1:]))
return dst
if __name__ == '__main__':
if speedups.available:
speedups.enable()
start = clock()
pts = shapely.geometry.MultiPoint(map(lambda p: (p[1], p[0]), POINTS))
t = 1000*(clock() - start)
print(t)
start = clock()
dst = dst_to_gravity(pts)
t = 1000*(clock() - start)
print(t)
start = clock()
dst2 = pairwise_distance(pts)
t = 1000*(clock() - start)
print(t)