king188.m
来自「书籍代码:遗传演算法原理与应用_活用MATLAB(Source Code)」· M 代码 · 共 34 行
M
34 行
% Main_Program king188.m for King's p184.
% Find a NN to replace the FIS in [P T] described
% in Example 3.5-4.
% Input pattern
P=[0.8 0.8; 0.8 0; 0.8 -0.8; 0.3 0.3;
0.3 -0.3; 0 0.8; 0 0; 0 -0.8;
-0.3 0.3; -0.3 -0.3; -0.8 0.8; -0.8 0;
-0.8 -0.8];
P=P';
% Target
T=[1 0.55 0 0.35 0 0.55 0 -0.55 0 -0.35 0 -0.55 -1];
% New Feedforward NN
net = newff([-1 1;-1 1],[2 1],{'tansig' 'purelin'});
net.trainParam.epochs = 500;
net.trainParam.goal = 1e-10;
% Training
net = train(net,P,T);
% Get the Neural output
Y = sim(net,P)
% Reprint the Target
T=[1 0.55 0 0.35 0 0.55 0 -0.55 0 -0.35 0 -0.55 -1]
% Display weights and bias
W10=net.IW{1,1}
B10=net.b{1}
W20=net.LW{2,1}
B10=net.b{2}
% Plot the target and neural outputs
sample=1:13;
figure(2);plot(sample,T,sample,Y)
title('Desired and Neural output plots')
xlabel('Sample points');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?