SOM_02.m
上传用户:sdcdgc2008
上传日期:2014-04-13
资源大小:365k
文件大小:4k
- %------ 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:SOMBPdata_sourcefeature02'; % minmax([I1';I2';I3';I4';I5';I6';I7';I8'])
- I1 = load([base_path,'apen.txt']); % 1 >> 2 1.2563 1.8150
- I2 = load([base_path,'kc.txt']); % 0 >> 1 0.6299 0.9611
- I3 = load([base_path,'mir.txt']); % 0 >> 5 0.4802 4.0544
- I4 = load([base_path,'asm.txt']); % 0 >> 0.01 0.0004 0.0037
- I5 = load([base_path,'idm.txt']); % 0 >> 0.5 0.0663 0.2906
- I6 = load([base_path,'cont.txt']); % 0 >> 500 12.2600 337.5440
- I7 = load([base_path,'ent.txt']); % 5 >> 9 5.8675 7.9858
- I8 = load([base_path,'gln.txt']); % 10 >> 60 13.4204 53.2048
- % normalize
- P = [(I1'-ones(1,sum_num));I2';(I3'./5);(I4'./0.01);I5'./0.5;(I6'./500);(I7'-ones(1,sum_num).*5)./4;(I8'-ones(1,sum_num).*10)./50];
- MinMaxValue = [zeros(input_num,1),ones(input_num,1)];
- % NEWSOM ---- create the som net
- net = newsom( MinMaxValue,[out_num]);
- net.trainParam.show = 1000;
- % net.parameter
- % TRAIN ----- train the net
- Epochs = 0;
- savePath1 = 'E:SOMBPsave_result8feature02';
- file = '.mat';
- M = 10;%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');
-
-
- % another
- SOM_03.m;
-
- % 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;