def __call__(self, x, inverse=False):
"""Rotates the input array `x` with a fixed rotation matrix
(``self.dicMatrices[len(x)]``)
"""
x = np.array(x, copy=False)
N = x.shape[0] # can be an array or matrix, TODO: accept also a list of arrays?
if N not in self.dicMatrices: # create new N-basis once and for all
rstate = np.random.get_state()
np.random.seed(self.seed) if self.seed else np.random.seed()
self.state = np.random.get_state() # only keep last state
B = np.random.randn(N, N)
np.random.set_state(rstate) # keep untouched/good sequence from outside view
for i in range(N):
for j in range(0, i):
B[i] -= np.dot(B[i], B[j]) * B[j]
B[i] /= sum(B[i]**2)**0.5
self.dicMatrices[N] = B
if inverse:
return np.dot(self.dicMatrices[N].T, x) # compute rotation
else:
return np.dot(self.dicMatrices[N], x) # compute rotation
评论列表
文章目录