SOM_02.m
上传用户:sdcdgc2008
上传日期:2014-04-13
资源大小:365k
文件大小:4k
开发平台:

Matlab

  1. %------  SOM test-02 --------
  2. clear
  3. clc
  4. echo off
  5. % --------------- initial the parameter
  6. out_num = 3;                  % 输出节点数目
  7. input_num = 8;                % 输入节点数目
  8. Epochs = 1;                  % 训练周期
  9. positive_num = 55;       %  正常图像数目
  10. negative_num = 75;       %  异常图像数目
  11. sum_num = positive_num + negative_num; % 总的图像数目
  12. % --------------- read data from the file
  13. base_path = 'E:SOMBPdata_sourcefeature02';                      % minmax([I1';I2';I3';I4';I5';I6';I7';I8'])
  14. I1 = load([base_path,'apen.txt']);           % 1 >> 2        1.2563    1.8150        
  15. I2 = load([base_path,'kc.txt']);             % 0 >> 1        0.6299    0.9611
  16. I3 = load([base_path,'mir.txt']);            % 0 >> 5        0.4802    4.0544
  17. I4 = load([base_path,'asm.txt']);            % 0 >> 0.01    0.0004    0.0037
  18. I5 = load([base_path,'idm.txt']);            % 0 >> 0.5       0.0663    0.2906
  19. I6 = load([base_path,'cont.txt']);           % 0 >> 500     12.2600  337.5440
  20. I7 = load([base_path,'ent.txt']);            % 5 >> 9        5.8675    7.9858
  21. I8 = load([base_path,'gln.txt']);            % 10 >> 60      13.4204   53.2048
  22. % normalize 
  23. 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];
  24. MinMaxValue = [zeros(input_num,1),ones(input_num,1)]; 
  25. % NEWSOM ---- create the som net 
  26. net = newsom( MinMaxValue,[out_num]);
  27. net.trainParam.show = 1000;
  28. % net.parameter
  29. % TRAIN ----- train the net
  30. Epochs = 0;
  31. savePath1 = 'E:SOMBPsave_result8feature02';
  32. file = '.mat';
  33. M = 10;%16;
  34. train_num = [1,10,100,500,1000,2000,3000,5000,10000,20000,30000,50000,100000,200000,500000,1000000];
  35. time_record = zeros(1,M);
  36. mix_record = zeros(M,out_num,2);
  37. % FN_record = zeros(1,M);
  38. % FP_record = zeros(1,M);
  39. for(i=1:M)
  40. % train 
  41.     if (i==1)
  42.         Epochs = 1;
  43.     else
  44.         Epochs = train_num(i) - train_num(i-1);
  45.     end
  46.     net.trainParam.epochs = Epochs;
  47.     %  train
  48.     begin_time = clock;
  49.     [net,tr,Y,E,Pf,Af] = train(net,P);
  50.     cost_time = etime(clock,begin_time)
  51.     time_record(i) = cost_time;
  52.     %  my sim   
  53.     SOMresult = dist(net.IW{1},P);
  54.     [minValue minNum] = min(SOMresult);
  55.     % give some test (stastical test)
  56.     mixture = zeros(out_num,2);                         %  the positve and negative in classes
  57.     for(k=1:out_num)
  58.         temp = 0;
  59.         for(j=1:positive_num)
  60.             if( minNum(j)==k)
  61.                 temp = temp + 1;
  62.             end
  63.         end
  64.         mixture(k,1) = temp;
  65.         temp = 0;
  66.         for(j=(positive_num+1):sum_num)
  67.             if( minNum(j)==k)
  68.                 temp = temp + 1;
  69.             end
  70.         end
  71.         mixture(k,2) = temp;
  72.     end
  73.     mix_record(i,:,:) = mixture(:,:); 
  74.        
  75. % OUTPUT ----- out put the som data which made as the bp input data
  76.     savePath2 = [savePath1 'SOMresult' num2str(train_num(i)) file];
  77.     save(savePath2, 'SOMresult','mixture', 'net', 'tr', 'Y' ,'E', 'Pf','Af','P'); 
  78. end
  79.     savePath3 = [savePath1 'statis_som'  file];
  80.     save(savePath3,'time_record','mix_record');
  81.   
  82.     
  83.  % another
  84.  SOM_03.m;
  85.     
  86. %     save(savePath3,'time_record','FN_record','FP_record','FN' ,'FP','Sens', 'Spec');  
  87. %     FN = 0;   %  False-negative rate
  88. %     FP = 0;   %  False-positive rate
  89. %     Sens = 0; %  1-FN
  90. %     Spec = 0; %  1-FP
  91. %     for(j=1:positive_num)
  92. %         if(minNum(1,j)~=1)
  93. %             FP = FP+1;
  94. %         end
  95. %     end
  96. %     for(j= (positive_num+1):sum_num)
  97. %         if(minNum(1,j)==1)
  98. %             FN = FN+1;
  99. %         end
  100. %     end
  101. %     FN = FN/negative_num;
  102. %     FP = FP/positive_num;
  103. %     Sens = 1-FN;
  104. %     Spec = 1-FP;
  105. %     FN_record(i) = FN;
  106. %     FP_record(i) = FP;