project4.asv
资源名称:matlab作业.rar [点击查看]
上传用户:miaohui010
上传日期:2013-01-08
资源大小:2540k
文件大小:2k
源码类别:
人工智能/神经网络
开发平台:
Matlab
- %function U=select_feature(sel)
- sel=120;
- load human;
- load vehicle;
- k_s=1;
- k_d=120;
- hm_tr(250,252)=0;
- hm_test(250,252)=0;
- [hm_tr,hm_test]=randQ(human);
- randQ(vehicle);
- bg_tr(250,252)=0;
- bg_test(250,252)=0;
- [veh_tr,veh_test]=randQ(vehicle);
- M_hm=hm_tr(1,:);
- for i=2:250
- M_hm=M_hm+(hm_tr(i));
- end
- M_hm=M_hm/250;
- M_veh=veh_tr(1,:);
- for i=2:250
- M_veh=M_veh+(veh_tr(i));
- end
- M_veh=M_veh/250;
- E_hm(252,252)=0;
- E_veh(252,252)=0;
- for i=1:250
- E_hm=E_hm+(hm_tr(i,:)-M_hm)'*(hm_tr(i,:)-M_hm);
- E_veh=E_veh+(veh_tr(i,:)-M_veh)'*(veh_tr(i,:)-M_veh);
- end
- E_hm=E_hm/250;
- E_veh=E_veh/250;
- %假设行人和骑车两类的先验概率都相等,均等于0.5;
- Sw=0.5*E_hm+0.5+E_veh;
- [V,D]=eig(Sw);
- M_S(1,252)=0;
- for i=1:250
- M_S=M_S+hm_tr(i)+veh_tr(i);
- end
- Sb=0.5*(M_hm-M_S)'*(M_hm-M_S)+0.5*(M_veh-M_S)'*(M_veh-M_S);
- Y(1,252)=0;
- for i=1:252
- for j=1:252
- if (i==j)
- Y(i)=V(i,j);
- end
- end
- end
- for i=1:252
- J(i)=V(:,i)'*Sb*V(:,i)/Y(i);
- end
- index(1:252)=0;
- for i=1:252
- [K,I]=max(J);
- index(i)=I;
- J(I)=-1.0e+19;
- end
- U(252,252)=0;
- for i=1:252
- a=index(i);
- U(:,i)=V(:,a);
- end
- U_OK(252,sel)=0;
- for i=1:sel
- U_OK(:,i)=U(:,i);
- end
- hm_tr_kl=U_OK'*hm_tr';
- veh_tr_kl=U_OK'*veh_tr';
- hm_test_kl=U_OK'*hm_test';
- veh_test_kl=U_OK'*veh_test';
- Y(500,1)=0;
- a(1,250)=0;
- a(1,:)=1;
- b(1,250)=0;
- b(1,:)=-1;
- c=[a,b]';
- tr_kl=[hm_tr_kl,veh_tr_kl]';
- test_kl=[hm_test_kl,veh_test_kl]';
- net=svm(sel,'rbf',5,1,0,'quadprog',50);
- K=svmkernel(net,hm_tr_kl',veh_tr_kl');
- net=svmtrain(net,tr_kl,c);
- Y=svmfwd(net,test_kl);