allenlu2007

A great WordPress.com site

Month: February, 2016

Perceptron Learning Algorithm and Stochastic Gradient Descent

by allenlu2007

Please refer to 林軒田’s lecture.

 

好好想一想,以下包含所有的 machine learning 精華!

Step 1 Based on Hypothesis (linear hypothesis, logistic hypothesis, etc.), 如何 optimize w (=> Algorithm A)?  

==> w 基本上是 (xi, yi) 的 linear combination =>   w = sum ( alpha xi yi)  for classification  and sum( alpha xi error(i) ) for linear regression.

where error(i) = (y(i) – f(xi) ) = y(i) – w(i) x(i)

 

在此可以引入 kernel 的觀念:   x -> phi(x)  w -> w_new

w_new = sum( alpha yi phi(xi) )

 

Step 2: 如何重組回 Hypothesis function, H or f(x)

==> 最簡單是 f(x) = w’x = sum( beta yi xi x ) 

如果有 kernel

==>  f(x) = sum( beta yi phi(x) phi(xi))   phi(x) * phi(xi) 就是 similarity 的測量!!  Linear 只是 inner product.  也可以用 Gaussian kernel (RBF)

 

重點在 beta (weighting) -> 這是由 w or w_new 在 learning 時決定的。 On-line learning 則可以 dynamically 修改。

如果 beta(i) = 0 則代表非 supporting vector (不重要!)  所以 SVM 是 special case.  

SVM 以及 L1 error 可以造成 sparsity ==>  可以省下 testing 和 CV 時的 computation effort!!!!

 

如果是 linear regression

f(x) = w’ x= sum( beta (yi – w’ xi) xi x ) = sum ( beta yi xi x – w’ xi xi x )  ==>  Need more derivation to confirm linear regression case!! 

 

 

 

 

——————-

 

I like the perceptron learning algorithm (PLA) idea.

It’s very geometric and intuitive!!!!

同時可以比較 PLA, Logistic Regression, and SVM!!!

 

Gradient descent, especially apply to logistic regression, can be regarded as soft PLA!

Actually, not gradient descent, but stochastic gradient descent.

 

General form:

PLA

w(n+1) = w(n) + (error) * (yn zn)

or 

w_pla = sum(beta_n (yn zn))  n from 1 to N (data)    beta is mistake correction #

 

Logistic Regression

w(n+1) = w(n) + soft_error * (yn zn)

or 

w_logisticregression = sum( E(??) * (yn zn))


注意如果是 linear regression, 其實是一樣 (stochastic gradient descent)

w_lin(n+1) = w_lin(n) + alpha * ( error ) * zn

where error = ( y(n) – w_lin(n)’ zn ) 


SVM 

wsvm = sum( alpha(n) * (yn zn))  from 1 to N (data), only support vectors

也就是非 support vector 根本不影響 w 的變化。

 

w_pla = sum(beta_n* (yn zn))

PLA 是用容易犯錯的點來表示。SVM 是用 support vector (也是容易犯錯的點) 來表示!

 

f(x) = sum( a_i yi (xi’ x) + b )

 

w => linear combination of yn zn (beta_n), 同時 yn zn 愈近 boundary, beta_n 愈大 

 

這也順便 link representer theorem and Kernel method.

For any L2-regularized cost/loss function in terms of zn * yn (or linear model)

w* = linear combination of zn * yn. 

==> 可以 apply kernel trick!

 

L1 regularize 就不行?  對!  因為在 proof 用到 垂直正交 = 0 的特性。也就是L2切線的特性 (微分=0)。

但在 L1 卻是 vertex (simplex) 的特性。所以 L2 regularized 的特性是 sparsity 而非 微分=0!!!

 

L2-regularized  ===  Kernel!!!

L1-regularized <<<<>>> kernel!!!

 

Kernel can be applied to :

SVM – L2 regularized inherent 

Linear regression with L2

Logistic regression with L2

