forked from LabGong/SDDObench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transfromation_function.py
39 lines (29 loc) · 1.03 KB
/
transfromation_function.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
def transform_func(phi, lb, ub, delt_t, severity):
delta = ub - lb
if delta == 0:
raise Exception("Error: lower bound equal to upper bound.")
shift_vec = np.full(phi.shape, delt_t)
theta = 4 * np.arcsin(delt_t ** 2)
lamda = severity * delta
if len(phi.shape) == 1:
dim = 1
else:
dim = phi.shape[1]
rotate_mart = get_rotate_mart(theta, dim)
shift_res = phi + lamda * shift_vec
if dim == 1:
return shift_res * rotate_mart
else:
return shift_res @ rotate_mart
def get_rotate_mart(theta, dim):
n = (dim - 1) * (dim % 2) + dim * (1 - (dim % 2))
l = np.arange(dim)
l = l[:n]
rotate_mart = np.eye(dim)
for i in range(int(n / 2)):
rotate_mart[l[i * 2], l[i * 2]] = np.cos(theta)
rotate_mart[l[i * 2 + 1], l[i * 2 + 1]] = np.cos(theta)
rotate_mart[l[i * 2], l[i * 2 + 1]] = -np.sin(theta)
rotate_mart[l[i * 2 + 1], l[i * 2]] = np.sin(theta)
return rotate_mart