-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
114 lines (81 loc) · 2.89 KB
/
utils.py
File metadata and controls
114 lines (81 loc) · 2.89 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import numpy as np
import torch
import re
import math
def PF(d,D,j):
if j//2 == 0:
pe = np.sin(j/20**(2*d/D))
else:
pe = np.cos(j/20**(2*d/D))
return pe
def reorderSMSP(names):
nItem = max([int(re.findall('\d+', name)[0]) for name in names if 'X' in name])+1
nCap = max([int(re.findall('\d+', name)[0]) for name in names if 'Y' in name])+1
XOrder = torch.Tensor(nItem+nCap,nItem)
for ind,name in enumerate(names):
ss = re.findall('\d+',name)
a,b = int(ss[0]),int(ss[1])
if 'X' in name:
XOrder[a,b] = ind
elif 'Y' in name:
XOrder[a+nItem,b] = ind
return {
'reorderInds':XOrder,
'nGroup':nItem,
'nElement':nItem+nCap
}
def addPosFeatureSMSP(features):
vf = features.varFeatures
vn = features.varNames
D1 = 16
D2 = 16
groupPos = np.zeros((vf.shape[0],D1))
elementPos = np.zeros((vf.shape[0],D2))
for ind,var in enumerate(vn):
ss = re.findall('\d+',var)
a,b = int(ss[0]),int(ss[1])
for d in range(D1):
groupPos[ind, d] = PF(d, D1, b)
if 'X' in var:
for d in range(D2):
elementPos[ind,d] = PF(d, D2, a)
elif 'Y' in var:
for d in range(D2):
elementPos[ind,d] = PF(d, D2, a+111)
features.groupFeatures = np.concatenate([ groupPos, elementPos], axis=-1)
return features
def reorderIP(names):
nItem = max([int(re.findall('\d+', name)[0]) for name in names if 'place' in name]) + 1
nBin = max([int(re.findall('\d+', name)[1]) for name in names if 'place' in name]) + 1
XOrder = torch.Tensor(nItem , nBin)
for ind, name in enumerate(names):
ss = re.findall('\d+', name)
a, b = int(ss[0]), int(ss[1])
if 'place' in name:
XOrder[a, b] = ind
return {
'reorderInds': XOrder,
'nGroup': nBin,
'nElement': nItem
}
def addPosFeatureIP(features):
vf = features.varFeatures
vn = features.varNames
nItem = max([int(re.findall('\d+', name)[0]) for name in vn if 'place' in name]) + 1
nBin = max([int(re.findall('\d+', name)[1]) for name in vn if 'place' in name]) + 1
D1 = 16
D2 = 16
groupPos = np.zeros((vf.shape[0], D1))
elementPos = np.zeros((vf.shape[0], D2))
for ind, var in enumerate(vn):
if 'place' not in var:
continue
ss = re.findall('\d+', var)
a, b = int(ss[0]), int(ss[1])
for d in range(D1):
groupPos[ind,d] = PF(d,D1,b)
for d in range(D2):
elementPos[ind,d] = PF(d,D2,a)
features.groupFeatures = np.concatenate([ groupPos, elementPos], axis=-1)
# features.varFeatures = np.concatenate([groupPos, elementPos], axis=-1)
return features