www.gusucode.com > som-bp混合神经网络的matlab程序源码 > matlab_emulator/SOM_01.m
%------ SOM test-02 -------- clear clc echo off % --------------- initial the parameter out_num = 3; % 输出节点数目 input_num = 8; % 输入节点数目 Epochs = 1; % 训练周期 positive_num = 55; % 正常图像数目 negative_num = 75; % 异常图像数目 sum_num = positive_num + negative_num; % 总的图像数目 % --------------- read data from the file base_path = 'E:\SOMBP\data_source\'; % minmax([I1';I2';I3';I4';I5';I6';I7';I8']) I1 = load([base_path,'apen2.txt']); % 1 >> 2 1.2563 1.8150 I2 = load([base_path,'kc2.txt']); % 0 >> 1 0.6299 0.9611 I3 = load([base_path,'mir2.txt']); % 0 >> 5 0.4802 4.0544 I4 = load([base_path,'asm2.txt']); % 0 >> 0.02 0.0016 0.0148 I5 = load([base_path,'idm2.txt']); % 0 >> 1 0.1325 0.5813 I6 = load([base_path,'con2.txt']); % 0 >> 1000 24.5200 675.0890 I7 = load([base_path,'ent2.txt']); % 5 >> 9 5.8675 7.9858 I8 = load([base_path,'gld2.txt']); % 10 >> 60 13.4204 53.2048 % normalize P = [(I1'-ones(1,sum_num));I2';(I3'./5);(I4'./0.02);I5';(I6'./1000);(I7'-ones(1,sum_num).*5)./4;(I8'-ones(1,sum_num).*10)./50]; MinMaxValue = [zeros(8,1),ones(8,1)]; % NEWSOM ---- create the som net net = newsom( MinMaxValue,[out_num]); % TRAIN ----- train the net Epochs = 0; savePath1 = 'E:\SOMBP\save_result\8feature\'; file = '.mat'; M = 16; train_num = [1,10,100,500,1000,2000,3000,5000,10000,20000,30000,50000,100000,200000,500000,1000000]; time_record = zeros(1,M); mix_record = zeros(M,out_num,2); % FN_record = zeros(1,M); % FP_record = zeros(1,M); for(i=1:M) % train if (i==1) Epochs = 1; else Epochs = train_num(i) - train_num(i-1); end net.trainParam.epochs = Epochs; % train begin_time = clock; [net,tr,Y,E,Pf,Af] = train(net,P); cost_time = etime(clock,begin_time); time_record(i) = cost_time; % my sim SOMresult = dist(net.IW{1},P); [minValue minNum] = min(SOMresult); % give some test (stastical test) mixture = zeros(out_num,2); % the positve and negative in classes for(k=1:out_num) temp = 0; for(j=1:positive_num) if( minNum(j)==k) temp = temp + 1; end end mixture(k,1) = temp; temp = 0; for(j=(positive_num+1):sum_num) if( minNum(j)==k) temp = temp + 1; end end mixture(k,2) = temp; end mix_record(i,:,:) = mixture(:,:); % OUTPUT ----- out put the som data which made as the bp input data savePath2 = [savePath1 'SOMresult' num2str(train_num(i)) file]; save(savePath2, 'SOMresult','mixture', 'net', 'tr', 'Y' ,'E', 'Pf','Af','P'); end savePath3 = [savePath1 'statis_som' file]; save(savePath3,'time_record','mix_record'); % save(savePath3,'time_record','FN_record','FP_record','FN' ,'FP','Sens', 'Spec'); % FN = 0; % False-negative rate % FP = 0; % False-positive rate % Sens = 0; % 1-FN % Spec = 0; % 1-FP % for(j=1:positive_num) % if(minNum(1,j)~=1) % FP = FP+1; % end % end % for(j= (positive_num+1):sum_num) % if(minNum(1,j)==1) % FN = FN+1; % end % end % FN = FN/negative_num; % FP = FP/positive_num; % Sens = 1-FN; % Spec = 1-FP; % FN_record(i) = FN; % FP_record(i) = FP;