Skip to content

Commit 53b6fe1

Browse files
committed
improve
1 parent e1befed commit 53b6fe1

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Neural_Network/neuralnetwork_bp3.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
import matplotlib.pyplot as plt
1111

12-
class Bpnw():
12+
class Bpnn():
1313

1414
def __init__(self,n_layer1,n_layer2,n_layer3,rate_w=0.3,rate_t=0.3):
1515
'''
@@ -38,7 +38,7 @@ def sig_plain(self,x):
3838
def do_round(self,x):
3939
return round(x, 3)
4040

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):
4242
'''
4343
:param patterns: the number of patterns
4444
:param data_train: training data x; numpy.ndarray
@@ -127,8 +127,26 @@ def predict(self,data_test):
127127

128128

129129
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)
132150

133151
if __name__ == '__main__':
134152
main()

0 commit comments

Comments
 (0)