Presentation is loading. Please wait.

Presentation is loading. Please wait.

(recap) Kernel Perceptron

Similar presentations


Presentation on theme: "(recap) Kernel Perceptron"โ€” Presentation transcript:

1 (recap) Kernel Perceptron
If nโ€™ is large, we cannot represent w explicitly. However, the weight vector w can be written as a linear combination of examples: Where ๐›ผ ๐‘— is the number of mistakes made on ๐‘ฅ (๐‘—) Then we can compute f(x) based on {๐‘ฅ (๐‘—) } and ๐œถ

2 (recap) Kernel Perceptron
In the training phase, we initialize ๐œถ to be an all-zeros vector. For training sample (๐‘ฅ (๐‘˜) , ๐‘ฆ (๐‘˜) ), instead of using the original Perceptron update rule in the ๐‘… ๐‘› โ€ฒ space we maintain ๐œถ by based on the relationship between w and ๐œถ :

3 Data Dependent VC dimension
Consider the class of linear functions that separate the data S with margin ยฐ. Note that although both classifiers (wโ€™s) separate the data, they do it with a different margin. Intuitively, we can agree that: Large Margin ๏ƒ  Small VC dimension

4 Generalization

5 Margin of a Separating Hyperplane
A separating hyperplane: wT x+b = 0 Assumption: data is linear separable Distance between wT x+b = +1 and -1 is 2 / ||w|| Idea: Consider all possible w with different angles Scale w such that the constraints are tight Pick the one with largest margin wT xi +bยธ 1 if yi = 1 wT xi +bยท -1 if yi = -1 => ๐‘ฆ ๐‘– ( ๐‘ค ๐‘‡ ๐‘ฅ ๐‘– +๐‘)โ‰ฅ1 wT x+b = 1 wT x+b = 0 wT x+b = -1

6 Maximal Margin min ๐‘ค,๐‘ 1 2 ๐‘ค ๐‘‡ ๐‘ค
The margin of a linear separator wT x+b = 0 is 2 / ||w|| max 2 / ||w|| = min ||w|| = min ยฝ wTw min ๐‘ค,๐‘ ๐‘ค ๐‘‡ ๐‘ค s.t y i (w T x i +๐‘)โ‰ฅ1, โˆ€ ๐‘ฅ ๐‘– , ๐‘ฆ ๐‘– โˆˆ๐‘†

7 Margin and VC dimension
Theorem (Vapnik): If Hยฐ is the space of all linear classifiers in <n that separate the training data with margin at least ยฐ, then VC(Hยฐ) ยท R2/ยฐ2 where R is the radius of the smallest sphere (in <n) that contains the data. This is the first observation that will lead to an algorithmic approach. The second observation is that: Small ||w|| ๏ƒ  Large Margin Consequently: the algorithm will be: from among all those wโ€™s that agree with the data, find the one with the minimal size ||w||

8 Hard SVM Optimization min ๐‘ค 1 2 ๐‘ค ๐‘‡ ๐‘ค
We have shown that the sought after weight vector w is the solution of the following optimization problem: SVM Optimization: (***) This is an optimization problem in (n+1) variables, with |S|=m inequality constraints. min ๐‘ค ๐‘ค ๐‘‡ ๐‘ค s.t y i ( w T x i +๐‘)โ‰ฅ1, โˆ€ ๐‘ฅ ๐‘– , ๐‘ฆ ๐‘– โˆˆ๐‘†

9 Support Vector Machines
The name โ€œSupport Vector Machineโ€ stems from the fact that w* is supported by (i.e. is the linear span of) the examples that are exactly at a distance 1/||w*|| from the separating hyperplane. These vectors are therefore called support vectors. Theorem: Let w* be the minimizer of the SVM optimization problem (***) for S = {(xi, yi)}. Let I= {i: yi (w*Txi + b) = 1}. Then there exists coefficients ยฎi > 0 such that: w* = ๏ƒฅi 2 I ยฎi yi xi This representation should ring a bellโ€ฆ

10 Recap: Perceptron in Dual Rep.
If nโ€™ is large, we cannot represent w explicitly. However, the weight vector w can be written as a linear combination of examples: Where ๐›ผ ๐‘— is the number of mistakes made on ๐‘ฅ (๐‘—) Then we can compute f(x) based on {๐‘ฅ (๐‘—) } and ๐œถ