PLA with L2

 

 

 

 

Some Idea from Ng Video

by allenlu2007

 

1. Gradient descent formula for linear regression and logistic regression are identifcal

except h_theata definition is different.   Why the gradient formula are the same?  

 

2. Why go neural net?  XOR –> perception or logistic regression can not classify.  But neural net can.

So the key is to do island classification?

=> machine learning and topology relationship????

 

Very interesting topic:  neural network, topology and manifold.

http://colah.github.io/posts/2014-03-NN-Manifolds-Topology/

Different Classification Based on Square Loss, L1 loss, Hinge Loss, and Entropy Loss

by allenlu2007

 

Classification 可以用不同的方式來做。

可以統一從 loss function 來解釋。

事實上不論 regression (continuous output) 或是 classification (discrete output) 都可以用 loss function 來解釋。所以 loss function 是比較 general learning 的觀念。

所以 regression 和 classification 本質上的差異是什麼?

就我而言,classification 多引入了一個 decision boundary 的觀念。在 testing/predicting 時,只要看是在那一個 decision boundary 可以決定是那一個 class.  這在數位通訊也是非常 critical 的觀念 (symbol detection).    

此處都是假設所有的 data sample 都是 independent generated.  所以 decision boundary 可以適用。如果不同 data 之間有 correlation, 仍然可以用 decision boundary (?) 只是要 expand 到更高維空間? 例如通訊中的 convolution code or trellis code.  此處忽略不考慮。

如何決定 decision boundary? 

傳統通訊的 decision boundary 是 a priori.  因為我們事先知道所有傳送的 symbol. 

當然一般還是會有 training phase, 先送一些已知的 structured data (training symbol) 來校正 receiver 的 decision boundary; 或是 equalization (比較像 regression).  以後有機會用 machine learning 在通訊上?  (DDR 似乎開始用 data training boundary).  一般要求的 error rate ~ 10^-3 – 10^-12, 可以說要求非常準確。

在 machine learning 中,no surprise, decision boundary 是由一堆 training data 所 train/learn 出來。最佳的 boundary 常常是任意 shape.  我們只是用簡單的 function 來逼近 decision boundary.  一般沒有 structured data 來校正 decision boundary,  多少都有一些主觀 depending on picked loss function, picked feature space, etc.  一般要求的 error rate ~ 幾 % to tens of %.  可以容忍一些 error.

 

 

先假設沒有 outliner 的 case.

Square loss classification:  all samples has equal importance –> far away sample may shift decision boundary significantly –> bad

NewImage

 

 

 

 

L1 loss classification: same as above –> but less penalty for far away sample to shift decision boundary, yes?  It seems to be better than square loss!

 

Hinge loss (SVM):  only supporting vector (near to the decision boundary) has impact on decision boundary!!

 

Entropy Loss (Logistic / softmax): only points close to boundary has largest impact on the decision boundary!!

 

如果有 outliner 的 case.

1. square loss –> penalty is square, very bad

2. L1 loss –> penalty is linear, still bad

4. Entropy loss –> log (exp), similar to L1 loss, still bad

3. hinge loss –> sill to L1 loss, still bad

 

==> square loss is extremely bad;  The rest seems to be similar (L1).

 

 

Least Square Application – Adaptive Filter (Special case of Kalman Filter)

by allenlu2007

本文主要參考 University of Delaware EE-636: Statistical Signal Processing and another.

 

前文 (Least Square and Least Norm 以及 Least Square with Regularization) 提到 LS 的公式以及應用。

主要是 data fitting (under-fit).  本文主要討論 LS 在 signal processing (filtering) 的應用。

 

幾點 summary:

* LS filtering 是 deterministic method.

* LS 對應 ML criterion if the error have a Gaussian distribution (之前已解釋)

* LS is related to linear regression

 

LS Filtering

考慮以下的 linear transversal filter (FIR filter), w (filter) 就是要 train 出的 filter.

