核稀疏表示公式推導

本文是對文章kernel sparse representation with local patterns
for face recognition中2.2節公式的推導
在優化求解中,很多人可能都會見過這個公式:

minβ12Xβy22

而根據正則項的不同,l1正則項,l2正則項,可以進行細分:
http://blog.csdn.net/liyuan123zhouhui/article/details/51882926

對於稀疏表示中的稀疏求解:

minβ12Xβy22+λβ1

左邊項是待求解的係數,右邊那一項是正則項,是對解的約束,
是對解的稀疏性的約束,至於爲什麼加這個正則項就會產生稀疏解
可以看看上面的網址

X表示的是字典,bata表示的是稀疏表示係數,lambda是l1正則項的係數

按照2.2節中的公式3:φ() 是隱式的特徵映射,將向量映射到核空間中,我們假設該映射滿足以下條件:
φ(x)Tφ(x)=1 when x2=1
即,當X的二範數爲1時,其核空間的內積也爲1
對於最優解,採用座標下降法進行求解,那麼將其他βi(i=1n,ij) 固定,只對βj 進行求偏導數:

0=φ(xj)T[i=1nβiφ(xi)φ(y)]+λsign(βj)

對於正則項的求導,由於是 λ 乘以βj 的l1範數,也就是所有的 β 絕對值的和,那麼求導後就只剩下λβj ,對一個數的絕對值進行求導,得到的就是他的符號函數,對公式進行下一步推導:

0=φ(xj)Tφ(xj)βj+φ(xj)Ti=1,ijnβiφ(xi)φ(y)+λsign(βj)


βj+λsign(βj)=φ(xj)Tφ(y)i=1,ijnβiφ(xi)


(βj+λ)sign(βj)=φ(xj)Tφ(y)i=1,ijnβiφ(xi)

左邊括號內都大於0:

sign(βj)=signφ(xj)Tφ(y)i=1,ijnβiφ(xi)


βj=αλsign(α)

α=φ(xj)Tφ(y)i=1,ijnβiφ(xi)


βj=sign(α)(|α|λ)+

還有這樣一個約束:
(s)+={s,s>00,otherwise

這個約束是因爲sign(α)sign(βj) 的符號是相等的,因此|α|λ 只能夠大於等於0
由於φ() 是核映射,因此,上面的公式在覈空間可以重新寫做:
α=K(xj,y)ni=1,ijβiK(xj,xi)

有了l1範數,再自己推導l2範數就簡單了,直接給出結果:
代價函數:
min12Xβy22+λβ22

βj=K(xj,y)i=1,ijnβiK(xj,xi)/(1+2λ)

elastic net:
代價函數:

min12Xβy22+λβ1+(1λ)β22

βj=sign(α){|α|λ}+(32λ)

其中:
α=φ(xj)Tφ(y)i=1,ijnβiφ(xi)


(s)+={s,s>00,otherwise

下面給出matlab代碼:


function [beta iter] = KernelCoorDescent ( R, Z, opt )

% Kernel Coordinate Descent (KCD) Algorithm Version 1.0
% KCD is for learning sparse representation in kernel space.
%
% Input:
% R = K(X,X) is a P-by-P kernel matrix, where P is the number of samples.
%    For example, R = X' * X in linear case.X是訓練樣本?
% Z = K(X,Y) is a P-by-1 kernel vector. For example, Z = X' * Y in linear
%    case.
% opt is a structure containing options for the algorithm.
% opt.lambda is the parameter for the l1 penality.
% opt.tol is the tolerance for convergence.
% opt.iter_num is the maximum number of iterations.
%
% Output:
% beta: the cofficient vector for the sparse representation
%
% Reference:
%    Cuicui Kang, Shengcai Liao, Shiming Xiang, and Chunhong Pan. 
%    "Kernel Sparse Representation With Pixel-level and Region-level 
%    Image Feature Kernels For Face Recognition", Neurocomputing, 
%    Volume 133, Pages141-152, 2014.
%
% Author: Kang Cuicui
% Email : [email protected]
% Date : 2013/11/20

if isfield( opt, 'lambda')
    lambda  = opt.lambda ;
else
    lambda  = 0.01 ;
end

if isfield( opt, 'tol')
    tol  = opt.tol ;
else
    tol  = 1e-6 ;
end

if isfield( opt, 'iter_num')
    iter_num  = opt.iter_num ;
else
    iter_num  = 50 ;
end

% initializition
[P, N]= size(R);
beta = zeros( N, 1 );

for iter = 1: iter_num

    prebeta = beta;

    for j = 1 : P

        a = Z(j) - R( j, : )*beta;
        a = a + beta(j, :);

        if abs( a ) < lambda        
            beta( j, : ) = 0;        
        else        
            beta( j, : ) = sign( a ).*( abs( a ) - lambda );        
        end

    end

%     if mod ( iter, 5) == 0
%         fprintf('CoorDescent Iteration %d of %d \n', iter, iter_num);
%     end
    if norm(beta-prebeta, 'fro' )/norm(prebeta, 'fro' )  < tol
        break;
    end

end

參考文獻:
kernel sparse representation with local patterns for face recognition
Regularization path for generalized linear models vis coordinate descent

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章