11 Duality This, and other properties of Support Vector Machines are shown by moving to the dual problem. Theorem: Let w* be the minimizer of the SVM optimization problem (***) for S = {(xi, yi)}. Let I= {i: yi (w*Txi +b)= 1}. Then there exists coefficients ยฎi >0 such that: w* = ๏ƒฅi 2 I ยฎi yi xi

12 Footnote about the threshold
Similar to Perceptron, we can augment vectors to handle the bias term ๐‘ฅ โ‡ ๐‘ฅ , 1 ; ๐‘ค โ‡ ๐‘ค , ๐‘ so that ๐‘ค ๐‘‡ ๐‘ฅ = ๐‘ค ๐‘‡ ๐‘ฅ+๐‘ Then consider the following formulation min ๐‘ค ๐‘ค ๐‘‡ ๐‘ค s.t y i ๐‘ค T ๐‘ฅ i โ‰ฅ1, โˆ€ ๐‘ฅ ๐‘– , ๐‘ฆ ๐‘– โˆˆS However, this formulation is slightly different from (***), because it is equivalent to min ๐‘ค,๐‘ ๐‘ค ๐‘‡ ๐‘ค ๐‘ 2 s.t y i ( ๐‘ค T x i +๐‘)โ‰ฅ1, โˆ€ ๐‘ฅ ๐‘– , ๐‘ฆ ๐‘– โˆˆS The bias term is included in the regularization. This usually doesnโ€™t matter For simplicity, we ignore the bias term

13 Key Issues Computational Issues Is it really optimal?
Training of an SVM used to be is very time consuming โ€“ solving quadratic program. Modern methods are based on Stochastic Gradient Descent and Coordinate Descent. Is it really optimal? Is the objective function we are optimizing the โ€œrightโ€ one?

14 Real Data 17,000 dimensional context sensitive spelling
Histogram of distance of points from the hyperplane In practice, even in the separable case, we may not want to depend on the points closest to the hyperplane but rather on the distribution of the distance. If only a few are close, maybe we can dismiss them. This applies both to generalization bounds and to the algorithm.

15 Soft SVM min ๐‘ค, ๐œ‰ ๐‘– 1 2 ๐‘ค ๐‘‡ ๐‘ค+๐ถ ๐‘– ๐œ‰ ๐‘–
Notice that the relaxation of the constraint: y i w T x i โ‰ฅ1 Can be done by introducing a slack variable ๐œ‰ ๐‘– (per example) and requiring: y i w T x i โ‰ฅ1โˆ’ ๐œ‰ ๐‘– ; ๐œ‰ ๐‘– โ‰ฅ0 Now, we want to solve: min ๐‘ค, ๐œ‰ ๐‘– ๐‘ค ๐‘‡ ๐‘ค+๐ถ ๐‘– ๐œ‰ ๐‘– s.t y i w T x i โ‰ฅ1โˆ’ ๐œ‰ ๐‘– ; ๐œ‰ ๐‘– โ‰ฅ0 โˆ€๐‘– What is the value of slack variable when the data point is classified correctly?

16 Soft SVM (2) min ๐‘ค, ๐œ‰ ๐‘– 1 2 ๐‘ค ๐‘‡ ๐‘ค+๐ถ ๐‘– ๐œ‰ ๐‘–
Now, we want to solve: Which can be written as: min ๐‘ค ๐‘ค ๐‘‡ ๐‘ค+๐ถ ๐‘– max (0, 1โˆ’ ๐‘ฆ ๐‘– ๐‘ค ๐‘‡ ๐‘ฅ ๐‘– ) . What is the interpretation of this? min ๐‘ค, ๐œ‰ ๐‘– ๐‘ค ๐‘‡ ๐‘ค+๐ถ ๐‘– ๐œ‰ ๐‘– s.t ๐œ‰ ๐‘– โ‰ฅ1โˆ’ y i w T x i ; ๐œ‰ ๐‘– โ‰ฅ0 โˆ€๐‘– min ๐‘ค, ๐œ‰ ๐‘– ๐‘ค ๐‘‡ ๐‘ค+๐ถ ๐‘– ๐œ‰ ๐‘– s.t y i w T x i โ‰ฅ1โˆ’ ๐œ‰ ๐‘– ; ๐œ‰ ๐‘– โ‰ฅ0 โˆ€๐‘– In optimum, ฮพ i = max (0, 1โˆ’ y i w T x i )