w 是 M-tap filter.   d(i) 則是 desired response (可以是事先決定的 training pattern).  

NewImage

Input u(i) 是 d(i) 經過 channel model 以及 additive noise 之後的結果。

Objective:   minimize

NewImage

每一個 e(i) 都是 wx[i]  inner product 的結果。Note x[i] 是一個 vector.   

 

LS 問題是求解 min ||Ax-b||2,   w 相當於 x (short column vector, 需要求解), dim(w) = M.

A 必須是 tall matrix.  Reference 用的 notation 是 minimize (d’ – w’ A’)(d – A w)

d (desired vector), 相當於 b (long column vector).  取的 size 是 (N-M+1) x 1. 

為什麼不是 N x 1 而是 (N-M+1)?  因為以上 M-tap FIR filter 在初始時的 M-1 registers 都是 0, 而非 input data u(i).  需要等到 M-1 time step 之後才會得到真實的 error signal.  

當然需要 (N-M+1) > M 才符合 LS 的 criterion.  

M 是 features, N-M+1 是 data samples.  N-M+1 > M 代表 underfit; 可做 LS. 

 

NewImage 

NewImage 

 

所以 LS optimization 就是 minimize error vector 如下:

NewImage

一如預期: w 是 A 的 left inverse and linear with d. 

 

(1) 附贈 physical insight 就是 A’ ϵ(w) = A’ (Aw – d) = 0  -> Orthogonal principle or innovation process

dim(A’)=Mx(N-M+1) dim(w)=Mx1 dim(d)=N-M+1 => 以上代表 M equations=0

同時有 M 個未知 w’ = [w1, w2, …, w(M)] => 可以解出 w

e.g.  

x(M).e(M) + x(M+1).e(M+1)+ ..  x(N).e(N) = 0

x(M-1).e(M-1)+… + x(N-1)e(N-1)  = 0

x(1).e(1)+ .. + x(N-M+1).e(N-M+1)  = 0

where

e(i) = d(i) – w’ x(i)

 

意即 minimize || Aw-d ||2 = (Aw-d)’ (Aw-d)  雖然無法為 0 (因為 A 是 tall, underfit, matrix)

但至少 A’ (Aw-d) = 0!!  

LS orthogonality principle: estimated error  Aw-d (dim=(N-M+1)) ⊥ A’ ( M x (N-M+1) )

注意即使 A 是 fat, overfit, matrix,  Aw-d=0 成立。因此 A’ (Aw-d) = 0 也成立!

因此 A'(Aw-d) = 0 is true regardless A 是 tall, square, or fat matrix.

A'(Aw-d) 稱為 innovation process, 可由導數為 0 得到。  


如果 A 是 fat, overfit, matrix, 則可以找到無數多 w such that (Aw-d)'(Aw-d)=0.  此時反而要加上 regularization ( min ||w||2, Tikhonov regularization)  才能有唯一解 

 

(2) 另一個看法是從 statistics 角度來看。w =  (auto-correlation)^(-1) * (cross-correlation)

auto-correlation = A’ A   (A 是 observed data matrix including noise, A’A 就是 auto-correlation)

cross-correlation = A’ d   (d 是 desired output, A’ d 就是 cross-correlation)

這是非常 general 的概念: ranging from Kalman filter, MLE, …

 

NewImage

 

(3) LS filter 同時也是 minimum error energy filter

因為 objective function 就是 minimize error energy function

採自前文 LS primal:  p* = b’ [ I – A(A’A)^(-1)A’ ] b

b’b 是 desired energy.  [ I – A(A’A)^(-1)A’ ] 是 estimation error in percentage.

 

NewImage

 

再回到 orthogonality principle:

NewImage

Φ 是 auto-correlation function 或是 time average correlation matrix. 

Φ 是 PSD 而且一般是 PD and invertable.

NewImage

NewImage

 

  

Adaptive Filter

以上提到 LS filter 的各種優點。包含 minimal error energy filter, best linear unbiased estimate (BLUE) filter, etc.  

