-
Notifications
You must be signed in to change notification settings - Fork 3
/
costmatrices.py
39 lines (28 loc) · 988 Bytes
/
costmatrices.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
import numpy as np
from scipy.spatial.distance import cdist
def random_uniform(n, shape):
np.random.seed(0)
for i in range(n):
yield np.random.uniform(-20, 20, shape)
def random_logarithmic(n, shape):
np.random.seed(0)
for i in range(n):
yield 10**np.random.uniform(-20, 20, shape)
def random_integer(n, shape):
np.random.seed(0)
for i in range(n):
yield np.random.randint(-1000, 1000, shape)
def random_binary(n, shape):
np.random.seed(0)
for i in range(n):
yield np.random.randint(0, 2, shape)
def random_spatial(n, shape):
np.random.seed(0)
for i in range(n):
P = np.random.uniform(-1, 1, size=(shape[0], 2))
Q = np.random.uniform(-1, 1, size=(shape[1], 2))
cost_matrix = cdist(P, Q, 'sqeuclidean')
assert cost_matrix.shape == shape
yield cost_matrix
generators = [random_uniform, random_spatial, random_logarithmic,
random_integer, random_binary]