17 Minw ยฝ ||w||2 + C ๏ƒฅ(x,y) 2 S max(0, 1 โ€“ y wTx)
Soft SVM (3) The hard SVM formulation assumes linearly separable data. A natural relaxation: maximize the margin while minimizing the # of examples that violate the margin (separability) constraints. However, this leads to non-convex problem that is hard to solve. Instead, move to a surrogate loss function that is convex. SVM relies on the hinge loss function (note that the dual formulation can give some intuition for that too). Minw ยฝ ||w||2 + C ๏ƒฅ(x,y) 2 S max(0, 1 โ€“ y wTx) where the parameter C controls the tradeoff between large margin (small ||w||) and small hinge-loss.

18 SVM Objective Function
A more general framework SVM: Minw ยฝ ||w||2 + C ๏ƒฅ(x,y) 2 S max(0, 1 โ€“ y wTx) General Form of a learning algorithm: Minimize empirical loss, and Regularize (to avoid over fitting) Think about the implication of large C and small C Theoretically motivated improvement over the original algorithm weโ€™ve see at the beginning of the semester. Regularization term Empirical loss Can be replaced by other regularization functions Can be replaced by other loss functions

19 Balance between regularization and empirical loss

20 Balance between regularization and empirical loss
(DEMO)

21 Underfitting and Overfitting
Model complexity Expected Error Underfitting Overfitting Variance Bias Simple models: High bias and low variance Complex models: High variance and low bias Smaller C Larger C

22 What Do We Optimize?

23 What Do We Optimize(2)? We get an unconstrained problem. We can use the gradient descent algorithm! However, it is quite slow. Many other methods Iterative scaling; non-linear conjugate gradient; quasi-Newton methods; truncated Newton methods; trust-region newton method. All methods are iterative methods, that generate a sequence wk that converges to the optimal solution of the optimization problem above. Currently: Limited memory BFGS is very popular

24 Optimization: How to Solve
1. Earlier methods used Quadratic Programming. Very slow. 2. The soft SVM problem is an unconstrained optimization problems. It is possible to use the gradient descent algorithm! Still, it is quite slow. Many options within this category: Iterative scaling; non-linear conjugate gradient; quasi-Newton methods; truncated Newton methods; trust-region newton method. All methods are iterative methods, that generate a sequence wk that converges to the optimal solution of the optimization problem above. Currently: Limited memory BFGS is very popular 3. 3rd generation algorithms are based on Stochastic Gradient Decent The runtime does not depend on n=#(examples); advantage when n is very large. Stopping criteria is a problem: method tends to be too aggressive at the beginning and reaches a moderate accuracy quite fast, but itโ€™s convergence becomes slow if we are interested in more accurate solutions. 4. Dual Coordinated Descent (& Stochastic Version)

25 SGD for SVM Initialize ๐‘ค=0โˆˆ ๐‘… ๐‘› 2. For every example x i , y i โˆˆ๐ท
Goal: min ๐‘ค ๐‘“ ๐‘ค โ‰ก ๐‘ค ๐‘‡ ๐‘ค+ ๐ถ ๐‘š ๐‘– max 0, 1โˆ’ ๐‘ฆ ๐‘– ๐‘ค ๐‘‡ ๐‘ฅ ๐‘– m: data size Compute sub-gradient of ๐‘“ ๐‘ค : ๐›ป๐‘“ ๐‘ค =๐‘คโˆ’๐ถ ๐‘ฆ ๐‘– ๐‘ฅ ๐‘– if 1โˆ’ ๐‘ฆ ๐‘– ๐‘ค ๐‘‡ ๐‘ฅ ๐‘– โ‰ฅ0 ; otherwise ๐›ป๐‘“ ๐‘ค =๐‘ค m is here for mathematical correctness, it doesnโ€™t matter in the view of modeling. Initialize ๐‘ค=0โˆˆ ๐‘… ๐‘› 2. For every example x i , y i โˆˆ๐ท If ๐‘ฆ ๐‘– ๐‘ค ๐‘‡ ๐‘ฅ ๐‘– โ‰ค1 update the weight vector to ๐‘คโ† 1โˆ’๐›พ ๐‘ค+๐›พ ๐ถ๐‘ฆ ๐‘– ๐‘ฅ ๐‘– (๐›พ - learning rate) Otherwise ๐‘คโ†(1โˆ’๐›พ)๐‘ค Continue until convergence is achieved Convergence can be proved for a slightly complicated version of SGD (e.g, Pegasos) This algorithm should ring a bellโ€ฆ

