⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 examplev2.m

📁 好东西啊 人脸识别用的 希望大家多支持这个
💻 M
字号:
%%% Patrick Etyngier
%%% etyngier@certis.enpc.fr
%%% http://cermics.enpc.fr/~etyngier
%%% ENPC - Ecole Nationale des Ponts et Chaussees 
%%%     http://www.enpc.fr
%%% CERTIS - Centre d'Enseignement en Recherche en Technologie de
%%%     l'Information et Systemes
%%%     http://cermics.enpc.fr/~certis
%%% Copyright CERTIS
%%%
%%% V.9 ExampleV2.m


%% Get data
clear all
close all
figure('DoubleBuffer','On')
axis([-1 1 -1 1])
hold on
but = 1;
n=1;
n1 = 1 ; n2 = 1;

while but == 1 | but ==3
    [xi,yi,but] = ginput(1);
    if but == 1
        plot(xi,yi,'rx')
        xy1(n1,:) = [xi,yi];
        n1 = n1+1;
    elseif but == 3
        plot(xi,yi,'bx')
        xy2(n2,:) = [xi,yi];
        n2 = n2+1;
    end
  
    label = (but==1) - (but==3);
    if label ~= 0 
        xy(n,:) = [xi,yi];
        all_lab(n,:) = label;
        
         n = n+1;
    end 
end

X = xy;
y= all_lab;
S_CI = X(find(y==1),:);
S_CII = X(find(y==-1),:);

d1 = length(S_CI(:,1));
d2 = length(S_CII(:,1));
pd1 = randperm(d1);
pd2 = randperm(d2);
ind1 = pd1(1:floor(d1/2));
cind1 = pd1((floor(d1/2)+1):end);
ind2 = pd2(1:floor(d2/2));
cind2 = pd2((floor(d2/2)+1):end);

LS_CI = S_CI(ind1,:);
LS_CII = S_CII(ind2,:);

TS_CI = S_CI(cind1,:);
TS_CII = S_CII(cind2,:);

plot(LS_CI(:,1),LS_CI(:,2),'ro')
plot(TS_CI(:,1),TS_CI(:,2),'rs')
plot(LS_CII(:,1),LS_CII(:,2),'bo')
plot(TS_CII(:,1),TS_CII(:,2),'bs')

M=100;
[fm1,fm2,linSeparators,alpha_ goodThresholds] = pkAdaBoost(X,y,M);



for m=1:M
    res_I = pkAdaClassify([LS_CI ones(length(LS_CI(:,1)),1)],fm1,fm2,linSeparators,alpha_,goodThresholds,m);
    res_II = pkAdaClassify([LS_CII ones(length(LS_CII(:,1)),1)],fm1,fm2,linSeparators,alpha_,goodThresholds,m);
    r1(m) = length(find(res_I==1))/length(res_I);
    r2(m) = length(find(res_II==-1))/length(res_II);
end

for m=1:M
    rest_I = pkAdaClassify([TS_CI ones(length(TS_CI(:,1)),1)],fm1,fm2,linSeparators,alpha_,goodThresholds,m);
    rest_II = pkAdaClassify([TS_CII ones(length(TS_CII(:,1)),1)],fm1,fm2,linSeparators,alpha_,goodThresholds,m);
    t1(m) = length(find(rest_I==1))/length(rest_I);
    t2(m) = length(find(rest_II==-1))/length(rest_II);
end

figure
subplot(211)
plot(1:M,1-r1(1:M),':',1:M,1-r2(1:M),':',1:M,mean([1-r1(1:M);1-r2(1:M)]),'-')
legend('class 1 learning error', 'class 2 learning error', 'learning error');
title( sprintf('On Learning Set, | Size Class I : %d / Size Class II : %d', length(LS_CI(:,1)), length(LS_CII(:,1))))

subplot(212)
plot(1:M,1-t1(1:M),':',1:M,1-t2(1:M),':',1:M,mean([1-t1(1:M);1-t2(1:M)]),'-')
legend('class 1 testing error', 'class 2 testing error' , 'testing error');
title( sprintf('On Testing Set,  | Size Class I : %d / Size Class II : %d',length(TS_CI(:,1)),length(TS_CII(:,1)) ))

[N,junk]=size(X);
XX = -1:1/50:1
YY = -1:1/50:1;
[XXX,YYY]=meshgrid(XX,YY);
xxx= reshape(XXX,[length(XX)*length(XX),1]);
yyy= reshape(YYY,[length(YY)*length(YY),1]);
dataT = [xxx,yyy,ones(length(xxx),1)];

res = pkAdaClassify(dataT,fm1,fm2,linSeparators,alpha_,goodThresholds,M);
figure
ii1 = find(res~=-1);
ii2 = find(res==-1);
plot(xxx(ii1),yyy(ii1),'.r',xxx(ii2),yyy(ii2),'.b','MarkerSize',10)
hold on 
%plot3(xxx(1:8:end),yyy(1:8:end),toto(1:8:end),'.');

plot(X(find(y==1),1),X(find(y==1),2),'.k','MarkerSize',15);
hold on
plot(X(find(y==-1),1),X(find(y==-1),2),'.g','MarkerSize',15);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -