soft thresholding and hard thresholding



今天在看Michael Elad 大牛的論文《On the Role of Sparse and Redundant Representations in Image Processing》中,看到了soft thresholding 和hard thresholding 這兩個概念,很是不明白,所以上網查了一些資料,先把網上查的東西貼出來討論下。

網上資料大體是說這是指兩類的函數,分別是軟閾值函數和硬閾值函數,在matlab中soft thresholding function 的形式是 soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding,其中x代表的的輸入向量或矩陣,T表示閾值,soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding if x<0, soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding if x>=0; hard thresholding function 的形式是 soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding兩者的shrinkage curves 爲下圖:

 

soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding
這兩個thresholding 有什麼用處完全不知道,歡迎知道的朋友告知下,在網上到,好像小波變換的時候有用到它們哥倆,還有什麼去噪什麼的,而我看的Michael的論文提到它們哥倆的時候是在解決優化問題的時候,論文中是這樣的,在解決優化問題soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding

的時候,由於上式加號兩邊的兩項是可分離的(separable)(爲什麼??),the optimization decouples into a set ofindependent scalar problems of the form soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding ,which have particularly simple closed-form solutions in the two notable cases p=0 and p=1, called hard- and soft-thresholding, respectively. 上面是論文上的原話,就是說當p=1的時候,上述優化問題稱爲軟閾值問題,論文中還有個結論就是對於soft thresholding, 閾值應該爲λ,而對於hard thresholding,閾值應該是2倍λ的開根號(不是λ開根號的2倍),到目前爲止完全不懂。在網上又看到了一個叫Simon Lucey的主頁,他裏面講了一些soft thresholding的東西,也弄過來看看,我就不翻譯了,直接上英文:Soft thresholding is becoming a very popular tool in computer vision and machine learning. Essentially it allows one to add to take the following objective:soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding, (和上面的p=1相比,那個0.5可有可無嗎???)and solve in a very fast fashion using an approach referred to as soft thresholding. Since L1 penalties are being used nearly everywhere at the moment, the property of soft thresholding to efficiently find the solution to the above form becomes very useful。
這個叫Simon的傢伙分別使用matlab的凸優化包CVX中的interior point methods 與剛纔講的soft thresholding去解決上面提到的優化問題進行了對比,代碼如下,先使用CVX工具箱,

% Function to solve soft thresholding problem using CVX
%
% arg min_{x} ||x - b||_{2}^{2} + lambda*||x||_{1}
%
% Usage:- x = soft_thresh_cvx
%
% where:- <in>
%         b = bias vector
%         lambda = weighting on the l1 penalty
%         <out>
%         x = solution         
%
% Written by Simon Lucey 2012

% 不得不佩服老外做事的認真嚴謹,隨便寫個函數看上面的註釋就看出來了
function x = soft_thresh_cvx(b,lambda)

M = length(b);
cvx_begin
    cvx_quiet(true);
    variable x(M,1);
    minimize( sum_square(x - b) + lambda*norm(x,1));
cvx_end

根據作者說上述方法很費時,下面貼上使用了soft thresholding方法的code。

先定義soft thresholding operator。


soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding

其實就是本文最開始的時候的soft thresholding function中x=b,T=0.5λ的分段形式,但是這裏的閾值取的卻是0.5λ,這和上文Michael論文中結論說soft thresholding 閾值應該取λ不符,難道是因爲這裏的2範數之前沒有那個1/2的原因嗎??函數代碼如下:

% Function to solve soft thresholding problem
%
% arg min_{x} ||x - b||_{2}^{2} + lambda*||x||_{1}
%
% Usage:- x = soft_thresh
%
% where:- <in>
%         b = bias vector
%         lambda = weighting on the l1 penalty
%         <out>
%         x = solution         
%
% Written by Simon Lucey 2012
function x = soft_thresh(b,lambda)

% Set the threshold
th = lambda/2;

% First find elements that are larger than the threshold
k = find(b > th);
x(k) = b(k) - th;

% Next find elements that are less than abs
k = find(abs(b) <= th);
x(k) = 0;

% Finally find elements that are less than -th
k = find(b < -th);
x(k) = b(k) + th;
x = x(:);

或者上述函數也可以更簡潔的用一句matlab代碼表示:

soft_thresh = @(b,lambda) sign(b).*max(abs(b) - lambda/2,0); %對matlab比較精通的同學可以解釋下。
下面進行對比:

b = [-0.8487   -0.3349    0.5528    1.0391   -1.1176]';
lambda=2;

 

soft_thresh(b, lambda)

ans =

         0
         0
         0
    0.0391
   -0.1176

 

soft_thresh_cvx(b, lambda)

ans =

   -0.0000
   -0.0000
    0.0000
    0.0391
   -0.1176

可以看到,兩者產生的結果完全一樣,我自己也在自己的電腦上試驗了一下,前提是需要安裝斯坦福大學的凸優化解決包CVX,試驗結果和simon的完全一樣,CVX的解決時間爲0.263894秒,而soft thresholding的時間僅僅爲0.002016秒,快了130倍!!!

作者Simon在最後提醒說soft thresholding不能簡單的用來解決下面形式的問題,soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding
我看Michael 的那篇論文中也說了不能上面形式的問題,Michael只是簡單的說由於A的存在,加號兩邊不具有可分離性了,所以不能使用soft thresholding了,而Simon說由於A將x進行了一個空間旋轉,我們不得不使用更慢的CVX來解決上面的問題,但是好消息是最近被證明Augmented Lagragian Methods(不知道什麼東東)可用於避免這一問題,並允許繼續使用高效的soft thresholding。具體的我就不清楚了。。。哎,數學不好害死人啊,什麼時候才能達到大牛們的高度啊。soft <wbr>thresholding <wbr>and <wbr>hard <wbr>thresholding

暫時先寫到這吧,

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