26 Nonlinear SVM Primal: Dual: min ๐‘ค, ๐œ‰ ๐‘– 1 2 ๐‘ค ๐‘‡ ๐‘ค+๐ถ ๐‘– ๐œ‰ ๐‘–
We can map data to a high dimensional space: xโ†’๐œ™ ๐‘ฅ (DEMO) Then use Kernel trick: ๐พ ๐‘ฅ ๐‘– , ๐‘ฅ ๐‘— =๐œ™ ๐‘ฅ ๐‘– ๐‘‡ ๐œ™ ๐‘ฅ ๐‘— (DEMO2) Primal: min ๐‘ค, ๐œ‰ ๐‘– ๐‘ค ๐‘‡ ๐‘ค+๐ถ ๐‘– ๐œ‰ ๐‘– s.t y i w T ๐œ™ ๐‘ฅ ๐‘– โ‰ฅ1โˆ’ ๐œ‰ ๐‘– ๐œ‰ ๐‘– โ‰ฅ0 โˆ€๐‘– Dual: min ๐›ผ ๐›ผ ๐‘‡ Q๐›ผโˆ’ ๐‘’ ๐‘‡ ๐›ผ s.t โ‰ค๐›ผโ‰ค๐ถ โˆ€๐‘– Q ๐‘–๐‘— = ๐‘ฆ ๐‘– ๐‘ฆ ๐‘— ๐พ ๐‘ฅ ๐‘– , ๐‘ฅ ๐‘— Theorem: Let w* be the minimizer of the primal problem, ๐›ผ โˆ— be the minimizer of the dual problem. Then w โˆ— = ๐‘– ๐›ผ โˆ— y i x i

27 Nonlinear SVM Tradeoff between training time and accuracy
Complex model v.s. simple model From:

28 At this point these work only for linear kernels
PEGASOS At = S Subgradient method |At| = 1 Stochastic gradient LibSVM has a version that is called LibLinear that implements similar ideas in the dual space. At this point these work only for linear kernels Not a real problem. Subgradient Projection CS446-Spring 10

29 Support Vector Machines โ€“ Short Summary
SVM = Linear Classifier + Regularization + [Kernel Trick]. Typically we are looking for the best w: wopt = argminw ๏ƒฅ1m L(f(x,w,b),y) Where L is a loss function that penalizes f when it makes a mistake. Typically, L is the 0-1 loss (hinge-loss): L(yโ€™, y)= ยฝ |y โ€“ sgn yโ€™| (y, yโ€™ 2 {-1,1}) Just optimizing with respect to the training data may lead to overfitting. We want to achieve good performance on the training while maintaining some notion of โ€œsimpleโ€ hypothesis. We therefore change our goal to: wopt = argminw ๏ƒฅ1m L(f(x,w,b),y) + ๏ฌ R(w) Where L is a loss function, and R is a regularization function, which penalizes w that results in a model that is too complex (high VC dimension). ๏ฌ determines the tradeoff between the empirical error and the regularization.

30 Support Vector Machines โ€“ Short Version
SVM = Linear Classifier + Regularization + [Kernel Trick]. This leads to an algorithm: from among all those wโ€™s that agree with the data, find the one with the minimal size ||w|| Minimize ยฝ ||w||2 Subject to: y(w ยข x + b) ยธ 1, for all x 2 S This is an optimization problem that can be solved using techniques from optimization theory. By introducing Lagrange multipliers ๏ก we can rewrite the dual formulation of this optimization problems as: w = ๏ƒฅi ๏กi yi xi Where the ๏กโ€™s are such that the following functional is maximized: L(๏ก) = -1/2 ๏ƒฅi ๏ƒฅj ๏ก1 ๏กj xi xj yi yj + ๏ƒฅi ๏กi The optimum setting of the ๏กโ€™s turns out to be: ๏กi yi (w ยข xi +b -1 ) = i

