-
Notifications
You must be signed in to change notification settings - Fork 0
/
featureSpan.py
61 lines (42 loc) · 2 KB
/
featureSpan.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import numpy as np
def computeMean(HEList, featureList):
X = []
Y = []
for i in range(len(HEList)):
Y.append(HEList[i][3])
x = HEList[i][2]
X1 = featureList[int(HEList[i][0]-57)]
X2 = featureList[int(HEList[i][1]-57)]
# Weighted mean, Quadratically weighted mean, absolute mean
X.append(np.array([x*X1 + (1-x)*X2, (x**2*X1 + (1-x)**2*X2)/(x**2+(1-x)**2), abs(X1-X2)/2]).flatten())
return X, Y
def generateFeatures(HEList, featureList):
X = []
Y = []
for i in range(len(HEList)):
Y.append(HEList[i][3])
x = HEList[i][2]
X1 = featureList[int(HEList[i][0]-57)]
X2 = featureList[int(HEList[i][1]-57)]
X.append(np.concatenate((np.array([x, 1/x, x * x, 1 / (x * x), 1-x, 1/(1-x), (1-x) * (1-x), 1/( (1-x) * (1-x))]), np.array([abs(X1-X2)/2.0, 2.0 / (abs(X1-X2)), (abs(X1-X2)/2.0) * (abs(X1-X2)/2.0), 4 / (abs(X1-X2) * abs(X1-X2)), (X1 + X2) / 2.0, 2.0 / (X1 + X2), (X1 + X2) * (X1 + X2) / 4, 4 / ((X1 + X2) * (X1 + X2))]).flatten())))
return X, Y
def generateFeatures_2(HEList, featureList):
X = []
Y = []
for i in range(len(HEList)):
Y.append(HEList[i][3])
x = HEList[i][2]
X1 = featureList[int(HEList[i][0]-57)]
X2 = featureList[int(HEList[i][1]-57)]
X.append(np.concatenate((np.array([x*(1-x)]), np.array([abs(X1-X2)/2.0, 2.0 / (abs(X1-X2)), (abs(X1-X2)/2.0) * (abs(X1-X2)/2.0), 4 / (abs(X1-X2) * abs(X1-X2)), (X1 + X2) / 2.0, 2.0 / (X1 + X2), (X1 + X2) * (X1 + X2) / 4, 4 / ((X1 + X2) * (X1 + X2))]).flatten())))
return X, Y
def X_Standardization(X):
# contains the means for each feature
mean = np.mean(X, axis = 0)
# contains the standard deviation for each feathure
std = np.std(X, axis=0)
X_standardized=np.empty(shape=X.shape)
#standardization
for j in range(X.shape[1]):
X_standardized[:,j] = (X[:,j] - np.ones(X.shape[0]) * mean[j]) / std[j]
return X_standardized, mean, std