一個實務的問題是 input data 是 sequential input, 很難等到所有 data 都收集到之後才解 w (FIR filter).  

另一個更重要的因素是 input data 的特性是 time-varying (e.g. wireless channel, time varying noise, etc.).  因此最佳的 LS filter 會隨著時間改變。因此 w 也應該隨時間改變,也就是 adaptive filter. 

兩種常見的 adaptive filter:  LS and RLS (recursive least square) based on normal equation, LMS (least mean square) based on gradient descent.  LS and RLS 是 deterministic; LMS 則是 stochastic.

有兩種不同的角度來看 adaptive filter: (1) 從 statistics 角度; 以及 (2) machine learning 角度。

 

Statistics 詮釋

假設 desired d(i) 是一個  linear system 同時包含 unobservable measurement error (or noise).

注意 x(i) 假設是固定值,因此 A 也是固定值。但 w 因為 eo 的關係則包含 random error. 

NewImage

 

按照之前  d^ = Aw  and  ϵ = d – d^  =>  ϵ ⊥ A  and ϵ ⊥ d^

 

下一步是 estimate bias of w^ = (A’A)^(-1) A’ d

w^ = wo + (A’A)^(-1)A’ ϵo

E{w^} = wo

 

cov{w^} = σ^2 * Φ^-1

where Φ = A’ A  (A 是 tall matrix)

cov{w^} 和 σ^2 成正比符合預期。但和 Φ^(-1) 而非 Φ 正相關則需要思考一下。

 

RLS Filter

NewImage

以上只是重新表述 LS filter 求解。如前所述,我們要找到一個 recursive 方法來解上述 equation.

(1) 意即 w(n+1) can be expressed in terms of w(n)

(2) 舊的 data 顯然影響力要變小。變小的幅度要可控制。這可透過 forgetting factor β 控制。重點是加在 loss/error function 中。如果 β=1 是傳統的 RLS, 只適合在 stationary statistics system.  如果  β<1 稱為 discounted or modified RLS, 可以用在 time varying statistics system.

NewImage

一個常用的 forgetting factor 就是 exponential forgetting factor

NewImage

因為 error function 引入 λ, 連帶原來的 normal equation 也變成:

NewImage

 

NewImage

NewImage

NewImage

此處就有 Kalman filter 的 fu~.   k(n) 類似 Kalman gain;  P(n) 類似 covariance.

重點是 P(n) = Φ^(-1)(n)

 

NewImage

NewImage

NewImage

 

同樣用 Kalman filter analogy.  α(n) 就是 prediction error; e(n) 就是 correction error.

 

Refresh Kalman filter 包含:

State equation:

1. X(k)=F X(k-1)+G U(k)+W(k)   (covariance Q)

Measurement:

2. Z(k)=H X(k)+V(k)   (covariance R)

=> F=1, G=0, H=x(n), Q=0, R = σ^2 (因為 V(k) = ϵ(k) = d(k) – x(k) w(k)’ ) 
=> X(k) = w(n)
=> Z(k) = d(k) 
=> V(k) = Z(k) – H X(k) = d(k) – x(k) w(k) = ϵ(k)   zero mean and σ^2 variance

Kalman filter 的 solution:

X(k|k-1)=F X(k-1|k-1)+G U(k) ……….. (1) 
P(k|k-1)=F P(k-1|k-1) F’+Q ……… (2)  
X(k|k)= X(k|k-1)+Kg(k) (Z(k)-H X(k|k-1)) ……… (3)  
Kg(k)= P(k|k-1) H’ / (H P(k|k-1) H’ + R) ……… (4)  
P(k|k)=(I-Kg(k) H)P(k|k-1) ……… (5)

 

w(k|k-1) = w(k-1)  …  (1)

P(k|k-1) = P(k-1|k-1) … (2)

w(k) = w(k|k) = w(k-1) + Kg(k) (d(k) – w(k-1)’ x(k) ) … (3)

