📄 patternclassify.asv
字号:
function PatternClassify(X2s_train, X2s_test)
[row,col] = size(X2s_train);
%提取训练数据和测试数据
input_P = 2s_train(:,1:col-1);
target_T = 2s_train(:,col);
test_P = 2s_test(:,1:col-1);
test_T = 2s_test(:,col);
%训练三层神经网络,隐藏层有10个单元
eps = 0.1;
alpha = 0.1;
initU1 = [0.43 0.54
0.23 0.54
0.54 0.54
0.53 0.22
0.15 0.98
0.67 0.23
0.34 0.65
0.54 0.34
0.11 0.87
0.34 0.45];
initV1 = [0.43 0.56
0.24 0.5
0.54 0.26
0.76 0.87
0.26 0.38
0.38 0.48
0.26 0.1
0.48 0.38
0.85 0.48
0.96 0.59];
initb1 = [0.42;0.23;0.31;0.43;0.42;0.34;0.43;0.23;0.12;0.43];
initU2 = [0.5 0.55 0.32 0.21 0.23 0.6 0.1 0.21 0.43 0.87];
initV2 = [0.4 0.32 0.52 0.36 0.14 0.9 0.45 0.21 0.78 0.11];
initb2 = [0.1];
[u1,u2, v1, v2, b1, b2, times] = MLP(eps, initU1, initV1, initb1, initU2, initV2, initb2 , alpha, input_P, target_T)
%验证神经网络的正确性
len = length(test_T);
correct = 0;
for i=1:len
x0 = test_P(i,:)';
x1 = sigmoid(u1*(x0.^2) + v1*x0 + b1);
x2 = sigmoid(u2*(x1.^2) + v2*x1 + b2);
if(round(x2)==test_T(i))
correct = correct+1;
end
end
correct
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -