參考文獻:Candès, E.J., Li, X., Ma, Y., and Wright, J.: ‘Robust principal component analysis?’, J. ACM, 2011, 58, (3), pp. 11
作者主頁有很多關於low-rank的代碼:http://perception.csl.illinois.edu/matrix-rank/sample_code.html
主要算法公式如下:
關於這個低秩分解的代碼,其實相當簡單:
例如:公式(5-2)對應的代碼為:
S = wthresh(M-L+Y/miu,'s',lambda/miu);
公式(5-3)對應的代碼:
% ---- update L --- %
[U,D,V] = svd(M-S+Y/miu,'econ');
D1 = wthresh(D,'s',1/miu);
L = U*D1*V';
我自己根據公式編寫的代碼如下:
% 求解 argmin rank(L) + ||S||_1 s.t. M = L+S % Reference: Wright, J., Ganesh, A., Rao, S., Peng, Y. and Ma, Y. (2009) % Robust principal component analysis: Exact recovery of corrupted low-rank matrices via convex optimization. % In: Proceedings of Advances in neural information processing systems. 2080-2088. L = zeros(size(M)); S = L; Y = L; norm_two = lansvd(M, 1, 'L'); % computes the K largest singular values. miu = 1.25/norm_two; % miu = 0.1; max_miu = 1e7; lambda = 0.005; rho = 1.5; max_iter = 200; for iter = 1:max_iter % --- update S ----% S = wthresh(M-L+Y/miu,'s',lambda/miu); % ---- update L --- % [U,D,V] = svd(M-S+Y/miu,'econ'); D1 = wthresh(D,'s',1/miu); L = U*D1*V'; Y = Y+miu*(M-L-S); miu = min(max_miu,rho*miu); obj(iter) = norm(M-L-S,'fro')^2; if iter > 2 && abs(obj(iter) - obj(iter-1)) < 1e-7 break; end end figure; imshow(reshape(L(:,80),50,40),[]); title('低秩部分'); figure; imshow(reshape(S(:,80),50,40),[]); title('稀疏部分'); figure; imshow(reshape(M(:,80),50,40),[]); title('原始圖像');
對於AR數據庫,我們對遮擋臉進行了試驗,結果如下:
而同時,我們調用作者主頁編寫的權威代碼得到的結果為:(這里原始文章的代碼下載地址為:鏈接: http://pan.baidu.com/s/1i5m4QrV 密碼: fduh)
這里我們小小總結下調這篇文章算法參數的心得:
1、lambda值越大時,對於lambda約束的矩陣,其值就越小,幾乎為0,矩陣越稀疏,甚至與稀疏到0~~;相反的,另外的那個矩陣則占據主導位置。
所以,在作者原始代碼中,lambda=1/sqrt(m), m為圖像特征維數。經驗:lambda常可取值[0.001,0.01];
2、關於miu這個值,作者用的是miu=1.25/S_L, S_L表示原始矩陣M的最大特征值。miu一般可取0.15等
3、總感覺盡管低秩矩陣可以去掉遮擋,但是是以丟失細節特征為代價。
4、一般而言,遮擋矩陣M中,若全為遮擋臉,那么恢復效果一般比較差,而當存在一些未遮擋臉時,恢復效果會比較好!!