本文是對文章kernel sparse representation with local patterns
for face recognition中2.2節公式的推導
在優化求解中,很多人可能都會見過這個公式:
而根據正則項的不同,l1正則項,l2正則項,可以進行細分:
http://blog.csdn.net/liyuan123zhouhui/article/details/51882926
對於稀疏表示中的稀疏求解:
左邊項是待求解的係數,右邊那一項是正則項,是對解的約束,
是對解的稀疏性的約束,至於爲什麼加這個正則項就會產生稀疏解
可以看看上面的網址
X表示的是字典,bata表示的是稀疏表示係數,lambda是l1正則項的係數
按照2.2節中的公式3:
即,當X的二範數爲1時,其核空間的內積也爲1
對於最優解,採用座標下降法進行求解,那麼將其他
對於正則項的求導,由於是
左邊括號內都大於0:
還有這樣一個約束:
這個約束是因爲
由於
有了l1範數,再自己推導l2範數就簡單了,直接給出結果:
代價函數:
elastic net:
代價函數:
其中:
下面給出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