-
Notifications
You must be signed in to change notification settings - Fork 0
/
layers.py
51 lines (46 loc) · 2.3 KB
/
layers.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
import numpy as np
class layer1:
def __init__(self, matrix):
self.mean = np.mean(matrix, axis=0)
self.std = np.std(matrix, axis = 0, dtype=np.float32)
self.z = np.hstack((np.ones((np.size(matrix, 0), 1)),self.__featureNormalize(matrix)))
def __featureNormalize(self, matrix):
means = np.tile(self.mean, (np.size(matrix, 0),1))
stds = np.tile(self.std, (np.size(matrix, 0),1))
return np.divide(matrix-means, stds)
class layer2:
def __init__(self, matrix1, matrix2):
self.mean = np.mean(np.hstack((matrix1, matrix2)), axis=0)
self.std = np.std(np.hstack((matrix1, matrix2)), axis = 0, dtype=np.float32)
self.z = np.hstack((np.ones((np.size(matrix1, 0), 1)),self.__featureNormalize(np.hstack((matrix1, matrix2)))))
def __featureNormalize(self, matrix):
means = np.tile(self.mean, (np.size(matrix, 0),1))
stds = np.tile(self.std, (np.size(matrix, 0),1))
return np.divide(matrix-means, stds)
class layer3:
def __init__(self, matrix):
self.mean = np.mean(matrix, axis=0)
self.std = np.std(matrix, axis = 0, dtype=np.float32)
self.z = np.hstack((np.ones((np.size(matrix, 0), 1)),self.__featureNormalize(matrix)))
def __featureNormalize(self, matrix):
means = np.tile(self.mean, (np.size(matrix, 0),1))
stds = np.tile(self.std, (np.size(matrix, 0),1))
return np.divide(matrix-means, stds)
class layer4:
def __init__(self, matrix):
self.mean = np.mean(matrix, axis=0)
self.std = np.std(matrix, axis = 0, dtype=np.float32)
self.z = np.hstack((np.ones((np.size(matrix, 0), 1)),self.__featureNormalize(matrix)))
def __featureNormalize(self, matrix):
means = np.tile(self.mean, (np.size(matrix, 0),1))
stds = np.tile(self.std, (np.size(matrix, 0),1))
return np.divide(matrix-means, stds)
class layer5:
def __init__(self, matrix):
self.mean = np.mean(matrix, axis=0)
self.std = np.std(matrix, axis = 0, dtype=np.float32)
self.z = self.__featureNormalize(matrix)
def __featureNormalize(self, matrix):
means = np.tile(self.mean, (np.size(matrix, 0),1))
stds = np.tile(self.std, (np.size(matrix, 0),1))
return np.divide(matrix-means, stds)