Appendix I ARENA training algorithm %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Implementation of Arena algorithm. % %----------------------------------------------------% % code written by : Gregory Tambasis % % (c)2000 % %----------------------------------------------------% % The algorithm is calculating the "distance" % % between the images of the training set. The result % % is used as an input to the neural network, % % in order to train it. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Aimages, Bimages = database images %RAimages, RBimages = reduced resolution database images %data = number of images used from the training dataset %power = p value %Turn on echoing of commands inside the script-file. echo on %Clear the workspace (all variables). clear all %Clear command window. clc %K = MENU('Choose a dataset','1: orl','2:feret'); %User defined parameters power = input('insert a value for p: '); data = input('insert number of images in training and testing set: '); rez = input('insert resolution: '); %read input image for j = 1:data string = ['train\' Train_Aimages{j} = end; for i = 1:data string = ['train\' Train_Bimages{i} = end; num2str(j) '.tif']; imread(string); num2str(i) '.tif']; imread(string); %Reduce resolution (resize) input and database images to 16x16. for j = 1:data Train_RAimages{j}= imresize(Train_Aimages{j},[rez,rez],'nearest'); end; for i = 1:data Train_RBimages{i}= imresize(Train_Bimages{i},[rez,rez],'nearest'); end; I Appendix I %measure the distance L for i = 1:data; for j = 1:data; if power==0; Train_FSum{j,i}= 1; else Train_X{j,i} = double(Train_RAimages{j}) double(Train_RBimages{i}); Train_Y{j,i} = abs(Train_X{j,i}); Train_Matrix_Sum{j,i} = sum((Train_Y{j,i})^power); Train_Vector_Sum{j,i} = sum(Train_Matrix_Sum{j,i}); Train_FSum{j,i} =min(Train_Vector_Sum{j,i}); end; end; end; clc; %display output Train_Fsum II Appendix I ARENA testing algorithm %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Implementation of Arena algorithm. % %----------------------------------------------------% % code written by : Gregory Tambasis % % (c)2000 % %----------------------------------------------------% % The algorithm is calculating the "distance" % % between one of the images in the Test set and % % the images in the training set. % % The result is used as an input to the % % neural network, in order to simulate and test. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Aimages, Bimages = database images %RAimages, RBimages = reduced resolution database images %data = number of images used from the training dataset %power = p value %Turn on echoing of commands inside the script-file. echo on %Clear the workspace (all variables). Clear all %Clear command window. clc %User defined value of p power = input('insert a value for p: '); data = input('insert number of images in training and Test set: '); rez = input('insert resolution: '); for n = 1:data string = ['test\' num2str(n) '.tif']; Test_Aimages{n} = imread(string); % imshow(Test_Aimages{n}) % pause end; for i = 1:data string = ['train\' num2str(i) '.tif']; Test_Bimages{i} = imread(string); end; %Reduce resolution (resize) input and databases images to 16x16. tj = input('image: '); Test_RA = imresize(Test_Aimages{tj},[rez,rez],'nearest'); for i = 1:data Test_RBimages{i}= imresize(Test_Bimages{i},[rez,rez],'nearest'); end; III Appendix I %measure the distance L for i = 1:data; if power==0; Test_FSum{i}= 1; else Test_X{i} = double(Test_RA) - double(Test_RBimages{i}); Test_Y{i} = abs(Test_X{i}); Test_Matrix_Sum{i} = sum((Test_Y{i})^power); Test_Vector_Sum{i} = sum(Test_Matrix_Sum{i}); Test_FSum{i} =min(Test_Vector_Sum{i}); end; end; %output Test_FSum IV Appendix I Training the neural network %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Implementation of Arena algorithm. % %----------------------------------------------------% % code written by : Gregory Tambasis % % (c)2000 % %----------------------------------------------------% % The program is training the neural network % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clc; classes = input('insert number of classes: '); if data==5 net = newff([-1 1;-1 1;-1 1;-1 1;-1 1;],[10,classes],{'tansig','purelin'}, 'traingd'); elseif data==10 net = newff([-1 1;-1 1;-1 1;-1 1;-1 1;-1 1;-1 1;-1 1;-1 1;-1 1;],[10,classes],{'tansig','purelin'}, 'traingd'); end; net.layers{1}.initFcn = 'initwb'; net.inputWeights{1,1}.initFcn = 'rands'; net.biases{1,1}.initFcn = 'rands'; net.biases{2,1}.initFcn = 'rands'; net=init(net); net.biases{1,1}.learnFcn = 'learngd'; net.biases{2,1}.learnFcn = 'learngd'; net.layerWeights{2,1}.learnFcn = 'learngd'; net.layerWeights{1,1}.learnFcn = 'learngd'; net.adaptParam.passes = 500; %-------------------------------for q=1:data for w=1:data p(q,w)=Train_FSum{q,w}; end; end; %generate target matrix for y=1:classes for u=1:classes if y==u t(y,u)=0; else t(y,u)=2000000; end; end; end; if classes<data for y=1:classes for u=classes+1:data V Appendix I if u==y+5 t(y,u)=0; else t(y,u)=2000000; end; end; end; end; %normilised from 0 to 1 %for k = 1:10 % for l = 1:10 % if p(k,l)==0; % pn(k,l)=0; % else % pn(k,l)=1./p(k,l); % end; % end; %end; %[net,a,e] = adapt(net,pn,t); %b = sim(net,pn) %normilised from -1 to 1 [pn,minp,maxp,tn,mint,maxt] = premnmx(p,t); [net,a,e] = adapt(net,pn,tn); b= sim(net,pn) %not normilised %p = num2cell(p,1); %t = num2cell(t,1); %[net,a,e] = adapt(net,p,t); %celldisp(a) %celldisp(e) %b= sim(net,p) %celldisp(b) VI Appendix I Testing the neural network %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Implementation of Arena algorithm. % %----------------------------------------------------% % code written by : Gregory Tambasis % % (c)2000 % %----------------------------------------------------% % The program is testing the neural network % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for q=1:data for w=1:data tp(q,w)=Test_FSum{w}; end; end; %normilised from -1 to 1 [tpn,minp,maxp,tn,mint,maxt] = premnmx(tp,t); %[net,a,e] = adapt(net,pn,tn); g= sim(net,tpn) %not normilised %p = num2cell(p,1); %t = num2cell(t,1); %[net,a,e] = adapt(net,p,t); %celldisp(a) %celldisp(e) %b= sim(net,p) %celldisp(b) VII