9
9
import numpy as np
10
10
import matplotlib .pyplot as plt
11
11
12
- class Bpnw ():
12
+ class Bpnn ():
13
13
14
14
def __init__ (self ,n_layer1 ,n_layer2 ,n_layer3 ,rate_w = 0.3 ,rate_t = 0.3 ):
15
15
'''
@@ -38,7 +38,7 @@ def sig_plain(self,x):
38
38
def do_round (self ,x ):
39
39
return round (x , 3 )
40
40
41
- def trian (self ,patterns ,data_train , data_teach , n_repeat , error_accuracy ,draw_e = bool ):
41
+ def trian (self ,patterns ,data_train , data_teach , n_repeat , error_accuracy , draw_e = False ):
42
42
'''
43
43
:param patterns: the number of patterns
44
44
:param data_train: training data x; numpy.ndarray
@@ -49,9 +49,9 @@ def trian(self,patterns,data_train, data_teach, n_repeat, error_accuracy,draw_e
49
49
'''
50
50
data_train = np .asarray (data_train )
51
51
data_teach = np .asarray (data_teach )
52
- print ('-------------------Start Training-------------------------' )
53
- print (' - - Shape: Train_Data ' ,np .shape (data_train ))
54
- print (' - - Shape: Teach_Data ' ,np .shape (data_teach ))
52
+ # print('-------------------Start Training-------------------------')
53
+ # print(' - - Shape: Train_Data ',np.shape(data_train))
54
+ # print(' - - Shape: Teach_Data ',np.shape(data_teach))
55
55
rp = 0
56
56
all_mse = []
57
57
mse = 10000
@@ -95,9 +95,9 @@ def draw_error():
95
95
plt .ylabel ('All_mse' )
96
96
plt .grid (True ,alpha = 0.7 )
97
97
plt .show ()
98
- print ('------------------Training Complished---------------------' )
99
- print (' - - Training epoch: ' , rp , ' - - Mse: %.6f' % mse )
100
- print (' - - Last Output: ' , final_out3 )
98
+ # print('------------------Training Complished---------------------')
99
+ # print(' - - Training epoch: ', rp, ' - - Mse: %.6f'%mse)
100
+ # print(' - - Last Output: ', final_out3)
101
101
if draw_e :
102
102
draw_error ()
103
103
@@ -108,9 +108,9 @@ def predict(self,data_test):
108
108
'''
109
109
data_test = np .asarray (data_test )
110
110
produce_out = []
111
- print ('-------------------Start Testing-------------------------' )
112
- print (' - - Shape: Test_Data ' ,np .shape (data_test ))
113
- print (np .shape (data_test ))
111
+ # print('-------------------Start Testing-------------------------')
112
+ # print(' - - Shape: Test_Data ',np.shape(data_test))
113
+ # print(np.shape(data_test))
114
114
for g in range (np .shape (data_test )[0 ]):
115
115
116
116
net_i = data_test [g ]
@@ -127,8 +127,26 @@ def predict(self,data_test):
127
127
128
128
129
129
def main ():
130
- #I will fish the mian function later
131
- pass
130
+ #example data
131
+ data_x = [[1 ,2 ,3 ,4 ],
132
+ [5 ,6 ,7 ,8 ],
133
+ [2 ,2 ,3 ,4 ],
134
+ [7 ,7 ,8 ,8 ]]
135
+ data_y = [[1 ,0 ,0 ,0 ],
136
+ [0 ,1 ,0 ,0 ],
137
+ [0 ,0 ,1 ,0 ],
138
+ [0 ,0 ,0 ,1 ]]
139
+
140
+ test_x = [[1 ,2 ,3 ,4 ],
141
+ [3 ,2 ,3 ,4 ]]
142
+
143
+ #building network model
144
+ model = Bpnn (4 ,10 ,4 )
145
+ #training the model
146
+ model .trian (patterns = 4 ,data_train = data_x ,data_teach = data_y ,
147
+ n_repeat = 100 ,error_accuracy = 0.1 ,draw_e = True )
148
+ #predicting data
149
+ model .predict (test_x )
132
150
133
151
if __name__ == '__main__' :
134
152
main ()
0 commit comments