31 Support Vector Machines โ€“ Short Version
Dependence on the dot product leads to the ability to introduce kernels (just like in perceptron) What if the data is not linearly separable? What is the difference from regularized perceptron/Winnow? SVM = Linear Classifier + Regularization + [Kernel Trick]. Minimize ยฝ ||w||2 Subject to: y(w ยข x + b) ยธ 1, for all x 2 S The dual formulation of this optimization problems gives: w = ๏ƒฅi ๏กi yi xi Optimum setting of ๏กโ€™s : ๏กi yi (w ยข xi +b -1 ) = i That is, ๏กi :=0 only when w ยข xi +b -1=0 Those are the points sitting on the margin, call support vectors We get: f(x,w,b) = w ยข x +b = ๏ƒฅi ๏กi yi xi ยข x +b The value of the function depends on the support vectors, and only on their dot product with the point of interest x.

32 SVM Notes Chp. 5 of โ€œSupport Vector Machineโ€ [Cristianini and Shawe-Taylor] provides an introduction to the theory of Optimization required in order to understand SVMs.

33 Optimization We are interested in finding the minimum or a maximum of a function, typically subject to some constraints. The general problem is: Minimize f(w), w 2 Rn Subject to gi(w) ยท 0, i=1,โ€ฆk hi(w) = 0, i=1,โ€ฆm An Inequality constraint gi(w) ยท 0 is called active if the solution w* satisfies gi(w*) = 0 An inequality constraint can be transformed into an equality constraint by introducing a slack variable: optimization gi(w) ยท ยด gi(w) + ๏ธi = 0, ๏ธ ยธ 0 CS446-Spring 10

34 Optimization Problems
An optimization problem in which the objective function and the constraints are linear is called a linear program. If the objective function is quadratic and the constraints linear it is called a quadratic program. If the objective function, the constraints and the domain of the functions are convex, that problem is a convex optimization problem. CS446-Spring 10

35 w u f(w) f(u) Convexity A real valued function f(w) is called convex for w 2 Rn if, 8 w,u 2 Rn, and for any a 2 (0,1): f(aw + (1-a)u) ยท af(w) + (1-a) f(u) Claim: If a function is convex, any local minimum w* of the unconstrained optimization problem with objective function f is also a global minimum. Proof: Take any u><w*. By the definition of the local minimum there exists a sufficiently close to 1 that f(w*) ยท f(aw*+ (1-a)u) ยท af(w*) + (1-a) f(u) Where the first inequality is a result of the assumption of local minimum and the second is from the convexity assumption. But that implies (algebra) that f(w*) ยท f(u) This is important. It renders optimization problems tractable when the functions involved are convex. CS446-Spring 10

36 Solving Optimization Problems (1)
Theorem 1. A necessary condition for w* to be a minimum of f 2 C, is df(w*)/d(w) =0. This condition, together with convexity, is also a sufficient solution. CS446-Spring 10

37 Constrained Optimization Problems
Solved by converting constrained problems to unconstrained problems. When the problems are constrained, there is a need to define the Lagrangian function, which incorporates information about both the objective function and the constraints, and which can be used to detect solutions. The Lagrangian is defined as the objective function plus a linear combination of the constraints, where the coefficients of the combination are call the Lagrange multipliers. Given an optimization problem with objective function f(w), and equality constraints hi(w)=0, i=1,โ€ฆ,m, we define the Lagrangian function as: L(w,๏ข) = f(w) + ๏ƒฅi=1m ๏ขi hi(w) where the coefficients ๏ขi are called the Lagrange multipliers. CS446-Spring 10

