forked from GabrieleSantin/VKOGA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (28 loc) · 1.14 KB
/
utils.py
File metadata and controls
35 lines (28 loc) · 1.14 KB
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
#!/usr/bin/env python3
import numpy as np
import scipy.stats as st
from scipy.spatial import distance_matrix
class log_uniform():
# Solution from
# https://stackoverflow.com/questions/49538120/how-to-implement-a-log-uniform-distribution-in-scipy
def __init__(self, a=-1, b=0, base=10):
self.loc = a
self.scale = b - a
self.base = base
def rvs(self, size=None, random_state=None):
uniform = st.uniform(loc=self.loc, scale=self.scale)
if size is None:
return np.power(self.base, uniform.rvs(random_state=random_state))
else:
return np.power(self.base, uniform.rvs(size=size, random_state=random_state))
def incremental_distance_matrix(X, batch_size):
N, d = np.atleast_2d(X).shape
num_batches = int(np.ceil(d / batch_size))
D = np.zeros((N, N))
for idx in range(num_batches):
idx_begin = idx * batch_size
idx_end = (idx + 1) * batch_size
x = np.atleast_2d(X)[:, idx_begin:idx_end]
D += distance_matrix(x, x) ** 2
print('Added dimensions from %5d to %5d' %(idx_begin+1, np.min([d, idx_end])))
return np.sqrt(D)