性能分析代码如下:
%%%%%%% 再次用无噪声字母训练识别网络,开始
fprintf('================================================/n');
fprintf('There are no noise,begin/n');
netn.trainParam.goal = 0.1; % 均方误差目标.
netn.trainParam.epochs = 500; % 最大训练步长
net.trainParam.show = 5; % 训练中显示的频率
P = alphabet;
T = targets;
[netn,tr] = train(netn,P,T);
%%%%%%% 再次用无噪声字母训练识别网络,结束
fprintf('There are no noise,end/n');
fprintf('================================================/n');
%%%% 测试所训练的网络性能
noise_range = 0:.02:0.2;
max_test = 100;
network1 = [];
network2 = [];
T = targets;
% PERFORM THE TEST
for noiselevel = noise_range
fprintf('================================================/n');
fprintf('Testing networks with noise level of %.2f./n',noiselevel);
errors1 = 0;
errors2 = 0;
for i=1:max_test
P = alphabet + randn(35,26)*noiselevel;
% TEST NETWORK 1
A = sim(net,P);
AA = compet(A);
errors1 = errors1 + sum(sum(abs(AA-T)))/2;
% TEST NETWORK 2
An = sim(netn,P);
AAn = compet(An);
errors2 = errors2 + sum(sum(abs(AAn-T)))/2;
echo off
end
% 100组26个矢量的平均误差
network1 = [network1 errors1/26/100];
network2 = [network2 errors2/26/100];
end
fprintf('================================================/n');
% echo on
%
% The echo command controls the echoing of M-files during execution.
% Normally, the commands in M-files are not displayed on the screen
% during execution. Command echoing is useful for debugging
% or for demonstrations, allowing the commands to be viewed as they execute.
% The echo command behaves in a slightly different manner for script files
% and function files. For script files, the use of echo is simple;
% echoing can be either on or off, in which case any script used is affected.
% echo onTurns on the echoing of commands in all script filesecho offTurns off the echoing of commands in all script filesechoToggles the echo state
% pause % 按任意键显示结果
% 显示结果
% ========
clf
% clf deletes from the current figure all graphics objects
% whose handles are not hidden (i.e., their HandleVisibility property is set to on).
% clf('reset') deletes from the current figure all graphics objects regardless of
% the setting of their HandleVisibility property and resets all figure properties except Position,
% Units, PaperPosition, and PaperUnits to their default values.
% figure_handle = clf(...) return the handle of the figure.
% This is useful when the figure IntegerHandle property is off
% since the noninteger handle becomes invalid when the reset option is used
% (i.e., IntegerHandle is reset to on, which is the default).
plot(noise_range,network1*100,'r*',noise_range,network2*100,'g*');
grid
xlabel('Noise Level');
ylabel('Percentage of Recognition');
% echo off
%三种情况下字母Y的表示情况
noisyY1 = alphabet(:,25)+randn(35,1) * 0.2;
figure(2);
plotchar(noisyY1);
noiseY2=alphabet(:,25)+randn(35,1)*0.1;
figure(3);
plotchar(noiseY2);
idealY=alphabet(:,25);
figure(4)
plotchar(idealY);
%%%%%%%%%%%%%%%=========================================================
% figure(5);
% sp=sim(net,noisyY1);
% plotchar(sp);
% figure(6);
% sp2=sim(net,noisyY1);
% plotchar(sp2);
调用的prodat,预处理数据用于产生字母序列表和eye矩阵,具体程序实现如下:
letterA = [0 0 1 0 0 ...
0 1 0 1 0 ...
0 1 0 1 0 ...
1 0 0 0 1 ...
1 1 1 1 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ]';
letterB = [1 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 1 1 1 0 ]';
letterC = [0 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 0 1 ...
0 1 1 1 0 ]';
letterD = [1 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 1 1 1 0 ]';
letterE = [1 1 1 1 1 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 1 1 1 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 1 1 1 1 ]';
letterF = [1 1 1 1 1 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 1 1 1 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ]';
letterG = [0 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 1 1 ...
1 0 0 0 1 ...
0 1 1 1 0 ]';
letterH = [1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 1 1 1 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ]';
letterI = [0 1 1 1 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 1 1 1 0 ]';
letterJ = [1 1 1 1 1 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
1 0 1 0 0 ...
0 1 0 0 0 ]';
letterK = [1 0 0 0 1 ...
1 0 0 1 0 ...
1 0 1 0 0 ...
1 1 0 0 0 ...
1 0 1 0 0 ...
1 0 0 1 0 ...
1 0 0 0 1 ]';
letterL = [1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 1 1 1 1 ]';
letterM = [1 0 0 0 1 ...
1 1 0 1 1 ...
1 0 1 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ]';
letterN = [1 0 0 0 1 ...
1 1 0 0 1 ...
1 1 0 0 1 ...
1 0 1 0 1 ...
1 0 0 1 1 ...
1 0 0 1 1 ...
1 0 0 0 1 ]';
letterO = [0 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
0 1 1 1 0 ]';
letterP = [1 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 1 1 1 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ...
1 0 0 0 0 ]';
letterQ = [0 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 1 0 1 ...
1 0 0 1 0 ...
0 1 1 0 1 ]';
letterR = [1 1 1 1 0 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 1 1 1 0 ...
1 0 1 0 0 ...
1 0 0 1 0 ...
1 0 0 0 1 ]';
letterS = [0 1 1 1 0 ...
1 0 0 0 1 ...
0 1 0 0 0 ...
0 0 1 0 0 ...
0 0 0 1 0 ...
1 0 0 0 1 ...
0 1 1 1 0 ]';
letterT = [1 1 1 1 1 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ]';
letterU = [1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
0 1 1 1 0 ]';
letterV = [1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
0 1 0 1 0 ...
0 0 1 0 0 ]';
letterW = [1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 0 0 1 ...
1 0 1 0 1 ...
1 1 0 1 1 ...
1 0 0 0 1 ]';
letterX = [1 0 0 0 1 ...
1 0 0 0 1 ...
0 1 0 1 0 ...
0 0 1 0 0 ...
0 1 0 1 0 ...
1 0 0 0 1 ...
1 0 0 0 1 ]';
letterY = [1 0 0 0 1 ...
1 0 0 0 1 ...
0 1 0 1 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ...
0 0 1 0 0 ]';
letterZ = [1 1 1 1 1 ...
0 0 0 0 1 ...
0 0 0 1 0 ...
0 0 1 0 0 ...
0 1 0 0 0 ...
1 0 0 0 0 ...
1 1 1 1 1 ]';
alphabet = [letterA,letterB,letterC,letterD,letterE,letterF,letterG,letterH,...
letterI,letterJ,letterK,letterL,letterM,letterN,letterO,letterP,...
letterQ,letterR,letterS,letterT,letterU,letterV,letterW,letterX,...
letterY,letterZ];
targets = eye(26);
% Y = eye(n) returns the n-by-n identity matrix.
% Y = eye(m,n) or eye([m n]) returns an m-by-n matrix with 1's on the diagonal and 0's elsewhere.
% Y = eye(size(A)) returns an identity matrix the same size as A.
% eye(m, n, classname) or eye([m,n],classname) is an m-by-n matrix
% with 1's of class classname on the diagonal and zeros of class classname elsewhere.
% classname is a string specifying the data type of the output.
% classname can have the following values:
% 'double', 'single', 'int8', 'uint8', 'int16', 'uint16', 'int32', or 'uint32'.
程序输出如下:
运行时,多次运行显示进行模糊处理后效果更好,但是也出现了模糊处理后效果不好的情况。