38 Constrained Optimization Problems (2)
If w* is a local minimum for an optimization problem with only equality constraints, it is possible that df(w*)/d(w) >< 0 (so, w/o constraints it would not be a candidate for extreme point) but that the direction in which we could move to reduce f would violate one or more of the constraints. In order to respect the equality constraints hi we must move in directions that are perpendicular to dhi(w*)/d(w), that is they do not change the constraints. Therefore, in order to respect all the constraints we must move perpendicular to the subspace V spanned by: dhi(w*)/dw, (i =1,m) So, we make the constrained problem be an unconstrained one in which we require that there exists bi such that df(w*)/dw + ๏ƒฅi=1m ๏ขi dhi(w*)/dw = 0 CS446-Spring 10

39 Constrained Optimization Problems (3)
Theorem 2 (Lagrange): A necessary condition for w* to be a minimum for an optimization problem with objective f(w) and equality constraints hi (1,โ€ฆ,m) is: df(w*)/dw + ๏ƒฅi=1m ๏ขi dhi(w*)/dw = 0 For some values ๏ข*. These conditions are also sufficient provided that L(w,๏ข*) is also a convex function of w. Another way to write it is L(w*,๏ข)/dw = L(w*,๏ข)/dw =0 The first condition results in a new system of equations. The second, returns the equality constraints. By solving jointly the two systems, one obtains the solution. CS446-Spring 10

40 Lagrange Theorem: Example
Consider the standard problem of finding the largest volume box with a given surface area. Let the sides of the box be u,v,w. Optimization problem Minimize: - uvw Subject to: wu+uv+vw=c The Lagrangian: L = -uvw + ๏ข(uv+wu+vw-c) Necessary conditions: dL/dw= -uv+๏ข(u+v); dL/du= -wv+๏ข(w+v); dL/dv= -uw+๏ข(u+w) Solving the equations gives ๏ข v(w-u) = ๏ข w (u-v) = 0, implying that the only non trivial solution is w=v=u=(c/3)1/2 CS446-Spring 10

41 Example (Maximum Entropy Distribution)
Suppose we wish to find the discrete probability distribution p= (p1,p2,โ€ฆpn) with maximal entropy H(p) = -๏ƒฅi=1n pi log{pi}. The optimization problem: minimize -H(p), subject to ๏ƒฅi=1n pi =1 L(p,๏ข) = ๏ƒฅi=1n pi log{pi} + ๏ข(๏ƒฅi=1n pi -1 ) Differentiating, we get: log{e pi) + ๏ข = 0 (i=1,โ€ฆn) Which implies that all the pi s are the same p=(1/nโ€ฆ1/n). It is not hard to show that the function H(p) is convex, so the uniform distribution is the global solution. CS446-Spring 10

42 General Optimization Problems
We now move to the general case, where the optimization problem contains both equality and inequality constraints. Define the generalize Lagrangian: L(w,๏ก, ๏ข) = f(w) + ๏ƒฅi=1k ๏กi gi(w) + ๏ƒฅi=1m ๏ขi hi(w) Theorem3(Kuhn-Tucker):Given an optimization problem on Rn: Minimize f(w), w 2 Rn Subject to gi(w) ยท 0, i=1,โ€ฆk hi(w) = 0, i=1,โ€ฆm Necessary and sufficient conditions for w* to be an optimum are the existence of ๏ก*, ๏ข* such that: dL(w*, ๏ก*, ๏ข* )/dw = dL(w*, ๏ก*, ๏ข* )/d๏ข = 0 And ๏กi* gi(w*) = i=1,โ€ฆ,k gi(w*) ยท i=1,โ€ฆ,k ๏กi* ยธ i=1,โ€ฆ,k CS446-Spring 10

43 General Optimization Problems (2)
The last conditions are called KKT: Karush-Kuhn-Tucker conditions. ๏กi* gi(w*) = i=1,โ€ฆ,k gi(w*) ยท i=1,โ€ฆ,k ๏กi* ยธ i=1,โ€ฆ,k It implies that solutions can be in one of two positions with respect to the inequality constraints. Either the solution is in the interior of the feasible region, so that the constraint is inactive (gi(w*) ยท 0) , or on the boundary defined by that constraints, which is active. In the first case, the ๏กi s need to be zero. In the second case, the constraint is active (gi(w*) = 0), and ๏กi can be non-zero. This condition will give rise to the notion of support vectors. CS446-Spring 10


Download ppt "(recap) Kernel Perceptron"

Similar presentations


Ads by Google