Kg(k) = P(k-1) x(k) / ( x(k)’ P(k-1) x(k) + σ^2 )   … (4)

P(k) = P(k-1)Kg(k) x(k) P(k-1) … (5)

以上說明傳統的 RLS 是 Kalman filter 的特例。 不過 H=x(k), Z(k)=d(k) 比較出人意外。

 

比較 discounted RLS (with forgetting factor) 如下。

(Discounted) RLS in summary

NewImage

可以看到 Kalman filter 和 discounted RLS (with forgetting factor) 有差異。

1. Equation (4) 的 𝜎^2 變為 1.  基本上是 P(n) 被 normalized 和 𝜎^2 無關。所以 R = 1??

2. Kalman filter 是處理 dynamic system,  x(n+1) = A x(n) + B u(n), 只要 A and B 是準確的,就可以 track dynamic system correctly.    

在一般的 RLS (λ=1) system 中,w(n) = w(n-1) + k(n) α*(n), target static system (因為 A = 1) 沒有問題。

但如果在 slowly changing dynamic system, 例如在一開始的 transient 過程,或是之後 x(n) 有些改變。如果堅持 A=1 without any dynamic factor.  可能會讓收歙的速度變慢或是 loss track.  因此引入 forgetting factor,  λ.  讓最新民意佔比較大的影響力。

可以參考 recursive identification 一文。 

3.  Kalman filter 直觀上相當於傳統的 RLS, 所以表示 discounted RLS 比較好嗎?  No.  如果用 Kalman filter 處理 dynamic system, A ≠ 1, 而應該用 position, velocity matrix, 可參考前文 (Kalman filter and water tank).

 

In summary:

  • Kalman filter: Track a moving object (estimate its location and velocity at each time), assuming that velocity at current time is velocity at previous time plus Gaussian noise). Use a sequence of location observations coming in sequentially.

  • Recursive LS: Keep updating estimate of location of an object that is static. Use a sequence of location observations coming in sequentially.

  • Discounted Recursive LS with forgetting factor: object not static but drifts very slowly.

 

 

LMS Filter

RLS filter 雖然看來有很多優點: (1) Recursively (不需要等所有 data samples); (2) adaptive tracking dynamic change (with forgetting factor); (3) Computation ~ M^2, 已經比 LS ~ M^3 好很多,但在 feature space (M) or FIR tap 大的時候,非常慢。

但 RLS 最大的缺點: (1) computation 量大,需要計算 matrix inversion; (2) stability and 收歙性的問題。

LMS filter 最大的好處是 computation 少很多。同時只需要 local information, 也非常 robust to model error, noise, etc. 

說 LMS 之前,必須先談 gradient descent (GD).   GD 也是需要等所有 data samples 才能計算。實務上也不可能。因此才有 LMS, 對應 stochastic gradient descent. 

wo = Φ^(-1) θ    where Φ is auto-correlation;  θ is cross-correlation

