project4.asv
上传用户:miaohui010
上传日期:2013-01-08
资源大小:2540k
文件大小:2k
开发平台:

Matlab

  1. %function U=select_feature(sel)
  2. sel=120;
  3. load human;
  4. load vehicle;
  5. k_s=1;
  6. k_d=120;
  7. hm_tr(250,252)=0;
  8. hm_test(250,252)=0;
  9. [hm_tr,hm_test]=randQ(human);
  10. randQ(vehicle);
  11. bg_tr(250,252)=0;
  12. bg_test(250,252)=0;
  13. [veh_tr,veh_test]=randQ(vehicle);  
  14. M_hm=hm_tr(1,:);
  15. for i=2:250
  16. M_hm=M_hm+(hm_tr(i));
  17. end
  18. M_hm=M_hm/250;
  19. M_veh=veh_tr(1,:);
  20. for i=2:250
  21. M_veh=M_veh+(veh_tr(i));
  22. end
  23. M_veh=M_veh/250;
  24. E_hm(252,252)=0;
  25. E_veh(252,252)=0;
  26. for i=1:250
  27.     E_hm=E_hm+(hm_tr(i,:)-M_hm)'*(hm_tr(i,:)-M_hm);
  28.     E_veh=E_veh+(veh_tr(i,:)-M_veh)'*(veh_tr(i,:)-M_veh);
  29. end
  30. E_hm=E_hm/250;
  31. E_veh=E_veh/250;
  32. %假设行人和骑车两类的先验概率都相等,均等于0.5;
  33. Sw=0.5*E_hm+0.5+E_veh;
  34. [V,D]=eig(Sw);
  35. M_S(1,252)=0;
  36. for i=1:250
  37. M_S=M_S+hm_tr(i)+veh_tr(i);
  38. end
  39. Sb=0.5*(M_hm-M_S)'*(M_hm-M_S)+0.5*(M_veh-M_S)'*(M_veh-M_S);
  40. Y(1,252)=0;
  41. for i=1:252
  42.     for j=1:252
  43.         if (i==j)
  44.             Y(i)=V(i,j);
  45.         end
  46.     end
  47. end
  48. for i=1:252
  49.     J(i)=V(:,i)'*Sb*V(:,i)/Y(i);
  50. end
  51. index(1:252)=0;
  52. for i=1:252
  53.    [K,I]=max(J);
  54.    index(i)=I;
  55.    J(I)=-1.0e+19;
  56. end
  57. U(252,252)=0;
  58. for i=1:252
  59.     a=index(i);
  60.     U(:,i)=V(:,a);
  61. end
  62. U_OK(252,sel)=0;
  63. for i=1:sel
  64. U_OK(:,i)=U(:,i);
  65. end
  66. hm_tr_kl=U_OK'*hm_tr';
  67. veh_tr_kl=U_OK'*veh_tr';
  68. hm_test_kl=U_OK'*hm_test';
  69. veh_test_kl=U_OK'*veh_test';
  70. Y(500,1)=0;
  71. a(1,250)=0;
  72. a(1,:)=1;
  73. b(1,250)=0;
  74. b(1,:)=-1;
  75. c=[a,b]';
  76. tr_kl=[hm_tr_kl,veh_tr_kl]';
  77. test_kl=[hm_test_kl,veh_test_kl]';
  78. net=svm(sel,'rbf',5,1,0,'quadprog',50);
  79. K=svmkernel(net,hm_tr_kl',veh_tr_kl');
  80. net=svmtrain(net,tr_kl,c);
  81. Y=svmfwd(net,test_kl);
  82.