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

📄 relevanceregression.m

📁 It is for Face Recognition
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% relevanceRegression()
%   10-28-2003, Z. Li
%   find decision boundary by kernel method
% input:
%   p - total positive samples
%   q - total negative samples
%   alpha - regression kernel parameter - positive samples
%   beta - regression kernel parameter - negative samples
%   thres - relevance thres for decision boundary
% return:
%   relevance - relevance grid 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function [relevance] = relevanceRegression( p, q, alpha, beta, thres)
function [relevance] = relevanceRegression( p, q, alpha, beta, thres)

% dbg
%p = 5; q=6; alpha = 1.0; beta=1.0; thres =0.8;

hold on;

% input area of interets
fprintf('\n input interets area', 2);
[bx, by] = ginput(2);
% plot area
ppx=[bx(1) bx(1)];ppy=[by(1) by(2)];plot(ppx, ppy, '.', ppx,ppy,'-m');
ppx=[bx(1) bx(2)];ppy=[by(1) by(1)];plot(ppx, ppy, '.', ppx,ppy,'-m');
ppx=[bx(1) bx(2)];ppy=[by(2) by(2)];plot(ppx, ppy, '.', ppx,ppy,'-m');
ppx=[bx(2) bx(2)];ppy=[by(2) by(1)];plot(ppx, ppy, '.', ppx,ppy,'-m');
areaW = bx(2) - bx(1);
areaH = by(2) - by(1);

% input positive samples
fprintf('\n input [%d]positive samples', p);
[px, py] = ginput(p);
% plot positive samples
for k=1:p
  plot(px(k), py(k), 'or');
end

% input negative samples
fprintf('\n input [%d]negative samples', q);
[qx, qy] = ginput(q);
% plot negative samples
for k=1:q
  plot(qx(k), qy(k), 'ok');
end

% compute the boundary on max_x x max_y grid
nPt = 40; dW = areaW/nPt; dH = areaH/nPt;
relevance = zeros(nPt, nPt);
for ypt=1:nPt
for xpt=1:nPt
    % compute the relevance at [x y], init
    % process positive samples, "OR" operation    
    relv = zeros(p, 1); 
    for k=1:p
        x = bx(1)+xpt*dW; y = by(1) + ypt*dH;
        d = norm([x y] - [px(k) py(k)]);
        relv(k) = exp(-alpha*d);
    end

    % process negative samples, "OR" operation    
    nrelv = zeros(q, 1); 
    for j=1:q
        x = bx(1)+xpt*dW; y = by(1) + ypt*dH;
        d = norm([x y] - [qx(j) qy(j)]);
        nrelv(j) = exp(-beta*d);
    end
    nrelv = 1 - nrelv; % invert the relevance, "NOT" operation

    % combine results from positive and negative samples    
    positive_relevance(ypt,xpt) = max(relv);
    relevance(ypt,xpt) = min([max(relv) min(nrelv)]);
end
end


figure;
subplot(2,2,1);
colormap('gray');
imagesc(positive_relevance);
axis xy;
title_str = sprintf('%s positive relevance: %s=%1.2f', '\fontsize{12}', '\alpha', alpha);
title(title_str);
xlabel('\fontsize{12}color');
ylabel('\fontsize{12}shape');

subplot(2,2,2);
axis xy;
hold on;
contour([bx(1):dW:bx(2)], [by(1):dH:by(2)], positive_relevance, thres, 'r');
contour([bx(1):dW:bx(2)], [by(1):dH:by(2)], positive_relevance, 0.5, ':b');

% plot positive samples
for k=1:p
  plot(px(k), py(k), '+r');
end
% plot negative samples
for k=1:q
  plot(qx(k), qy(k), 'xk');
end
title_str = sprintf('%s decision boundary: %s=%1.2f', '\fontsize{12}', '\theta', thres);
title(title_str);
xlabel('\fontsize{12}color');
ylabel('\fontsize{12}shape');

subplot(2,2,3);
colormap('gray');
imagesc(relevance);
axis xy;
title_str = sprintf('%s pos+neg relevance: %s=%1.2f, %s=%1.2f', '\fontsize{12}', '\alpha', alpha, '\beta', beta);
title(title_str);
xlabel('\fontsize{12}color');
ylabel('\fontsize{12}shape');

subplot(2,2,4);
axis xy;
hold on;
contour(relevance, thres, 'r');
contour(relevance, 0.5, ':b');

% plot positive samples
for k=1:p
  plot(px(k), py(k), '+r');
end
% plot negative samples
for k=1:q
  plot(qx(k), qy(k), 'xk');
end
title_str = sprintf('%s decision boundary: %s=%1.2f', '\fontsize{12}', '\theta',thres);
title(title_str);
xlabel('\fontsize{12}color');
ylabel('\fontsize{12}shape');






⌨️ 快捷键说明

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