GD, LMS 基本上都不用 matrix inversion 來算 w.  LS, RLS 則是需要計算 matrix inversion (or simplified algorithm 來算 w.  

NewImage 

NewImage

再重覆之前的推導:

e(n) = d(n) – d^(n) = d(n) – w(n)’ x(n) 

MSE at time n

J(n) = E{|e(n)|^2} = σd^2 – w(n)’ p + p’ w(n) + w(n)’ R w(n) 

where

σd^2 – variance of desired signal

p – cross-correlation between x(n) and d(n)

R – auto-correlation matrix of x(n)


對這 quadratic function 的 optimal (Wiener) solution,

w(n) = wo = R^(-1) p

J(n) = Jmin =  σd^2 – p’ wo =  σd^2 – p’ R^(-1) p

NewImage

如何能在不計算 matrix inversion (R^(-1)) 情況下,仍能求得最佳的 w* 以及 J*?

1. 前述如果要等全部 data ready (R and p) 才做 matrix inversion, 在實務上很多時候不可行。

2. 解決方法之一是 recursive LS.  可以每多一個 data sample 就 update w.  就像 Kalman filter.  最大的問題是仍需要算 matrix inversion (recursively), computation 量還是太大。同時也要 a priori error surface (global information).

解決之道是只用 local information, iteratively approach optimal solution 如上圖 contour plot.

w(n+1) = w(n) + 1/2 μ [-∇J(n)]

∇J(n) = -2p + 2 R w(n)

w(n+1) = w(n) + μ [ p – R w(n) ]   where μ 是 step size, 或是 learning rate

μ 太大有可能 unstable; μ 太小則收歙慢。

μ 必須小於 eigenvalue of R 才能 guaranteeing stability (Widrow).

有一整套的理論如何選取 μ 以及其他 的參數,可以參考本文

  

 

我們可以從 machine learning 角度來看 adaptive filtering. 

基本上是 linear regression with least square loss function.

可以引入 learning rate concept.

有兩種做法,recursive and stochastic gradient descent, 對應的就是 RLS 和 LMS.

 

Difference Between RLS or LMS

首先是算法本身。RLS 是 based on a priori error; LMS 是 based on a posteriori error.

RLS 的 gain 是 based on minimize least square error;  LMS 的 μ 則是比較 heuristics. 

NewImage

 

再就 algorithm 本身的複雜度比較 (M 是 FIR filter tap number; or feature dimension in machine learning).

LMS:

NewImage

LS: 

NewImage

 

RLS:

NewImage

 

Andrew Ng 做了一個簡單的比較。 Normal equation 主要是指 LS, 不過也適用 RLS.

Gradient descent 是指 LMS.  另一個重點是 gradient descent 可用於各種 loss function (square loss, L1 loss, hinge loss, cross-entropy loss).  Normal equation 主要是 square loss!

所以 gradient descent, e.g. LMS 算法非常重要。

 

NewImage

 

 

LMS -> learning is done by stochastic gradient descent

RLS -> Recursive least square -> iterative gradient descent

 

1. Signal recovery problem:  Wiener fileter

2. 

 

 

LS with L2

iterative filter

Kalman filter

Wiener filter

LMS

 

Physical meaning of primal and dual

L1 regularization – Lasso

by allenlu2007

Total Variation method (TV)

Lasso

compressed sensing

under-determined linear system

sparsity

….

Lapacial noise

..

Lots of applications using L1 norm now.

 

 

L2 – least square, least norm, LMS, Kalman filtering….

 

L1 and L2 mixing

L2 filtering – LMS or Kalman filter

 

NewImage

Least Square with Regularization

by allenlu2007

本文參考 Kim’s “An Interior-Point Method for Large-Scale L1-Regularized Least Squares

 

先說結論:

Least square with regularization primal problem 如下 (一般 n < k, overfit)

NewImage

where A is fat matrix.  dim(A) = n x k;  dim(x) = k x 1;  dim(b) = n x 1

如果 n > k, underfit 也行,不過不大 make sense.  因為已經 underfit.  例如前文 linear regression, 如果為了 minimize ||x||2 而讓直線偏一些,就會造成 least square error 大量增加。因此在 n > k (under fit) 情況下增加 regularization term 並不會改變原來的 solution 太多。

相反在 k > n, overfit 情況下,滿足 ||Ax-y||=0 的 solution 很多,regularization 此時 play an important role to nail down the solution. 

 

Dual problem 就是 unconstraint quadratic function 而非 least square linear function (underfit)

因為 unconstraint, 同時 A’A or AA’ 看那一個是 full rank.   不論 n > k or n < k or n =k 都 ok.

 

標準的 Least Square 如下

NewImage

dim(A) = n x k  (n >> k), i.e. tall matrix

dim(x) = k x 1;  dim(b) = n x 1

標準的 LS 是 underfit.

 

Analytic solution: 

NewImage

A’A  (dim=k x k) 是 PSD matrix.  假設A’A 是 full rank 所以 invertible.  但若 eigenvalue 太小,收歙上仍可能 非常慢。

 

 

Regularization 在 Optimization 是常用的技巧

NewImage

為什麼要加上 regularization? 

 

* 要解決 overfit 的問題!!

 當有太多的 x 可以滿足 Ax = b  (i.e. || Ax-b || 是 minimum), 要挑最小的 norm (L1 or L2?)

==>  所以原先 underfit 的 A (tall matrix), 突然不適用!!!  反而是變成類似 least norm 問題,但不要求 Ax=b.

  此時 A 是 fat matrix, n x k.   k > n

 

* 為何 regularization 可以解決 overfit 的問題?

1. SNR 觀點:  yn (w’ xn + b) > = 1  where yn = +1 or -1.  

因此 |wn| 愈小,代表 |xn| cos(theta) 愈大。xn 基本上是定值,所以 cos(theta) 變大,也就是 xn 在 decision boundary 的法向量投影愈大,也就是 margin 最大。在有 noise 的時候,仍可以 reliably detect/classify。或許會疑惑 overfit 和  noise 有什麼關係。可以參考林軒田教授的 ML foundation lecture.

Model complexity (due to overfit) 可以視為 deterministic noise.  因此 regularization by minimize |w| 所造出的 margin 可以對抗 overfit 的問題。

 

2. Model complexity 觀點: 同樣參考林軒田的 lectures.  Regularization 的效果是等效 VC (Vanpnik .) dimension 變小。根據 learning theory (請參林軒田 lecture), regularization 雖然不會讓 in-sample error 變小,但會讓 out-sample error 變小,這非常重要。也是 learning theory 最 critical 的部份。

 

 

其他的 regularization 的用途:

* Prior knowledge:  ||x||  is small.  (Baysian view)

* Small signal optimal design:  Ax ~ b holds when x is small

* Robust design:  || (A + ΔA) x – b || = || Ax -b + ΔA.x ||.   Robust design when x is small

 

 

Tikhonov (L2) Regularization

 

NewImage

NewImage

因為 I 的關係,A’A + λI 為 PD, 不論 A 是 tall or fat matix.  所以 matrix 一定是 invertible, 同時收歙會更好。

如果 λ -> 0, 變成 LS optimization, A 必須是 tall matrix.  

 

Lagrange dual

以下是 Lagrange dual 的推導,假設 L2 norm regularization (minimum energy).  

如果是用 L1 norm regularization (下文,x 會是 sparsity vector). 

NewImage

以上是 Lagrange dual.  再來是找 maximum point 如下。

注意 x 是 linear function of b!! 代表 L2 regularization 得到 linear filter!  

NewImage

補充一下如何把 λ(AA’ + λI)^(-1)  變成 I – A(A’A+λI)^(-1)A’

NewImage

 

再補充一下如何 left inverse = right inverse.  注意這並非 in general true, 只有在以下 two conditions hold.

NewImage

 

以下是包含 kernel, 參考 Rifkin “Regularized Least-Squares Classification

NewImage

 

 

L1-Regularization

可以參考 Kim and Boyd “An Interior-Point Method for Large-Scale L1-Regularized Least Squares

NewImage

 L1 norm 沒有 close form.  但可用 quadratic programming.  

可用 Matlab 求解。見 reference.

 

Lagrange dual

 在做 dual 之前,可以把 (3) 變得更 general 如 (5).  如果 λi = λ.  (5) 就變為 (3).

NewImage

因為沒有 constraint, 所以先製造 equality constraints.

NewImage

 

NewImage

注意在 minimize 過程中,可得到 z + v = 0 ;  x 則是用 z = Ax – y 得出。    

 

另一個推導見於見 reference.

注意上面的 eq. (10) 和 下面的 eq. (5) 有些不同。 Eq. (10) 來自上面的 Eq. (5), 是假設 weighted L1 regularization.  下面的 eq. (5) 則是假設 global L1 regularization. 

NewImage

NewImage

以上的 z 就是前文的 v.    r  + z = 0  =>  r = -z  => r = Ax -b =>  -z = Ax – b => solve x as above!!

注意 x 並非 linear function of b, 因為 z 是由 QP 決定!!!  這是 L1 和 L2 重要的差別!

在後文 filter 可看出。

 

Least Square with L1 or L2 Regularization?

L2 regularization 是 LS 最常用的 regularization.  部份的原因和 L2 norm 的歷史有關。

數學上漂亮且有 close form, 還有 iterative solution (Kalman filter, LMS).  同時對於 low pass signal + Gaussian noise or Gaussian signal (e.g. match filter) 是 optimal controller (Wiener filter, Kalman filter).

L1 regularization 長久以來都只是 publication purpose.  並無實際用途。

但 Stanford Boyd group 以及其他 researchers driver L1 norm/regularization 在解法 (convex optimization) 以及 large scale 算法,以及很多實際的應用 (compressed sensing, medical imaging, sparse signal processing).  請見另文討論。

以下為 a sparse signal recovery example.

x ∈ R(4096), 包含 160 spikes of +1 or -1, 如下圖。  

A ∈ R(1024×4096) 是 fat matrix, overfit. 

y = Ax + v   v ~ N(0, 0.01^2 I) on R(1024).  

NewImage 

LS filter with L2 and L1 norm regularization 結果分別如下圖。第一圖是用 L2 regularization (minimum energy).  第二圖是用 L1 regularization.  

Signal process 中 x (4096) -> y (1024) 是個 decimation or under-sampling process, 同時加上 gaussian noise.   傳統的 signal processing 中有 Nyquist sampling theorem, 可以看到原始的 signal spikes 需要很高的 over-sampling 才有可能 recovery x.  此處不但沒有 over-sampling, 反而是 under-sampling.

如果使用 LS with L2 regularization 類似傳統的 LMS filter.  Recovered signal 如下第一圖,沒有任何的 signal.

神奇的是如果使用 LS with L1 regularization,  recovered signal 如下第二圖,幾乎可以恢復原來的 x.

這似乎完全違背 Nyquist sampling theorem!!!

關鍵是:

1. Sparsity: 請見 Wiki compressed sensing.  Candes, Tao, Donoho 証明在 sparsity condition, 可以用少量的 sample to reconstruct original signal.

2. Nyquist sampling theorem 只是 sufficient condition, 而不是 necessary condition.  例如對於 bandpass signal, 也可以 under-sampling.  同樣對於 sparsity signal, 也可以 reconstruct orignal signal.  不過不是用 LS with L2 regularization!!

3. 為什麼 L1 regularization 比 L2 regularization 適合 sparsity signal 或高頻信號或影像信號?

高頻或影像信號在 L2 regularization 都會造成很大的 penalty.  L1 則是 a lot better.  當然這只是 hand-waving 解釋。影像信號包含很多 edge (高頻), L1 似乎比較好。同時 L2 似乎容易有 aliasing problem. 

NewImage 

 

 

Questions:

1. How about CVBS, AHD, CVI, etc.  use L1 regularization

2. How about mixed L1 and L2? 

   * Not use LS, but use Huber loss function?

   * Mixed L1 and L2 regulariation

3. Re-weighted, iterative L1 regularization?

Legendre Transform and Lagrange Dual

by allenlu2007

 

* Both of them are defined in convex functions

* Both of them can be generalized to non-convex function but extended to convex hull

* Legendre transform is more general and (sort of) unique   f(x) -> f*(v) -> f(x).   f*(v) is conjugate function.

* Lagrange dual is only for minimum value equivalent; depending on the constraints, Lagrange dual can be more than one.

* Lagrange dual can utilize conjugate function.

 

Young-Fenchel inequality

Fenchel duality theorem