diff --git a/doc/pub/svm/html/._svm-bs000.html b/doc/pub/svm/html/._svm-bs000.html index 85f83e77f..e08dfbbfe 100644 --- a/doc/pub/svm/html/._svm-bs000.html +++ b/doc/pub/svm/html/._svm-bs000.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -187,7 +194,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs001.html b/doc/pub/svm/html/._svm-bs001.html index 37297f5b7..399026d80 100644 --- a/doc/pub/svm/html/._svm-bs001.html +++ b/doc/pub/svm/html/._svm-bs001.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -166,8 +173,14 @@ classification problems) of variables. It is also used for regression problems.

    -With SVMs we distinguish between hard margin and soft margins. The latter introduces a so-called softening parameter to be discussed below. -We distinguish also between linear and non-linear approaches. The latter are the most frequent ones since it is rather unlikely that we can separate classes easily by say straight lines. +With SVMs we distinguish between hard margin and soft margins. The +latter introduces a so-called softening parameter to be discussed +below. We distinguish also between linear and non-linear +approaches. The latter are the most frequent ones since it is rather +unlikely that we can separate classes easily by say straight lines. + +

    +Note: several figures are missing. They will be added shortly. To run the codes, use the jupyter notebook

    @@ -186,7 +199,7 @@ We distinguish also between linear and non-linear approaches. The latter are the

  • 10
  • 11
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs002.html b/doc/pub/svm/html/._svm-bs002.html index 5db305100..07b5be673 100644 --- a/doc/pub/svm/html/._svm-bs002.html +++ b/doc/pub/svm/html/._svm-bs002.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -177,7 +184,7 @@ circles.
  • 11
  • 12
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs003.html b/doc/pub/svm/html/._svm-bs003.html index 109fd8cb1..bb33133ca 100644 --- a/doc/pub/svm/html/._svm-bs003.html +++ b/doc/pub/svm/html/._svm-bs003.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -187,7 +194,7 @@ $$
  • 12
  • 13
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs004.html b/doc/pub/svm/html/._svm-bs004.html index bd6abfe12..b60f9cb67 100644 --- a/doc/pub/svm/html/._svm-bs004.html +++ b/doc/pub/svm/html/._svm-bs004.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -203,7 +210,7 @@ When we try to separate hyperplanes, if it exists, we can use it to construct a
  • 13
  • 14
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs005.html b/doc/pub/svm/html/._svm-bs005.html index 8c3337f06..58e847731 100644 --- a/doc/pub/svm/html/._svm-bs005.html +++ b/doc/pub/svm/html/._svm-bs005.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -189,7 +196,7 @@ for our data sample.
  • 14
  • 15
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs006.html b/doc/pub/svm/html/._svm-bs006.html index 2f72c0129..db52ab566 100644 --- a/doc/pub/svm/html/._svm-bs006.html +++ b/doc/pub/svm/html/._svm-bs006.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -185,7 +192,7 @@ $$
  • 15
  • 16
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs007.html b/doc/pub/svm/html/._svm-bs007.html index 10ed2ca41..b748b5532 100644 --- a/doc/pub/svm/html/._svm-bs007.html +++ b/doc/pub/svm/html/._svm-bs007.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -189,7 +196,7 @@ $$
  • 16
  • 17
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs008.html b/doc/pub/svm/html/._svm-bs008.html index 08dfd1a31..48006344a 100644 --- a/doc/pub/svm/html/._svm-bs008.html +++ b/doc/pub/svm/html/._svm-bs008.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -193,7 +200,7 @@ at all.
  • 17
  • 18
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs009.html b/doc/pub/svm/html/._svm-bs009.html index 13e415077..80dfee3db 100644 --- a/doc/pub/svm/html/._svm-bs009.html +++ b/doc/pub/svm/html/._svm-bs009.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -205,7 +212,7 @@ We have thus defined our margin as the invers of the norm of \( \boldsymbol{w} \
  • 18
  • 19
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs010.html b/doc/pub/svm/html/._svm-bs010.html index ff49403d1..e8cac7084 100644 --- a/doc/pub/svm/html/._svm-bs010.html +++ b/doc/pub/svm/html/._svm-bs010.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -217,7 +224,7 @@ Then \( dz \) is no longer arbitrary.
  • 19
  • 20
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs011.html b/doc/pub/svm/html/._svm-bs011.html index 9c274b1b3..260e4471a 100644 --- a/doc/pub/svm/html/._svm-bs011.html +++ b/doc/pub/svm/html/._svm-bs011.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -210,7 +217,7 @@ $$
  • 20
  • 21
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs012.html b/doc/pub/svm/html/._svm-bs012.html index d5deef96a..c73530b2f 100644 --- a/doc/pub/svm/html/._svm-bs012.html +++ b/doc/pub/svm/html/._svm-bs012.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -208,7 +215,7 @@ When \( \lambda_i > 0 \), the vectors \( \boldsymbol{x}_i \) are called support
  • 21
  • 22
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs013.html b/doc/pub/svm/html/._svm-bs013.html index d67cdc39e..999868c65 100644 --- a/doc/pub/svm/html/._svm-bs013.html +++ b/doc/pub/svm/html/._svm-bs013.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -191,7 +198,7 @@ subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vec
  • 22
  • 23
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs014.html b/doc/pub/svm/html/._svm-bs014.html index d132c80e9..b56b6ce36 100644 --- a/doc/pub/svm/html/._svm-bs014.html +++ b/doc/pub/svm/html/._svm-bs014.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -200,6 +207,8 @@ Below we discuss how to find the optimal values of \( \lambda_i \). Before we pr
  • 22
  • 23
  • 24
  • +
  • ...
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs015.html b/doc/pub/svm/html/._svm-bs015.html index b87cc8e72..6fc1126c9 100644 --- a/doc/pub/svm/html/._svm-bs015.html +++ b/doc/pub/svm/html/._svm-bs015.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -200,6 +207,9 @@ misclassifications.
  • 22
  • 23
  • 24
  • +
  • 25
  • +
  • ...
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs016.html b/doc/pub/svm/html/._svm-bs016.html index ef073b5cf..7ae6500f9 100644 --- a/doc/pub/svm/html/._svm-bs016.html +++ b/doc/pub/svm/html/._svm-bs016.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -218,6 +225,8 @@ $$
  • 22
  • 23
  • 24
  • +
  • 25
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs017.html b/doc/pub/svm/html/._svm-bs017.html index 8df569d0b..b832478ce 100644 --- a/doc/pub/svm/html/._svm-bs017.html +++ b/doc/pub/svm/html/._svm-bs017.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -186,6 +193,8 @@ we need to introduce for example a polynomial transformation to a two-dimensiona
  • 22
  • 23
  • 24
  • +
  • 25
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs018.html b/doc/pub/svm/html/._svm-bs018.html index dd6ac5476..072d3320b 100644 --- a/doc/pub/svm/html/._svm-bs018.html +++ b/doc/pub/svm/html/._svm-bs018.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -147,15 +154,15 @@ MathJax.Hub.Config({

    The equations

    -Suppose we define a polynomial transformation of degree two (we continue to live in a plane with \( x_1 \) and \( x_2 \) as variables) +Suppose we define a polynomial transformation of degree two only (we continue to live in a plane with \( x_i \) and \( y_i \) as variables) $$ -z = \phi(x) =\left(1, x_1, x_2, x_1^2, x_2^2, x_1x_2). +z = \phi(x_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right). $$

    With our new basis, the equations we solved earlier are basically the same, that is we have now (without the slack option for simplicity) $$ -{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{z}_i^T\boldsymbol{Z}_j, +{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{z}_j, $$ subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \), and for the support vectors @@ -164,6 +171,17 @@ y_i(\boldsymbol{w}^T\boldsymbol{z}_i+b)= 1 \hspace{0.1cm}\forall i, $$ from which we also find \( b \). +To compute \( \boldsymbol{z}_i^T\boldsymbol{Z}_j \) we define the kerne \( K(\boldsymbol{x}_i,\boldsymbol{x}_j) \) as +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\boldsymbol{z}_i^T\boldsymbol{Z}_j= \phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). +$$ + +For the above example, the kernel reads +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=[x_i^2, y_i^2, \sqrt{2}x_iy_i]^T\begin{bmatrix} x_j^2 \\ y_j^2 \\ \sqrt{2}x_jy_j \end{bmatrix}=x_i^2x_j^2+2x_ixJy_iy_j+y_i^2y_j^2. +$$ + +We note that this is nothing but the dot product of the two original vectors \( (\boldsymbol{x}_i^T\boldsymbol{x}_j)^2 \). Instead of thus computing the product in the Lagrangian of \( \boldsymbol{x}_i^T\boldsymbol{z}_j \) we simply compute the dot product \( (\boldsymbol{x}_i^T\boldsymbol{x}_j)^2 \). This leads to the so-called kernel trick and the result leads to the same as if we went through the trouble of performing the transformation \( (\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j) \) during the SVM calculations.

    @@ -186,6 +204,8 @@ from which we also find \( b \).

  • 22
  • 23
  • 24
  • +
  • 25
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs019.html b/doc/pub/svm/html/._svm-bs019.html index 52686a402..a94b303c3 100644 --- a/doc/pub/svm/html/._svm-bs019.html +++ b/doc/pub/svm/html/._svm-bs019.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -144,7 +151,38 @@ MathJax.Hub.Config({ -

    Different kernels

    +

    The problem to solve

    +Using our definition of the kernel We can rewrite again the Lagrangian +$$ +{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{z}_j, +$$ + +subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \) in terms of a convex optimization problem +$$ +\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1K(\boldsymbol{x}_1,\boldsymbol{x}_1) & y_1y_2K(\boldsymbol{x}_1,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_1,\boldsymbol{x}_n) \\ +y_2y_1\boldsymbol{x}_2^T\boldsymbol{x}_1 & y_2y_2\boldsymbol{x}_2^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_2^T\boldsymbol{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\boldsymbol{x}_n,\boldsymbol{x}_1) & y_ny_2K(\boldsymbol{x}_n\boldsymbol{x}_2) & \dots & \dots & y_ny_nK(\boldsymbol{x}_n,\boldsymbol{x}_n) \\ +\end{bmatrix}\boldsymbol{\lambda}-\mathbb{I}\boldsymbol{\lambda}, +$$ + +subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vectors \( \boldsymbol{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and +\( \boldsymbol{y}=[y_1,y_2,\dots,y_n] \). +If we add the slack constants this leads to the additional constraint \( 0\leq \lambda_i \leq C \). + +

    +We can rewrite this (see the solutions below) in terms of a convex optimization problem of the type +$$ +\begin{align*} + &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{\lambda}=f. +\end{align*} +$$ + +Below we discuss how to solve these equations. Here we note that the matrix \( \boldsymbol{P} \) has matrix elements \( p_{ij}=y_iy_jK(\boldsymbol{x}_i,\boldsymbol{x}_j) \). +Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up. The constraint \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \) leads to \( f=0 \) and \( \boldsymbol{A}=\boldsymbol{y} \). How to set up the matrix \( \boldsymbol{G} \) is discussed later. Here note that the inequalities \( 0\leq \lambda_i \leq C \) can be split up into +\( 0\leq \lambda_i \) and \( \lambda_i \leq C \). These two inequalities define then the matrix \( \boldsymbol{G} \) and the vector \( \boldsymbol{h} \).

    @@ -166,6 +204,8 @@ MathJax.Hub.Config({

  • 22
  • 23
  • 24
  • +
  • 25
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs020.html b/doc/pub/svm/html/._svm-bs020.html index fee529438..d6b10f85a 100644 --- a/doc/pub/svm/html/._svm-bs020.html +++ b/doc/pub/svm/html/._svm-bs020.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -144,7 +151,33 @@ MathJax.Hub.Config({ -

    Quadratic coefficient matrix

    +

    Different kernels and Mercer's theorem

    + +

    +There are several popular kernels being used. These are + +

      +
    1. Linear: \( K(\boldsymbol{x},\boldsymbol{y})=\boldsymbol{x}^T\boldsymbol{y} \),
    2. +
    3. Polynomial: \( K(\boldsymbol{x},\boldsymbol{y})=(\boldsymbol{x}^T\boldsymbol{y}+\gamma)^d \),
    4. +
    5. Gaussian Radial Basis Function: \( K(\boldsymbol{x},\boldsymbol{y})=\exp{\left(-\gamma\vert\vert\boldsymbol{x}-\boldsymbol{y}\vert\vert^2\right)} \),
    6. +
    7. Tanh: \( K(\boldsymbol{x},\boldsymbol{y})=\tanh{(\boldsymbol{x}^T\boldsymbol{y}+\gamma)} \),
    8. +
    + +and many other ones. + +

    +An important theorem for us is "Mercer's theorem":https://en.wikipedia.org/wiki/Mercer%27s_theorem". +The theorem states that if a kernel function \( K \) is symmetric, continuous and leads to a positive semi-definite matrix \( \boldsymbol{P} \) then +there exists a function \( \phi \) that maps \( \boldsymbol{x}_i \) and \( \boldsymbol{x}_j \) into another space +(possibly with much higher dimensions) such that +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). +$$ + +So you can use \( K \) as a kernel since you know \( \phi \) exists, even if +you don’t know what \( \phi \) is. +Note that some frequently used kernels (such as the Sigmoid kernel) don’t respect all of Mercer’s conditions, yet they generally work +well in practice.

    @@ -165,6 +198,8 @@ MathJax.Hub.Config({

  • 22
  • 23
  • 24
  • +
  • 25
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs021.html b/doc/pub/svm/html/._svm-bs021.html index d855421d5..516500727 100644 --- a/doc/pub/svm/html/._svm-bs021.html +++ b/doc/pub/svm/html/._svm-bs021.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -142,9 +149,29 @@ MathJax.Hub.Config({

     

     

     

    - + -

    Mercer's theorem

    +

    Mathematical optimization of convex functions

    + +

    +A mathematical (quadratic) optimization problem, or just optimization problem, has the form +$$ +\begin{align*} + &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{\lambda}=f. +\end{align*} +$$ + +subject to some constraints for say a selected set \( i=1,2,\dots, n \). +In our case we are optimizing with respect to the Lagrangian multipliers \( \lambda_i \), and the +vector \( \boldsymbol{\lambda}=[\lambda_1, \lambda_2,\dots, \lambda_n] \) is the optimization variable we are dealing with. + +

    +In our case we are particularly interested in a class of optimization problems called convex optmization problems. +In our disussion on gradient descent methods we discussed at length the definition of a convex function. + +

    +Convex optimization problems play a central role in applied mathematics and we recommend strongly Boyd and Vandenberghe's text on the topics.

    @@ -164,6 +191,8 @@ MathJax.Hub.Config({

  • 22
  • 23
  • 24
  • +
  • 25
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs022.html b/doc/pub/svm/html/._svm-bs022.html index 2c44ea8be..4244211c1 100644 --- a/doc/pub/svm/html/._svm-bs022.html +++ b/doc/pub/svm/html/._svm-bs022.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -144,25 +151,28 @@ MathJax.Hub.Config({ -

    Mathematical optimization of convex functions

    +

    How do we solve these problems?

    -A mathematical optimization problem, or just optimization problem, has the form -$$ -\mathrm{minimize}\hspace{0.1cm} f(x), -$$ - -subject to some constraints \( g(\lambda_i) \leq b_i \) for say a selected set \( i=1,2,\dots, n \). -In our case we are optimizing with respect to the Lagrangian multipliers \( \lambda_i \), and the -vector \( \boldsymbol{\lambda}=[\lambda_1, \lambda_2,\dots, \lambda_n] \) is the optimization variable we are dealing with. -and \( f(x) \) is our objective function while \( g(\lambda_i) \leq b_i \) represents our constraint function. +If we use Python as programming language and wish to venture beyond +scikit-learn, tensorflow and similar software which makes our +lives so much easier, we need to dive into the wonderful world of +quadratic programming. We can, if we wish, solve the minimization +problem using say standard gradient methods or conjugate gradient +methods. However, these methods tend to exhibit a rather slow +converge. So, welcome to the promised land of quadratic programming.

    -In our case we are particularly interested in a class of optimization problems called convex optmization problems. -In our disussion on gradient descent methods we discussed at length the definition of a convex function. +The functions we need are contained in the quadratic programming package CVXOPT and we need to import it together with numpy as

    -Convex optimization problems play a central role in applied mathematics and we recommend strongly Boyd and Vandenberghe's text on the topics. + + +

    import numpy
    +import cvxopt
    +
    +

    +This will make our life much easier. You don't need t write your own optimizer.

    @@ -181,6 +191,8 @@ Convex optimization problems play a central role in applied mathematics and we r

  • 22
  • 23
  • 24
  • +
  • 25
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/._svm-bs023.html b/doc/pub/svm/html/._svm-bs023.html new file mode 100644 index 000000000..d223dbeb0 --- /dev/null +++ b/doc/pub/svm/html/._svm-bs023.html @@ -0,0 +1,267 @@ + + + + + + + +Data Analysis and Machine Learning: Support Vector Machines + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    A simplex example

    + +

    +We remind ourselves about the general problem we want to solve +$$ +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}\boldsymbol{x}^T\boldsymbol{P}\boldsymbol{x}+\boldsymbol{q}^T\boldsymbol{x},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{x} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{x}=f. +\end{align*} +$$ + +

    +Let us show how to perform the optmization using a simple case. Assume we want to optimize the following problem +$$ +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}x^2+5x+3y \\ \nonumber + &\mathrm{subject to} \\ \nonumber + &x, y \geq 0 \\ \nonumber + &x+3y \geq 15 \\ \nonumber + &2x+5y \leq 100 \\ \nonumber + &3x+4y \leq 80. \\ \nonumber +\end{align*} +$$ + +The minimization problem can be rewritten in terms of vectors and matrices as (with \( x \) and \( y \) being the unknowns) +$$ +frac{1}{2}\begin{bmatrix} x\\ y \end{bmatrix}^T \begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix}3\\ 4 \end{bmatrix}^T \begin{bmatrix}x \\ y \end{bmatrix}. +$$ + +Similarly, we can now set up the inequalities (we need to change \( \geq \) to \( \leq \) by multiplying with \( -1 \) on bot sides) as the following matrix-vector equation +$$ +\begin{bmatrix} -1 & 0 \\ 0 & -1 \\ -1 & -3 \\ 2 & 5 \\ 3 & 4\end{matrix}\begin{bmatrix} x \\ y\end{bmatrix} \preceq \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +$$ + +We have collapsed all the inequalities into a single matrix \( \boldsymbol{G} \). We see also that our matrix +$$ +\boldsymbol{P} =\begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} +$$ + +is clearly positive semi-definite (all eigenvalues larger or equal zero). +Finally, the vector \( \boldsymbol{h} \) is defined as +$$ +\boldsymbol{h} = \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +$$ + +

    +Since we don't have any equalities the matrix \( \boldsymbol{A} \) is set to zero +The following code does this for us +

    + + +

    # Import the necessary packages
    +import numpy
    +from cvxopt import matrix
    +from cvxopt import solvers
    +# Define QP parameters (directly)
    +P = matrix([[1.0,0.0],[0.0,0.0]])
    +q = matrix([3.0,4.0])
    +G = matrix([[-1.0,0.0,-1.0,2.0,3.0],[0.0,-1.0,-3.0,5.0,4.0]])
    +h = matrix([0.0,0.0,-15.0,100.0,80.0])
    +# Define QP parameters (with NumPy)
    +P = matrix(numpy.diag([1,0]), tc=’d’)
    +q = matrix(numpy.array([3,4]), tc=’d’)
    +G = matrix(numpy.array([[-1,0],[0,-1],[-1,-3],[2,5],[3,4]]), tc=’d’)
    +h = matrix(numpy.array([0,0,-15,100,80]), tc=’d’)
    +# Construct the QP, invoke solver
    +sol = solvers.qp(P,q,G,h)
    +# Extract optimal value and solution
    +sol[’x’] 
    +sol[’primal objective’]
    +
    +

    +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/svm/html/._svm-bs024.html b/doc/pub/svm/html/._svm-bs024.html new file mode 100644 index 000000000..6dcd0583d --- /dev/null +++ b/doc/pub/svm/html/._svm-bs024.html @@ -0,0 +1,215 @@ + + + + + + + +Data Analysis and Machine Learning: Support Vector Machines + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    Back to the more realistic cases

    + +

    +We are now ready to return to our setup of the optmization problem for a more realistic case. Introducint the slack parameter \( C \) we have +$$ +\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1K(\boldsymbol{x}_1,\boldsymbol{x}_1) & y_1y_2K(\boldsymbol{x}_1,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_1,\boldsymbol{x}_n) \\ +y_2y_1\boldsymbol{x}_2^T\boldsymbol{x}_1 & y_2y_2\boldsymbol{x}_2^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_2^T\boldsymbol{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\boldsymbol{x}_n,\boldsymbol{x}_1) & y_ny_2K(\boldsymbol{x}_n\boldsymbol{x}_2) & \dots & \dots & y_ny_nK(\boldsymbol{x}_n,\boldsymbol{x}_n) \\ +\end{bmatrix}\boldsymbol{\lambda}-\mathbb{I}\boldsymbol{\lambda}, +$$ + +subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vectors \( \boldsymbol{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and +\( \boldsymbol{y}=[y_1,y_2,\dots,y_n] \). +With the slack constants this leads to the additional constraint \( 0\leq \lambda_i \leq C \). + +

    +code will be added + +

    +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/svm/html/._svm-bs025.html b/doc/pub/svm/html/._svm-bs025.html new file mode 100644 index 000000000..6a1bdc7ab --- /dev/null +++ b/doc/pub/svm/html/._svm-bs025.html @@ -0,0 +1,195 @@ + + + + + + + +Data Analysis and Machine Learning: Support Vector Machines + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +

     

     

     

    + + + + +

    Multiclass problems and regression with SVMs

    +This material will be added later. + +

    + +

    + + +
    + + + + + + + +
    + +
    + + + + + + diff --git a/doc/pub/svm/html/svm-bs.html b/doc/pub/svm/html/svm-bs.html index 85f83e77f..e08dfbbfe 100644 --- a/doc/pub/svm/html/svm-bs.html +++ b/doc/pub/svm/html/svm-bs.html @@ -61,14 +61,19 @@ Automatically generated HTML file from DocOnce source ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -124,11 +129,13 @@ MathJax.Hub.Config({
  • Soft optmization problem
  • Kernels and non-linearity
  • The equations
  • -
  • Different kernels
  • -
  • Quadratic coefficient matrix
  • -
  • Mercer's theorem
  • -
  • Mathematical optimization of convex functions
  • -
  • How do we solve these problems
  • +
  • The problem to solve
  • +
  • Different kernels and Mercer's theorem
  • +
  • Mathematical optimization of convex functions
  • +
  • How do we solve these problems?
  • +
  • A simplex example
  • +
  • Back to the more realistic cases
  • +
  • Multiclass problems and regression with SVMs
  • @@ -187,7 +194,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 24
  • +
  • 26
  • »
  • diff --git a/doc/pub/svm/html/svm-reveal.html b/doc/pub/svm/html/svm-reveal.html index 77ba1ed41..3916fb6df 100644 --- a/doc/pub/svm/html/svm-reveal.html +++ b/doc/pub/svm/html/svm-reveal.html @@ -181,8 +181,14 @@ classification problems) of variables. It is also used for regression problems.

    -With SVMs we distinguish between hard margin and soft margins. The latter introduces a so-called softening parameter to be discussed below. -We distinguish also between linear and non-linear approaches. The latter are the most frequent ones since it is rather unlikely that we can separate classes easily by say straight lines. +With SVMs we distinguish between hard margin and soft margins. The +latter introduces a so-called softening parameter to be discussed +below. We distinguish also between linear and non-linear +approaches. The latter are the most frequent ones since it is rather +unlikely that we can separate classes easily by say straight lines. + +

    +Note: several figures are missing. They will be added shortly. To run the codes, use the jupyter notebook @@ -829,10 +835,10 @@ we need to introduce for example a polynomial transformation to a two-dimensiona

    The equations

    -Suppose we define a polynomial transformation of degree two (we continue to live in a plane with \( x_1 \) and \( x_2 \) as variables) +Suppose we define a polynomial transformation of degree two only (we continue to live in a plane with \( x_i \) and \( y_i \) as variables)

     
    $$ -z = \phi(x) =\left(1, x_1, x_2, x_1^2, x_2^2, x_1x_2). +z = \phi(x_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right). $$

     
    @@ -840,7 +846,7 @@ $$ With our new basis, the equations we solved earlier are basically the same, that is we have now (without the slack option for simplicity)

     
    $$ -{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{z}_i^T\boldsymbol{Z}_j, +{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{z}_j, $$

     
    @@ -852,39 +858,117 @@ $$

     
    from which we also find \( b \). +To compute \( \boldsymbol{z}_i^T\boldsymbol{Z}_j \) we define the kerne \( K(\boldsymbol{x}_i,\boldsymbol{x}_j) \) as +

     
    +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\boldsymbol{z}_i^T\boldsymbol{Z}_j= \phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). +$$ +

     
    + +For the above example, the kernel reads +

     
    +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=[x_i^2, y_i^2, \sqrt{2}x_iy_i]^T\begin{bmatrix} x_j^2 \\ y_j^2 \\ \sqrt{2}x_jy_j \end{bmatrix}=x_i^2x_j^2+2x_ixJy_iy_j+y_i^2y_j^2. +$$ +

     
    + +We note that this is nothing but the dot product of the two original vectors \( (\boldsymbol{x}_i^T\boldsymbol{x}_j)^2 \). Instead of thus computing the product in the Lagrangian of \( \boldsymbol{x}_i^T\boldsymbol{z}_j \) we simply compute the dot product \( (\boldsymbol{x}_i^T\boldsymbol{x}_j)^2 \). This leads to the so-called kernel trick and the result leads to the same as if we went through the trouble of performing the transformation \( (\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j) \) during the SVM calculations.

    -

    Different kernels

    -
    +

    The problem to solve

    +Using our definition of the kernel We can rewrite again the Lagrangian +

     
    +$$ +{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{z}_j, +$$ +

     
    +subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \) in terms of a convex optimization problem +

     
    +$$ +\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1K(\boldsymbol{x}_1,\boldsymbol{x}_1) & y_1y_2K(\boldsymbol{x}_1,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_1,\boldsymbol{x}_n) \\ +y_2y_1\boldsymbol{x}_2^T\boldsymbol{x}_1 & y_2y_2\boldsymbol{x}_2^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_2^T\boldsymbol{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\boldsymbol{x}_n,\boldsymbol{x}_1) & y_ny_2K(\boldsymbol{x}_n\boldsymbol{x}_2) & \dots & \dots & y_ny_nK(\boldsymbol{x}_n,\boldsymbol{x}_n) \\ +\end{bmatrix}\boldsymbol{\lambda}-\mathbb{I}\boldsymbol{\lambda}, +$$ +

     
    -

    -

    Quadratic coefficient matrix

    -
    - - -
    -

    Mercer's theorem

    -
    - - -
    -

    Mathematical optimization of convex functions

    +subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vectors \( \boldsymbol{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and +\( \boldsymbol{y}=[y_1,y_2,\dots,y_n] \). +If we add the slack constants this leads to the additional constraint \( 0\leq \lambda_i \leq C \).

    -A mathematical optimization problem, or just optimization problem, has the form +We can rewrite this (see the solutions below) in terms of a convex optimization problem of the type

     
    $$ -\mathrm{minimize}\hspace{0.1cm} f(x), +\begin{align*} + &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{\lambda}=f. +\end{align*} $$

     
    -subject to some constraints \( g(\lambda_i) \leq b_i \) for say a selected set \( i=1,2,\dots, n \). +Below we discuss how to solve these equations. Here we note that the matrix \( \boldsymbol{P} \) has matrix elements \( p_{ij}=y_iy_jK(\boldsymbol{x}_i,\boldsymbol{x}_j) \). +Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up. The constraint \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \) leads to \( f=0 \) and \( \boldsymbol{A}=\boldsymbol{y} \). How to set up the matrix \( \boldsymbol{G} \) is discussed later. Here note that the inequalities \( 0\leq \lambda_i \leq C \) can be split up into +\( 0\leq \lambda_i \) and \( \lambda_i \leq C \). These two inequalities define then the matrix \( \boldsymbol{G} \) and the vector \( \boldsymbol{h} \). +

    + + +
    +

    Different kernels and Mercer's theorem

    + +

    +There are several popular kernels being used. These are + +

      +

    1. Linear: \( K(\boldsymbol{x},\boldsymbol{y})=\boldsymbol{x}^T\boldsymbol{y} \),
    2. +

    3. Polynomial: \( K(\boldsymbol{x},\boldsymbol{y})=(\boldsymbol{x}^T\boldsymbol{y}+\gamma)^d \),
    4. +

    5. Gaussian Radial Basis Function: \( K(\boldsymbol{x},\boldsymbol{y})=\exp{\left(-\gamma\vert\vert\boldsymbol{x}-\boldsymbol{y}\vert\vert^2\right)} \),
    6. +

    7. Tanh: \( K(\boldsymbol{x},\boldsymbol{y})=\tanh{(\boldsymbol{x}^T\boldsymbol{y}+\gamma)} \),
    8. +
    +

    + +and many other ones. + +

    +An important theorem for us is "Mercer's theorem":https://en.wikipedia.org/wiki/Mercer%27s_theorem". +The theorem states that if a kernel function \( K \) is symmetric, continuous and leads to a positive semi-definite matrix \( \boldsymbol{P} \) then +there exists a function \( \phi \) that maps \( \boldsymbol{x}_i \) and \( \boldsymbol{x}_j \) into another space +(possibly with much higher dimensions) such that +

     
    +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). +$$ +

     
    + +So you can use \( K \) as a kernel since you know \( \phi \) exists, even if +you don’t know what \( \phi \) is. +Note that some frequently used kernels (such as the Sigmoid kernel) don’t respect all of Mercer’s conditions, yet they generally work +well in practice. +

    + + +
    +

    Mathematical optimization of convex functions

    + +

    +A mathematical (quadratic) optimization problem, or just optimization problem, has the form +

     
    +$$ +\begin{align*} + &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{\lambda}=f. +\end{align*} +$$ +

     
    + +subject to some constraints for say a selected set \( i=1,2,\dots, n \). In our case we are optimizing with respect to the Lagrangian multipliers \( \lambda_i \), and the vector \( \boldsymbol{\lambda}=[\lambda_1, \lambda_2,\dots, \lambda_n] \) is the optimization variable we are dealing with. -and \( f(x) \) is our objective function while \( g(\lambda_i) \leq b_i \) represents our constraint function.

    In our case we are particularly interested in a class of optimization problems called convex optmization problems. @@ -896,7 +980,7 @@ Convex optimization problems play a central role in applied mathematics and we r

    -

    How do we solve these problems

    +

    How do we solve these problems?

    If we use Python as programming language and wish to venture beyond @@ -908,7 +992,8 @@ methods. However, these methods tend to exhibit a rather slow converge. So, welcome to the promised land of quadratic programming.

    -The functions we need are contained in the quadratic programming package CVXOPT and we need to import it +The functions we need are contained in the quadratic programming package CVXOPT and we need to import it together with numpy as +

    @@ -916,32 +1001,71 @@ The functions we need are contained in the quadratic programming package CVXO import cvxopt

    -Let us first set up the standard form the of quadratic programming (QP) equations by defining the problem as +This will make our life much easier. You don't need t write your own optimizer. +

    + + +
    +

    A simplex example

    + +

    +We remind ourselves about the general problem we want to solve

     
    $$ -\mathrm{min} +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}\boldsymbol{x}^T\boldsymbol{P}\boldsymbol{x}+\boldsymbol{q}^T\boldsymbol{x},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{x} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{x}=f. +\end{align*} $$

     

    -subject to Gx u. Note that x itself is not provided to the solver, since it is an internal -variable being optimized over. In particular, this means that the solver has no explicit knowledge -of x itself; everything is implicity defined by the supplied parameters. It is essential -that the same variable order is maintained for the relevant parameters (e.g., qi -Non-convexity implies the existence of local optima, making it difficult to find global optima. +Let us show how to perform the optmization using a simple case. Assume we want to optimize the following problem +

     
    +$$ +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}x^2+5x+3y \\ \nonumber + &\mathrm{subject to} \\ \nonumber + &x, y \geq 0 \\ \nonumber + &x+3y \geq 15 \\ \nonumber + &2x+5y \leq 100 \\ \nonumber + &3x+4y \leq 80. \\ \nonumber +\end{align*} +$$ +

     
    + +The minimization problem can be rewritten in terms of vectors and matrices as (with \( x \) and \( y \) being the unknowns) +

     
    +$$ +frac{1}{2}\begin{bmatrix} x\\ y \end{bmatrix}^T \begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix}3\\ 4 \end{bmatrix}^T \begin{bmatrix}x \\ y \end{bmatrix}. +$$ +

     
    + +Similarly, we can now set up the inequalities (we need to change \( \geq \) to \( \leq \) by multiplying with \( -1 \) on bot sides) as the following matrix-vector equation +

     
    +$$ +\begin{bmatrix} -1 & 0 \\ 0 & -1 \\ -1 & -3 \\ 2 & 5 \\ 3 & 4\end{matrix}\begin{bmatrix} x \\ y\end{bmatrix} \preceq \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +$$ +

     
    + +We have collapsed all the inequalities into a single matrix \( \boldsymbol{G} \). We see also that our matrix +

     
    +$$ +\boldsymbol{P} =\begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} +$$ +

     
    + +is clearly positive semi-definite (all eigenvalues larger or equal zero). +Finally, the vector \( \boldsymbol{h} \) is defined as +

     
    +$$ +\boldsymbol{h} = \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +$$ +

     

    -collapsed all inequality constraints into a single G matrix of the standard form. -Since there are no equality constraints, we do not need to provide the empty A, b. Note -that even though y -2 did not appear in the original objective, we had to include it with zero -coefficients in P because the solver parameters must be defined using the full set of variables. -Even if certain variables only appear in constraints, they will still need to be expressed with -zero coefficients in the objective parameters, and vice versa. -Let us first define the above parameters in Python. CVXOPT supplies its own matrix -object; all arguments given to its solvers must be in this matrix type. There are two ways -to do this. The first is to define the matrix directly with (potentially nested) lists: -from cvxopt import matrix +Since we don't have any equalities the matrix \( \boldsymbol{A} \) is set to zero +The following code does this for us

    @@ -962,12 +1086,43 @@ h = matrix(numpy.array([0,# Construct the QP, invoke solver sol = solvers.qp(P,q,G,h) # Extract optimal value and solution -sol[x] # [7.13e-07, 5.00e+00] +sol[x] sol[primal objective]

    +
    +

    Back to the more realistic cases

    + +

    +We are now ready to return to our setup of the optmization problem for a more realistic case. Introducint the slack parameter \( C \) we have +

     
    +$$ +\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1K(\boldsymbol{x}_1,\boldsymbol{x}_1) & y_1y_2K(\boldsymbol{x}_1,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_1,\boldsymbol{x}_n) \\ +y_2y_1\boldsymbol{x}_2^T\boldsymbol{x}_1 & y_2y_2\boldsymbol{x}_2^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_2^T\boldsymbol{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\boldsymbol{x}_n,\boldsymbol{x}_1) & y_ny_2K(\boldsymbol{x}_n\boldsymbol{x}_2) & \dots & \dots & y_ny_nK(\boldsymbol{x}_n,\boldsymbol{x}_n) \\ +\end{bmatrix}\boldsymbol{\lambda}-\mathbb{I}\boldsymbol{\lambda}, +$$ +

     
    + +subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vectors \( \boldsymbol{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and +\( \boldsymbol{y}=[y_1,y_2,\dots,y_n] \). +With the slack constants this leads to the additional constraint \( 0\leq \lambda_i \leq C \). + +

    +code will be added +

    + + +
    +

    Multiclass problems and regression with SVMs

    +This material will be added later. +
    + + diff --git a/doc/pub/svm/html/svm-solarized.html b/doc/pub/svm/html/svm-solarized.html index cf850a809..edb7dc9c0 100644 --- a/doc/pub/svm/html/svm-solarized.html +++ b/doc/pub/svm/html/svm-solarized.html @@ -55,14 +55,19 @@ div { text-align: justify; text-justify: inter-word; } ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -131,8 +136,14 @@ classification problems) of variables. It is also used for regression problems.

    -With SVMs we distinguish between hard margin and soft margins. The latter introduces a so-called softening parameter to be discussed below. -We distinguish also between linear and non-linear approaches. The latter are the most frequent ones since it is rather unlikely that we can separate classes easily by say straight lines. +With SVMs we distinguish between hard margin and soft margins. The +latter introduces a so-called softening parameter to be discussed +below. We distinguish also between linear and non-linear +approaches. The latter are the most frequent ones since it is rather +unlikely that we can separate classes easily by say straight lines. + +

    +Note: several figures are missing. They will be added shortly. To run the codes, use the jupyter notebook











    @@ -672,15 +683,15 @@ we need to introduce for example a polynomial transformation to a two-dimensiona

    The equations

    -Suppose we define a polynomial transformation of degree two (we continue to live in a plane with \( x_1 \) and \( x_2 \) as variables) +Suppose we define a polynomial transformation of degree two only (we continue to live in a plane with \( x_i \) and \( y_i \) as variables) $$ -z = \phi(x) =\left(1, x_1, x_2, x_1^2, x_2^2, x_1x_2). +z = \phi(x_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right). $$

    With our new basis, the equations we solved earlier are basically the same, that is we have now (without the slack option for simplicity) $$ -{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{z}_i^T\boldsymbol{Z}_j, +{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{z}_j, $$ subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \), and for the support vectors @@ -689,37 +700,102 @@ y_i(\boldsymbol{w}^T\boldsymbol{z}_i+b)= 1 \hspace{0.1cm}\forall i, $$ from which we also find \( b \). - -

    -









    - -

    Different kernels

    - -

    -









    - -

    Quadratic coefficient matrix

    - -

    - - -

    Mercer's theorem

    - -

    -









    - -

    Mathematical optimization of convex functions

    - -

    -A mathematical optimization problem, or just optimization problem, has the form +To compute \( \boldsymbol{z}_i^T\boldsymbol{Z}_j \) we define the kerne \( K(\boldsymbol{x}_i,\boldsymbol{x}_j) \) as $$ -\mathrm{minimize}\hspace{0.1cm} f(x), +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\boldsymbol{z}_i^T\boldsymbol{Z}_j= \phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). $$ -subject to some constraints \( g(\lambda_i) \leq b_i \) for say a selected set \( i=1,2,\dots, n \). +For the above example, the kernel reads +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=[x_i^2, y_i^2, \sqrt{2}x_iy_i]^T\begin{bmatrix} x_j^2 \\ y_j^2 \\ \sqrt{2}x_jy_j \end{bmatrix}=x_i^2x_j^2+2x_ixJy_iy_j+y_i^2y_j^2. +$$ + +We note that this is nothing but the dot product of the two original vectors \( (\boldsymbol{x}_i^T\boldsymbol{x}_j)^2 \). Instead of thus computing the product in the Lagrangian of \( \boldsymbol{x}_i^T\boldsymbol{z}_j \) we simply compute the dot product \( (\boldsymbol{x}_i^T\boldsymbol{x}_j)^2 \). This leads to the so-called kernel trick and the result leads to the same as if we went through the trouble of performing the transformation \( (\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j) \) during the SVM calculations. + +

    +









    + +

    The problem to solve

    +Using our definition of the kernel We can rewrite again the Lagrangian +$$ +{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{z}_j, +$$ + +subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \) in terms of a convex optimization problem +$$ +\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1K(\boldsymbol{x}_1,\boldsymbol{x}_1) & y_1y_2K(\boldsymbol{x}_1,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_1,\boldsymbol{x}_n) \\ +y_2y_1\boldsymbol{x}_2^T\boldsymbol{x}_1 & y_2y_2\boldsymbol{x}_2^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_2^T\boldsymbol{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\boldsymbol{x}_n,\boldsymbol{x}_1) & y_ny_2K(\boldsymbol{x}_n\boldsymbol{x}_2) & \dots & \dots & y_ny_nK(\boldsymbol{x}_n,\boldsymbol{x}_n) \\ +\end{bmatrix}\boldsymbol{\lambda}-\mathbb{I}\boldsymbol{\lambda}, +$$ + +subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vectors \( \boldsymbol{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and +\( \boldsymbol{y}=[y_1,y_2,\dots,y_n] \). +If we add the slack constants this leads to the additional constraint \( 0\leq \lambda_i \leq C \). + +

    +We can rewrite this (see the solutions below) in terms of a convex optimization problem of the type +$$ +\begin{align*} + &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{\lambda}=f. +\end{align*} +$$ + +Below we discuss how to solve these equations. Here we note that the matrix \( \boldsymbol{P} \) has matrix elements \( p_{ij}=y_iy_jK(\boldsymbol{x}_i,\boldsymbol{x}_j) \). +Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up. The constraint \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \) leads to \( f=0 \) and \( \boldsymbol{A}=\boldsymbol{y} \). How to set up the matrix \( \boldsymbol{G} \) is discussed later. Here note that the inequalities \( 0\leq \lambda_i \leq C \) can be split up into +\( 0\leq \lambda_i \) and \( \lambda_i \leq C \). These two inequalities define then the matrix \( \boldsymbol{G} \) and the vector \( \boldsymbol{h} \). + +

    +









    + +

    Different kernels and Mercer's theorem

    + +

    +There are several popular kernels being used. These are + +

      +
    1. Linear: \( K(\boldsymbol{x},\boldsymbol{y})=\boldsymbol{x}^T\boldsymbol{y} \),
    2. +
    3. Polynomial: \( K(\boldsymbol{x},\boldsymbol{y})=(\boldsymbol{x}^T\boldsymbol{y}+\gamma)^d \),
    4. +
    5. Gaussian Radial Basis Function: \( K(\boldsymbol{x},\boldsymbol{y})=\exp{\left(-\gamma\vert\vert\boldsymbol{x}-\boldsymbol{y}\vert\vert^2\right)} \),
    6. +
    7. Tanh: \( K(\boldsymbol{x},\boldsymbol{y})=\tanh{(\boldsymbol{x}^T\boldsymbol{y}+\gamma)} \),
    8. +
    + +and many other ones. + +

    +An important theorem for us is "Mercer's theorem":https://en.wikipedia.org/wiki/Mercer%27s_theorem". +The theorem states that if a kernel function \( K \) is symmetric, continuous and leads to a positive semi-definite matrix \( \boldsymbol{P} \) then +there exists a function \( \phi \) that maps \( \boldsymbol{x}_i \) and \( \boldsymbol{x}_j \) into another space +(possibly with much higher dimensions) such that +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). +$$ + +So you can use \( K \) as a kernel since you know \( \phi \) exists, even if +you don’t know what \( \phi \) is. +Note that some frequently used kernels (such as the Sigmoid kernel) don’t respect all of Mercer’s conditions, yet they generally work +well in practice. + +

    +









    + +

    Mathematical optimization of convex functions

    + +

    +A mathematical (quadratic) optimization problem, or just optimization problem, has the form +$$ +\begin{align*} + &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{\lambda}=f. +\end{align*} +$$ + +subject to some constraints for say a selected set \( i=1,2,\dots, n \). In our case we are optimizing with respect to the Lagrangian multipliers \( \lambda_i \), and the vector \( \boldsymbol{\lambda}=[\lambda_1, \lambda_2,\dots, \lambda_n] \) is the optimization variable we are dealing with. -and \( f(x) \) is our objective function while \( g(\lambda_i) \leq b_i \) represents our constraint function.

    In our case we are particularly interested in a class of optimization problems called convex optmization problems. @@ -731,7 +807,7 @@ Convex optimization problems play a central role in applied mathematics and we r











    -

    How do we solve these problems

    +

    How do we solve these problems?

    If we use Python as programming language and wish to venture beyond @@ -743,7 +819,8 @@ methods. However, these methods tend to exhibit a rather slow converge. So, welcome to the promised land of quadratic programming.

    -The functions we need are contained in the quadratic programming package CVXOPT and we need to import it +The functions we need are contained in the quadratic programming package CVXOPT and we need to import it together with numpy as +

    @@ -751,30 +828,59 @@ The functions we need are contained in the quadratic programming package CVXO import cvxopt

    -Let us first set up the standard form the of quadratic programming (QP) equations by defining the problem as +This will make our life much easier. You don't need t write your own optimizer. + +

    +









    + +

    A simplex example

    + +

    +We remind ourselves about the general problem we want to solve $$ -\mathrm{min} +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}\boldsymbol{x}^T\boldsymbol{P}\boldsymbol{x}+\boldsymbol{q}^T\boldsymbol{x},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{x} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{x}=f. +\end{align*} $$

    -subject to Gx u. Note that x itself is not provided to the solver, since it is an internal -variable being optimized over. In particular, this means that the solver has no explicit knowledge -of x itself; everything is implicity defined by the supplied parameters. It is essential -that the same variable order is maintained for the relevant parameters (e.g., qi -Non-convexity implies the existence of local optima, making it difficult to find global optima. +Let us show how to perform the optmization using a simple case. Assume we want to optimize the following problem +$$ +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}x^2+5x+3y \\ \nonumber + &\mathrm{subject to} \\ \nonumber + &x, y \geq 0 \\ \nonumber + &x+3y \geq 15 \\ \nonumber + &2x+5y \leq 100 \\ \nonumber + &3x+4y \leq 80. \\ \nonumber +\end{align*} +$$ + +The minimization problem can be rewritten in terms of vectors and matrices as (with \( x \) and \( y \) being the unknowns) +$$ +frac{1}{2}\begin{bmatrix} x\\ y \end{bmatrix}^T \begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix}3\\ 4 \end{bmatrix}^T \begin{bmatrix}x \\ y \end{bmatrix}. +$$ + +Similarly, we can now set up the inequalities (we need to change \( \geq \) to \( \leq \) by multiplying with \( -1 \) on bot sides) as the following matrix-vector equation +$$ +\begin{bmatrix} -1 & 0 \\ 0 & -1 \\ -1 & -3 \\ 2 & 5 \\ 3 & 4\end{matrix}\begin{bmatrix} x \\ y\end{bmatrix} \preceq \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +$$ + +We have collapsed all the inequalities into a single matrix \( \boldsymbol{G} \). We see also that our matrix +$$ +\boldsymbol{P} =\begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} +$$ + +is clearly positive semi-definite (all eigenvalues larger or equal zero). +Finally, the vector \( \boldsymbol{h} \) is defined as +$$ +\boldsymbol{h} = \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +$$

    -collapsed all inequality constraints into a single G matrix of the standard form. -Since there are no equality constraints, we do not need to provide the empty A, b. Note -that even though y -2 did not appear in the original objective, we had to include it with zero -coefficients in P because the solver parameters must be defined using the full set of variables. -Even if certain variables only appear in constraints, they will still need to be expressed with -zero coefficients in the objective parameters, and vice versa. -Let us first define the above parameters in Python. CVXOPT supplies its own matrix -object; all arguments given to its solvers must be in this matrix type. There are two ways -to do this. The first is to define the matrix directly with (potentially nested) lists: -from cvxopt import matrix +Since we don't have any equalities the matrix \( \boldsymbol{A} \) is set to zero +The following code does this for us

    @@ -795,10 +901,37 @@ h = matrix(numpy.array([0,# Construct the QP, invoke solver sol = solvers.qp(P,q,G,h) # Extract optimal value and solution -sol[x] # [7.13e-07, 5.00e+00] +sol[x] sol[primal objective]

    +









    + +

    Back to the more realistic cases

    + +

    +We are now ready to return to our setup of the optmization problem for a more realistic case. Introducint the slack parameter \( C \) we have +$$ +\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1K(\boldsymbol{x}_1,\boldsymbol{x}_1) & y_1y_2K(\boldsymbol{x}_1,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_1,\boldsymbol{x}_n) \\ +y_2y_1\boldsymbol{x}_2^T\boldsymbol{x}_1 & y_2y_2\boldsymbol{x}_2^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_2^T\boldsymbol{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\boldsymbol{x}_n,\boldsymbol{x}_1) & y_ny_2K(\boldsymbol{x}_n\boldsymbol{x}_2) & \dots & \dots & y_ny_nK(\boldsymbol{x}_n,\boldsymbol{x}_n) \\ +\end{bmatrix}\boldsymbol{\lambda}-\mathbb{I}\boldsymbol{\lambda}, +$$ + +subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vectors \( \boldsymbol{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and +\( \boldsymbol{y}=[y_1,y_2,\dots,y_n] \). +With the slack constants this leads to the additional constraint \( 0\leq \lambda_i \leq C \). + +

    +code will be added + +

    +









    + +

    Multiclass problems and regression with SVMs

    +This material will be added later. diff --git a/doc/pub/svm/html/svm.html b/doc/pub/svm/html/svm.html index 6d99d69b8..2ef8ae2da 100644 --- a/doc/pub/svm/html/svm.html +++ b/doc/pub/svm/html/svm.html @@ -60,14 +60,19 @@ div { text-align: justify; text-justify: inter-word; } ('Soft optmization problem', 2, None, '___sec15'), ('Kernels and non-linearity', 2, None, '___sec16'), ('The equations', 2, None, '___sec17'), - ('Different kernels', 2, None, '___sec18'), - ('Quadratic coefficient matrix', 2, None, '___sec19'), - ("Mercer's theorem", 2, None, '___sec20'), + ('The problem to solve', 2, None, '___sec18'), + ("Different kernels and Mercer's theorem", 2, None, '___sec19'), ('Mathematical optimization of convex functions', 2, None, - '___sec21'), - ('How do we solve these problems', 2, None, '___sec22')]} + '___sec20'), + ('How do we solve these problems?', 2, None, '___sec21'), + ('A simplex example', 2, None, '___sec22'), + ('Back to the more realistic cases', 2, None, '___sec23'), + ('Multiclass problems and regression with SVMs', + 2, + None, + '___sec24')]} end of tocinfo --> @@ -136,8 +141,14 @@ classification problems) of variables. It is also used for regression problems.

    -With SVMs we distinguish between hard margin and soft margins. The latter introduces a so-called softening parameter to be discussed below. -We distinguish also between linear and non-linear approaches. The latter are the most frequent ones since it is rather unlikely that we can separate classes easily by say straight lines. +With SVMs we distinguish between hard margin and soft margins. The +latter introduces a so-called softening parameter to be discussed +below. We distinguish also between linear and non-linear +approaches. The latter are the most frequent ones since it is rather +unlikely that we can separate classes easily by say straight lines. + +

    +Note: several figures are missing. They will be added shortly. To run the codes, use the jupyter notebook











    @@ -677,15 +688,15 @@ we need to introduce for example a polynomial transformation to a two-dimensiona

    The equations

    -Suppose we define a polynomial transformation of degree two (we continue to live in a plane with \( x_1 \) and \( x_2 \) as variables) +Suppose we define a polynomial transformation of degree two only (we continue to live in a plane with \( x_i \) and \( y_i \) as variables) $$ -z = \phi(x) =\left(1, x_1, x_2, x_1^2, x_2^2, x_1x_2). +z = \phi(x_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right). $$

    With our new basis, the equations we solved earlier are basically the same, that is we have now (without the slack option for simplicity) $$ -{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{z}_i^T\boldsymbol{Z}_j, +{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{z}_j, $$ subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \), and for the support vectors @@ -694,37 +705,102 @@ y_i(\boldsymbol{w}^T\boldsymbol{z}_i+b)= 1 \hspace{0.1cm}\forall i, $$ from which we also find \( b \). - -

    -









    - -

    Different kernels

    - -

    -









    - -

    Quadratic coefficient matrix

    - -

    - - -

    Mercer's theorem

    - -

    -









    - -

    Mathematical optimization of convex functions

    - -

    -A mathematical optimization problem, or just optimization problem, has the form +To compute \( \boldsymbol{z}_i^T\boldsymbol{Z}_j \) we define the kerne \( K(\boldsymbol{x}_i,\boldsymbol{x}_j) \) as $$ -\mathrm{minimize}\hspace{0.1cm} f(x), +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\boldsymbol{z}_i^T\boldsymbol{Z}_j= \phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). $$ -subject to some constraints \( g(\lambda_i) \leq b_i \) for say a selected set \( i=1,2,\dots, n \). +For the above example, the kernel reads +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=[x_i^2, y_i^2, \sqrt{2}x_iy_i]^T\begin{bmatrix} x_j^2 \\ y_j^2 \\ \sqrt{2}x_jy_j \end{bmatrix}=x_i^2x_j^2+2x_ixJy_iy_j+y_i^2y_j^2. +$$ + +We note that this is nothing but the dot product of the two original vectors \( (\boldsymbol{x}_i^T\boldsymbol{x}_j)^2 \). Instead of thus computing the product in the Lagrangian of \( \boldsymbol{x}_i^T\boldsymbol{z}_j \) we simply compute the dot product \( (\boldsymbol{x}_i^T\boldsymbol{x}_j)^2 \). This leads to the so-called kernel trick and the result leads to the same as if we went through the trouble of performing the transformation \( (\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j) \) during the SVM calculations. + +

    +









    + +

    The problem to solve

    +Using our definition of the kernel We can rewrite again the Lagrangian +$$ +{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{z}_j, +$$ + +subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \) in terms of a convex optimization problem +$$ +\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1K(\boldsymbol{x}_1,\boldsymbol{x}_1) & y_1y_2K(\boldsymbol{x}_1,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_1,\boldsymbol{x}_n) \\ +y_2y_1\boldsymbol{x}_2^T\boldsymbol{x}_1 & y_2y_2\boldsymbol{x}_2^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_2^T\boldsymbol{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\boldsymbol{x}_n,\boldsymbol{x}_1) & y_ny_2K(\boldsymbol{x}_n\boldsymbol{x}_2) & \dots & \dots & y_ny_nK(\boldsymbol{x}_n,\boldsymbol{x}_n) \\ +\end{bmatrix}\boldsymbol{\lambda}-\mathbb{I}\boldsymbol{\lambda}, +$$ + +subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vectors \( \boldsymbol{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and +\( \boldsymbol{y}=[y_1,y_2,\dots,y_n] \). +If we add the slack constants this leads to the additional constraint \( 0\leq \lambda_i \leq C \). + +

    +We can rewrite this (see the solutions below) in terms of a convex optimization problem of the type +$$ +\begin{align*} + &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{\lambda}=f. +\end{align*} +$$ + +Below we discuss how to solve these equations. Here we note that the matrix \( \boldsymbol{P} \) has matrix elements \( p_{ij}=y_iy_jK(\boldsymbol{x}_i,\boldsymbol{x}_j) \). +Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up. The constraint \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \) leads to \( f=0 \) and \( \boldsymbol{A}=\boldsymbol{y} \). How to set up the matrix \( \boldsymbol{G} \) is discussed later. Here note that the inequalities \( 0\leq \lambda_i \leq C \) can be split up into +\( 0\leq \lambda_i \) and \( \lambda_i \leq C \). These two inequalities define then the matrix \( \boldsymbol{G} \) and the vector \( \boldsymbol{h} \). + +

    +









    + +

    Different kernels and Mercer's theorem

    + +

    +There are several popular kernels being used. These are + +

      +
    1. Linear: \( K(\boldsymbol{x},\boldsymbol{y})=\boldsymbol{x}^T\boldsymbol{y} \),
    2. +
    3. Polynomial: \( K(\boldsymbol{x},\boldsymbol{y})=(\boldsymbol{x}^T\boldsymbol{y}+\gamma)^d \),
    4. +
    5. Gaussian Radial Basis Function: \( K(\boldsymbol{x},\boldsymbol{y})=\exp{\left(-\gamma\vert\vert\boldsymbol{x}-\boldsymbol{y}\vert\vert^2\right)} \),
    6. +
    7. Tanh: \( K(\boldsymbol{x},\boldsymbol{y})=\tanh{(\boldsymbol{x}^T\boldsymbol{y}+\gamma)} \),
    8. +
    + +and many other ones. + +

    +An important theorem for us is "Mercer's theorem":https://en.wikipedia.org/wiki/Mercer%27s_theorem". +The theorem states that if a kernel function \( K \) is symmetric, continuous and leads to a positive semi-definite matrix \( \boldsymbol{P} \) then +there exists a function \( \phi \) that maps \( \boldsymbol{x}_i \) and \( \boldsymbol{x}_j \) into another space +(possibly with much higher dimensions) such that +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). +$$ + +So you can use \( K \) as a kernel since you know \( \phi \) exists, even if +you don’t know what \( \phi \) is. +Note that some frequently used kernels (such as the Sigmoid kernel) don’t respect all of Mercer’s conditions, yet they generally work +well in practice. + +

    +









    + +

    Mathematical optimization of convex functions

    + +

    +A mathematical (quadratic) optimization problem, or just optimization problem, has the form +$$ +\begin{align*} + &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{\lambda}=f. +\end{align*} +$$ + +subject to some constraints for say a selected set \( i=1,2,\dots, n \). In our case we are optimizing with respect to the Lagrangian multipliers \( \lambda_i \), and the vector \( \boldsymbol{\lambda}=[\lambda_1, \lambda_2,\dots, \lambda_n] \) is the optimization variable we are dealing with. -and \( f(x) \) is our objective function while \( g(\lambda_i) \leq b_i \) represents our constraint function.

    In our case we are particularly interested in a class of optimization problems called convex optmization problems. @@ -736,7 +812,7 @@ Convex optimization problems play a central role in applied mathematics and we r











    -

    How do we solve these problems

    +

    How do we solve these problems?

    If we use Python as programming language and wish to venture beyond @@ -748,7 +824,8 @@ methods. However, these methods tend to exhibit a rather slow converge. So, welcome to the promised land of quadratic programming.

    -The functions we need are contained in the quadratic programming package CVXOPT and we need to import it +The functions we need are contained in the quadratic programming package CVXOPT and we need to import it together with numpy as +

    @@ -756,30 +833,59 @@ The functions we need are contained in the quadratic programming package CVXO import cvxopt

    -Let us first set up the standard form the of quadratic programming (QP) equations by defining the problem as +This will make our life much easier. You don't need t write your own optimizer. + +

    +









    + +

    A simplex example

    + +

    +We remind ourselves about the general problem we want to solve $$ -\mathrm{min} +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}\boldsymbol{x}^T\boldsymbol{P}\boldsymbol{x}+\boldsymbol{q}^T\boldsymbol{x},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{x} \preceq \boldsymbol{h} \hspace{0.2cm} \boldsymbol{A}\boldsymbol{x}=f. +\end{align*} $$

    -subject to Gx u. Note that x itself is not provided to the solver, since it is an internal -variable being optimized over. In particular, this means that the solver has no explicit knowledge -of x itself; everything is implicity defined by the supplied parameters. It is essential -that the same variable order is maintained for the relevant parameters (e.g., qi -Non-convexity implies the existence of local optima, making it difficult to find global optima. +Let us show how to perform the optmization using a simple case. Assume we want to optimize the following problem +$$ +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}x^2+5x+3y \\ \nonumber + &\mathrm{subject to} \\ \nonumber + &x, y \geq 0 \\ \nonumber + &x+3y \geq 15 \\ \nonumber + &2x+5y \leq 100 \\ \nonumber + &3x+4y \leq 80. \\ \nonumber +\end{align*} +$$ + +The minimization problem can be rewritten in terms of vectors and matrices as (with \( x \) and \( y \) being the unknowns) +$$ +frac{1}{2}\begin{bmatrix} x\\ y \end{bmatrix}^T \begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix}3\\ 4 \end{bmatrix}^T \begin{bmatrix}x \\ y \end{bmatrix}. +$$ + +Similarly, we can now set up the inequalities (we need to change \( \geq \) to \( \leq \) by multiplying with \( -1 \) on bot sides) as the following matrix-vector equation +$$ +\begin{bmatrix} -1 & 0 \\ 0 & -1 \\ -1 & -3 \\ 2 & 5 \\ 3 & 4\end{matrix}\begin{bmatrix} x \\ y\end{bmatrix} \preceq \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +$$ + +We have collapsed all the inequalities into a single matrix \( \boldsymbol{G} \). We see also that our matrix +$$ +\boldsymbol{P} =\begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} +$$ + +is clearly positive semi-definite (all eigenvalues larger or equal zero). +Finally, the vector \( \boldsymbol{h} \) is defined as +$$ +\boldsymbol{h} = \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +$$

    -collapsed all inequality constraints into a single G matrix of the standard form. -Since there are no equality constraints, we do not need to provide the empty A, b. Note -that even though y -2 did not appear in the original objective, we had to include it with zero -coefficients in P because the solver parameters must be defined using the full set of variables. -Even if certain variables only appear in constraints, they will still need to be expressed with -zero coefficients in the objective parameters, and vice versa. -Let us first define the above parameters in Python. CVXOPT supplies its own matrix -object; all arguments given to its solvers must be in this matrix type. There are two ways -to do this. The first is to define the matrix directly with (potentially nested) lists: -from cvxopt import matrix +Since we don't have any equalities the matrix \( \boldsymbol{A} \) is set to zero +The following code does this for us

    @@ -800,10 +906,37 @@ h = matrix(numpy# Construct the QP, invoke solver sol = solvers.qp(P,q,G,h) # Extract optimal value and solution -sol[’x’] # [7.13e-07, 5.00e+00] +sol[’x’] sol[’primal objective’]

    +









    + +

    Back to the more realistic cases

    + +

    +We are now ready to return to our setup of the optmization problem for a more realistic case. Introducint the slack parameter \( C \) we have +$$ +\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1K(\boldsymbol{x}_1,\boldsymbol{x}_1) & y_1y_2K(\boldsymbol{x}_1,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_1,\boldsymbol{x}_n) \\ +y_2y_1\boldsymbol{x}_2^T\boldsymbol{x}_1 & y_2y_2\boldsymbol{x}_2^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_2^T\boldsymbol{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\boldsymbol{x}_n,\boldsymbol{x}_1) & y_ny_2K(\boldsymbol{x}_n\boldsymbol{x}_2) & \dots & \dots & y_ny_nK(\boldsymbol{x}_n,\boldsymbol{x}_n) \\ +\end{bmatrix}\boldsymbol{\lambda}-\mathbb{I}\boldsymbol{\lambda}, +$$ + +subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vectors \( \boldsymbol{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and +\( \boldsymbol{y}=[y_1,y_2,\dots,y_n] \). +With the slack constants this leads to the additional constraint \( 0\leq \lambda_i \leq C \). + +

    +code will be added + +

    +









    + +

    Multiclass problems and regression with SVMs

    +This material will be added later. diff --git a/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz b/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz index ff6e50e1a..7e410e360 100644 Binary files a/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz and b/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz differ diff --git a/doc/pub/svm/ipynb/svm.ipynb b/doc/pub/svm/ipynb/svm.ipynb index 33ccaa50c..0e100566e 100644 --- a/doc/pub/svm/ipynb/svm.ipynb +++ b/doc/pub/svm/ipynb/svm.ipynb @@ -34,10 +34,13 @@ "classification problems) of variables. It is also used for regression\n", "problems.\n", "\n", - "With SVMs we distinguish between hard margin and soft margins. The latter introduces a so-called softening parameter to be discussed below.\n", - "We distinguish also between linear and non-linear approaches. The latter are the most frequent ones since it is rather unlikely that we can separate classes easily by say straight lines. \n", - "\n", + "With SVMs we distinguish between hard margin and soft margins. The\n", + "latter introduces a so-called softening parameter to be discussed\n", + "below. We distinguish also between linear and non-linear\n", + "approaches. The latter are the most frequent ones since it is rather\n", + "unlikely that we can separate classes easily by say straight lines.\n", "\n", + "**Note: several figures are missing. They will be added shortly. To run the codes, use the jupyter notebook**\n", "\n", "\n", "## Hyperplanes and all that\n", @@ -1080,7 +1083,7 @@ "\n", "## The equations\n", "\n", - "Suppose we define a polynomial transformation of degree two (we continue to live in a plane with $x_1$ and $x_2$ as variables)" + "Suppose we define a polynomial transformation of degree two only (we continue to live in a plane with $x_i$ and $y_i$ as variables)" ] }, { @@ -1088,7 +1091,7 @@ "metadata": {}, "source": [ "$$\n", - "z = \\phi(x) =\\left(1, x_1, x_2, x_1^2, x_2^2, x_1x_2).\n", + "z = \\phi(x_i) =\\left(x_i^2, y_i^2, \\sqrt{2}x_iy_i\\right).\n", "$$" ] }, @@ -1104,7 +1107,7 @@ "metadata": {}, "source": [ "$$\n", - "{\\cal L}=\\sum_i\\lambda_i-\\frac{1}{2}\\sum_{ij}^n\\lambda_i\\lambda_jy_iy_j\\boldsymbol{z}_i^T\\boldsymbol{Z}_j,\n", + "{\\cal L}=\\sum_i\\lambda_i-\\frac{1}{2}\\sum_{ij}^n\\lambda_i\\lambda_jy_iy_j\\boldsymbol{x}_i^T\\boldsymbol{z}_j,\n", "$$" ] }, @@ -1128,18 +1131,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "from which we also find $b$. \n", - "\n", - "## Different kernels\n", - "\n", - "## Quadratic coefficient matrix\n", - "\n", - "\n", - "## Mercer's theorem\n", - "\n", - "## Mathematical optimization of convex functions\n", - "\n", - "A mathematical optimization problem, or just optimization problem, has the form" + "from which we also find $b$.\n", + "To compute $\\boldsymbol{z}_i^T\\boldsymbol{Z}_j$ we define the kerne $K(\\boldsymbol{x}_i,\\boldsymbol{x}_j)$ as" ] }, { @@ -1147,7 +1140,7 @@ "metadata": {}, "source": [ "$$\n", - "\\mathrm{minimize}\\hspace{0.1cm} f(x),\n", + "K(\\boldsymbol{x}_i,\\boldsymbol{x}_j)=\\boldsymbol{z}_i^T\\boldsymbol{Z}_j= \\phi(\\boldsymbol{x}_i)^T\\phi(\\boldsymbol{x}_j).\n", "$$" ] }, @@ -1155,10 +1148,153 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "subject to some constraints $g(\\lambda_i) \\leq b_i$ for say a selected set $i=1,2,\\dots, n$.\n", + "For the above example, the kernel reads" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "K(\\boldsymbol{x}_i,\\boldsymbol{x}_j)=[x_i^2, y_i^2, \\sqrt{2}x_iy_i]^T\\begin{bmatrix} x_j^2 \\\\ y_j^2 \\\\ \\sqrt{2}x_jy_j \\end{bmatrix}=x_i^2x_j^2+2x_ixJy_iy_j+y_i^2y_j^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We note that this is nothing but the dot product of the two original vectors $(\\boldsymbol{x}_i^T\\boldsymbol{x}_j)^2$. Instead of thus computing the product in the Lagrangian of $\\boldsymbol{x}_i^T\\boldsymbol{z}_j$ we simply compute the dot product $(\\boldsymbol{x}_i^T\\boldsymbol{x}_j)^2$. This leads to the so-called kernel trick and the result leads to the same as if we went through the trouble of performing the transformation $(\\phi(\\boldsymbol{x}_i)^T\\phi(\\boldsymbol{x}_j)$ during the SVM calculations. \n", + "\n", + "\n", + "## The problem to solve\n", + "Using our definition of the kernel We can rewrite again the Lagrangian" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "{\\cal L}=\\sum_i\\lambda_i-\\frac{1}{2}\\sum_{ij}^n\\lambda_i\\lambda_jy_iy_j\\boldsymbol{x}_i^T\\boldsymbol{z}_j,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "subject to the constraints $\\lambda_i\\geq 0$, $\\sum_i\\lambda_iy_i=0$ in terms of a convex optimization problem" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{1}{2} \\boldsymbol{\\lambda}^T\\begin{bmatrix} y_1y_1K(\\boldsymbol{x}_1,\\boldsymbol{x}_1) & y_1y_2K(\\boldsymbol{x}_1,\\boldsymbol{x}_2) & \\dots & \\dots & y_1y_nK(\\boldsymbol{x}_1,\\boldsymbol{x}_n) \\\\\n", + "y_2y_1\\boldsymbol{x}_2^T\\boldsymbol{x}_1 & y_2y_2\\boldsymbol{x}_2^T\\boldsymbol{x}_2 & \\dots & \\dots & y_1y_n\\boldsymbol{x}_2^T\\boldsymbol{x}_n \\\\\n", + "\\dots & \\dots & \\dots & \\dots & \\dots \\\\\n", + "\\dots & \\dots & \\dots & \\dots & \\dots \\\\\n", + "y_ny_1K(\\boldsymbol{x}_n,\\boldsymbol{x}_1) & y_ny_2K(\\boldsymbol{x}_n\\boldsymbol{x}_2) & \\dots & \\dots & y_ny_nK(\\boldsymbol{x}_n,\\boldsymbol{x}_n) \\\\\n", + "\\end{bmatrix}\\boldsymbol{\\lambda}-\\mathbb{I}\\boldsymbol{\\lambda},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "subject to $\\boldsymbol{y}^T\\boldsymbol{\\lambda}=0$. Here we defined the vectors $\\boldsymbol{\\lambda} =[\\lambda_1,\\lambda_2,\\dots,\\lambda_n]$ and \n", + "$\\boldsymbol{y}=[y_1,y_2,\\dots,y_n]$. \n", + "If we add the slack constants this leads to the additional constraint $0\\leq \\lambda_i \\leq C$.\n", + "\n", + "We can rewrite this (see the solutions below) in terms of a convex optimization problem of the type" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{align*}\n", + " &\\mathrm{min}_{\\lambda}\\hspace{0.2cm} \\frac{1}{2}\\boldsymbol{\\lambda}^T\\boldsymbol{P}\\boldsymbol{\\lambda}+\\boldsymbol{q}^T\\boldsymbol{\\lambda},\\\\ \\nonumber\n", + " &\\mathrm{subject to} \\hspace{0.2cm} \\boldsymbol{G}\\boldsymbol{\\lambda} \\preceq \\boldsymbol{h} \\hspace{0.2cm} \\boldsymbol{A}\\boldsymbol{\\lambda}=f.\n", + "\\end{align*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Below we discuss how to solve these equations. Here we note that the matrix $\\boldsymbol{P}$ has matrix elements $p_{ij}=y_iy_jK(\\boldsymbol{x}_i,\\boldsymbol{x}_j)$.\n", + "Given a kernel $K$ and the targets $y_i$ this matrix is easy to set up. The constraint $\\boldsymbol{y}^T\\boldsymbol{\\lambda}=0$ leads to $f=0$ and $\\boldsymbol{A}=\\boldsymbol{y}$. How to set up the matrix $\\boldsymbol{G}$ is discussed later. Here note that the inequalities $0\\leq \\lambda_i \\leq C$ can be split up into\n", + "$0\\leq \\lambda_i$ and $\\lambda_i \\leq C$. These two inequalities define then the matrix $\\boldsymbol{G}$ and the vector $\\boldsymbol{h}$.\n", + "\n", + "\n", + "## Different kernels and Mercer's theorem\n", + "\n", + "There are several popular kernels being used. These are\n", + "1. Linear: $K(\\boldsymbol{x},\\boldsymbol{y})=\\boldsymbol{x}^T\\boldsymbol{y}$,\n", + "\n", + "2. Polynomial: $K(\\boldsymbol{x},\\boldsymbol{y})=(\\boldsymbol{x}^T\\boldsymbol{y}+\\gamma)^d$,\n", + "\n", + "3. Gaussian Radial Basis Function: $K(\\boldsymbol{x},\\boldsymbol{y})=\\exp{\\left(-\\gamma\\vert\\vert\\boldsymbol{x}-\\boldsymbol{y}\\vert\\vert^2\\right)}$,\n", + "\n", + "4. Tanh: $K(\\boldsymbol{x},\\boldsymbol{y})=\\tanh{(\\boldsymbol{x}^T\\boldsymbol{y}+\\gamma)}$,\n", + "\n", + "and many other ones.\n", + "\n", + "An important theorem for us is \"Mercer's theorem\":https://en.wikipedia.org/wiki/Mercer%27s_theorem\". \n", + "The theorem states that if a kernel function $K$ is symmetric, continuous and leads to a positive semi-definite matrix $\\boldsymbol{P}$ then\n", + "there exists a function $\\phi$ that maps $\\boldsymbol{x}_i$ and $\\boldsymbol{x}_j$ into another space\n", + "(possibly with much higher dimensions) such that" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "K(\\boldsymbol{x}_i,\\boldsymbol{x}_j)=\\phi(\\boldsymbol{x}_i)^T\\phi(\\boldsymbol{x}_j).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So you can use $K$ as a kernel since you know $\\phi$ exists, even if\n", + "you don’t know what $\\phi$ is. \n", + "Note that some frequently used kernels (such as the Sigmoid kernel) don’t respect all of Mercer’s conditions, yet they generally work\n", + "well in practice.\n", + "\n", + "\n", + "## Mathematical optimization of convex functions\n", + "\n", + "A mathematical (quadratic) optimization problem, or just optimization problem, has the form" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{align*}\n", + " &\\mathrm{min}_{\\lambda}\\hspace{0.2cm} \\frac{1}{2}\\boldsymbol{\\lambda}^T\\boldsymbol{P}\\boldsymbol{\\lambda}+\\boldsymbol{q}^T\\boldsymbol{\\lambda},\\\\ \\nonumber\n", + " &\\mathrm{subject to} \\hspace{0.2cm} \\boldsymbol{G}\\boldsymbol{\\lambda} \\preceq \\boldsymbol{h} \\hspace{0.2cm} \\boldsymbol{A}\\boldsymbol{\\lambda}=f.\n", + "\\end{align*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "subject to some constraints for say a selected set $i=1,2,\\dots, n$.\n", "In our case we are optimizing with respect to the Lagrangian multipliers $\\lambda_i$, and the\n", "vector $\\boldsymbol{\\lambda}=[\\lambda_1, \\lambda_2,\\dots, \\lambda_n]$ is the optimization variable we are dealing with.\n", - "and $f(x)$ is our objective function while $g(\\lambda_i) \\leq b_i$ represents our constraint function.\n", "\n", "In our case we are particularly interested in a class of optimization problems called convex optmization problems. \n", "In our disussion on gradient descent methods we discussed at length the definition of a convex function. \n", @@ -1167,7 +1303,7 @@ "\n", "\n", "\n", - "## How do we solve these problems\n", + "## How do we solve these problems?\n", "\n", "If we use Python as programming language and wish to venture beyond\n", "**scikit-learn**, **tensorflow** and similar software which makes our\n", @@ -1177,7 +1313,7 @@ "methods. However, these methods tend to exhibit a rather slow\n", "converge. So, welcome to the promised land of quadratic programming.\n", "\n", - "The functions we need are contained in the quadratic programming package **CVXOPT** and we need to import it" + "The functions we need are contained in the quadratic programming package **CVXOPT** and we need to import it together with **numpy** as" ] }, { @@ -1196,7 +1332,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Let us first set up the standard form the of quadratic programming (QP) equations by defining the problem as" + "This will make our life much easier. You don't need t write your own optimizer.\n", + "\n", + "\n", + "## A simplex example\n", + "\n", + "We remind ourselves about the general problem we want to solve" ] }, { @@ -1204,7 +1345,10 @@ "metadata": {}, "source": [ "$$\n", - "\\mathrm{min}\n", + "\\begin{align*}\n", + " &\\mathrm{min}_{x}\\hspace{0.2cm} \\frac{1}{2}\\boldsymbol{x}^T\\boldsymbol{P}\\boldsymbol{x}+\\boldsymbol{q}^T\\boldsymbol{x},\\\\ \\nonumber\n", + " &\\mathrm{subject to} \\hspace{0.2cm} \\boldsymbol{G}\\boldsymbol{x} \\preceq \\boldsymbol{h} \\hspace{0.2cm} \\boldsymbol{A}\\boldsymbol{x}=f.\n", + "\\end{align*}\n", "$$" ] }, @@ -1212,23 +1356,96 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "subject to Gx u. Note that x itself is not provided to the solver, since it is an internal\n", - "variable being optimized over. In particular, this means that the solver has no explicit knowledge\n", - "of x itself; everything is implicity defined by the supplied parameters. It is essential\n", - "that the same variable order is maintained for the relevant parameters (e.g., qi\n", - "Non-convexity implies the existence of local optima, making it difficult to find global optima.\n", - "\n", - "collapsed all inequality constraints into a single G matrix of the standard form.\n", - "Since there are no equality constraints, we do not need to provide the empty A, b. Note\n", - "that even though y\n", - "2 did not appear in the original objective, we had to include it with zero\n", - "coefficients in P because the solver parameters must be defined using the full set of variables.\n", - "Even if certain variables only appear in constraints, they will still need to be expressed with\n", - "zero coefficients in the objective parameters, and vice versa.\n", - "Let us first define the above parameters in Python. CVXOPT supplies its own matrix\n", - "object; all arguments given to its solvers must be in this matrix type. There are two ways\n", - "to do this. The first is to define the matrix directly with (potentially nested) lists:\n", - "from cvxopt import matrix" + "Let us show how to perform the optmization using a simple case. Assume we want to optimize the following problem" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{align*}\n", + " &\\mathrm{min}_{x}\\hspace{0.2cm} \\frac{1}{2}x^2+5x+3y \\\\ \\nonumber\n", + " &\\mathrm{subject to} \\\\ \\nonumber\n", + " &x, y \\geq 0 \\\\ \\nonumber\n", + " &x+3y \\geq 15 \\\\ \\nonumber\n", + " &2x+5y \\leq 100 \\\\ \\nonumber\n", + " &3x+4y \\leq 80. \\\\ \\nonumber\n", + "\\end{align*}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The minimization problem can be rewritten in terms of vectors and matrices as (with $x$ and $y$ being the unknowns)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "frac{1}{2}\\begin{bmatrix} x\\\\ y \\end{bmatrix}^T \\begin{bmatrix} 1 & 0\\\\ 0 & 0 \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\end{bmatrix} + \\begin{bmatrix}3\\\\ 4 \\end{bmatrix}^T \\begin{bmatrix}x \\\\ y \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Similarly, we can now set up the inequalities (we need to change $\\geq$ to $\\leq$ by multiplying with $-1$ on bot sides) as the following matrix-vector equation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\begin{bmatrix} -1 & 0 \\\\ 0 & -1 \\\\ -1 & -3 \\\\ 2 & 5 \\\\ 3 & 4\\end{matrix}\\begin{bmatrix} x \\\\ y\\end{bmatrix} \\preceq \\begin{bmatrix}0 \\\\ 0\\\\ -15 \\\\ 100 \\\\ 80\\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have collapsed all the inequalities into a single matrix $\\boldsymbol{G}$. We see also that our matrix" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{P} =\\begin{bmatrix} 1 & 0\\\\ 0 & 0 \\end{bmatrix}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "is clearly positive semi-definite (all eigenvalues larger or equal zero). \n", + "Finally, the vector $\\boldsymbol{h}$ is defined as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{h} = \\begin{bmatrix}0 \\\\ 0\\\\ -15 \\\\ 100 \\\\ 80\\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Since we don't have any equalities the matrix $\\boldsymbol{A}$ is set to zero\n", + "The following code does this for us" ] }, { @@ -1256,9 +1473,47 @@ "# Construct the QP, invoke solver\n", "sol = solvers.qp(P,q,G,h)\n", "# Extract optimal value and solution\n", - "sol[’x’] # [7.13e-07, 5.00e+00]\n", + "sol[’x’] \n", "sol[’primal objective’]" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Back to the more realistic cases\n", + "\n", + "We are now ready to return to our setup of the optmization problem for a more realistic case. Introducint the **slack** parameter $C$ we have" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{1}{2} \\boldsymbol{\\lambda}^T\\begin{bmatrix} y_1y_1K(\\boldsymbol{x}_1,\\boldsymbol{x}_1) & y_1y_2K(\\boldsymbol{x}_1,\\boldsymbol{x}_2) & \\dots & \\dots & y_1y_nK(\\boldsymbol{x}_1,\\boldsymbol{x}_n) \\\\\n", + "y_2y_1\\boldsymbol{x}_2^T\\boldsymbol{x}_1 & y_2y_2\\boldsymbol{x}_2^T\\boldsymbol{x}_2 & \\dots & \\dots & y_1y_n\\boldsymbol{x}_2^T\\boldsymbol{x}_n \\\\\n", + "\\dots & \\dots & \\dots & \\dots & \\dots \\\\\n", + "\\dots & \\dots & \\dots & \\dots & \\dots \\\\\n", + "y_ny_1K(\\boldsymbol{x}_n,\\boldsymbol{x}_1) & y_ny_2K(\\boldsymbol{x}_n\\boldsymbol{x}_2) & \\dots & \\dots & y_ny_nK(\\boldsymbol{x}_n,\\boldsymbol{x}_n) \\\\\n", + "\\end{bmatrix}\\boldsymbol{\\lambda}-\\mathbb{I}\\boldsymbol{\\lambda},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "subject to $\\boldsymbol{y}^T\\boldsymbol{\\lambda}=0$. Here we defined the vectors $\\boldsymbol{\\lambda} =[\\lambda_1,\\lambda_2,\\dots,\\lambda_n]$ and \n", + "$\\boldsymbol{y}=[y_1,y_2,\\dots,y_n]$. \n", + "With the slack constants this leads to the additional constraint $0\\leq \\lambda_i \\leq C$.\n", + "\n", + "**code will be added**\n", + "\n", + "\n", + "## Multiclass problems and regression with SVMs\n", + "This material will be added later." + ] } ], "metadata": {}, diff --git a/doc/pub/svm/pdf/svm-minted.pdf b/doc/pub/svm/pdf/svm-minted.pdf index 226be3e02..f9cf6937c 100644 Binary files a/doc/pub/svm/pdf/svm-minted.pdf and b/doc/pub/svm/pdf/svm-minted.pdf differ diff --git a/doc/src/SupportVMachines/svm.do.txt b/doc/src/SupportVMachines/svm.do.txt index a645290ed..17b9a8b0b 100644 --- a/doc/src/SupportVMachines/svm.do.txt +++ b/doc/src/SupportVMachines/svm.do.txt @@ -621,7 +621,7 @@ We can rewrite this (see the solutions below) in terms of a convex optimization &\mathrm{subject to} \hspace{0.2cm} \bm{G}\bm{\lambda} \preceq \bm{h} \hspace{0.2cm} \bm{A}\bm{\lambda}=f. \end{align*} !et -Below we discuss how to solve these equations. Here we note that the matrix $\bm{P} has matrix elements $p_{ij}=y_iy_jK(\bm{x}_i,\bm{x}_j)$. +Below we discuss how to solve these equations. Here we note that the matrix $\bm{P}$ has matrix elements $p_{ij}=y_iy_jK(\bm{x}_i,\bm{x}_j)$. Given a kernel $K$ and the targets $y_i$ this matrix is easy to set up. The constraint $\bm{y}^T\bm{\lambda}=0$ leads to $f=0$ and $\bm{A}=\bm{y}$. How to set up the matrix $\bm{G}$ is discussed later. Here note that the inequalities $0\leq \lambda_i \leq C$ can be split up into $0\leq \lambda_i$ and $\lambda_i \leq C$. These two inequalities define then the matrix $\bm{G}$ and the vector $\bm{h}$. @@ -637,7 +637,7 @@ o Tanh: $K(\bm{x},\bm{y})=\tanh{(\bm{x}^T\bm{y}+\gamma)}$, and many other ones. An important theorem for us is "Mercer's theorem":https://en.wikipedia.org/wiki/Mercer%27s_theorem". -The theorem states that if a kernel function $K$ is symmetric, continuous and leads to a positive definite matrix $\bm{P}$ then +The theorem states that if a kernel function $K$ is symmetric, continuous and leads to a positive semi-definite matrix $\bm{P}$ then there exists a function $\phi$ that maps $\bm{x}_i$ and $\bm{x}_j$ into another space (possibly with much higher dimensions) such that !bt @@ -673,7 +673,7 @@ Convex optimization problems play a central role in applied mathematics and we r !split -===== How do we solve these problems ===== +===== How do we solve these problems? ===== If we use Python as programming language and wish to venture beyond _scikit-learn_, _tensorflow_ and similar software which makes our @@ -696,10 +696,18 @@ This will make our life much easier. You don't need t write your own optimizer. !split ===== A simplex example ===== +We remind ourselves about the general problem we want to solve +!bt +\begin{align*} + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}\bm{x}^T\bm{P}\bm{x}+\bm{q}^T\bm{x},\\ \nonumber + &\mathrm{subject to} \hspace{0.2cm} \bm{G}\bm{x} \preceq \bm{h} \hspace{0.2cm} \bm{A}\bm{x}=f. +\end{align*} +!et + Let us show how to perform the optmization using a simple case. Assume we want to optimize the following problem !bt \begin{align*} - &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}x^2+5x+3y \\ \nonumber + &\mathrm{min}_{x}\hspace{0.2cm} \frac{1}{2}x^2+5x+3y \\ \nonumber &\mathrm{subject to} \\ \nonumber &x, y \geq 0 \\ \nonumber &x+3y \geq 15 \\ \nonumber @@ -713,24 +721,29 @@ The minimization problem can be rewritten in terms of vectors and matrices as (w frac{1}{2}\begin{bmatrix} x\\ y \end{bmatrix}^T \begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix}3\\ 4 \end{bmatrix}^T \begin{bmatrix}x \\ y \end{bmatrix}. \] !et -Similarly, we an now -subject to Gx u. Note that x itself is not provided to the solver, since it is an internal -variable being optimized over. In particular, this means that the solver has no explicit knowledge -of x itself; everything is implicity defined by the supplied parameters. It is essential -that the same variable order is maintained for the relevant parameters (e.g., qi -Non-convexity implies the existence of local optima, making it difficult to find global optima. +Similarly, we can now set up the inequalities (we need to change $\geq$ to $\leq$ by multiplying with $-1$ on bot sides) as the following matrix-vector equation +!bt +\[ +\begin{bmatrix} -1 & 0 \\ 0 & -1 \\ -1 & -3 \\ 2 & 5 \\ 3 & 4\end{matrix}\begin{bmatrix} x \\ y\end{bmatrix} \preceq \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +\] +!et +We have collapsed all the inequalities into a single matrix $\bm{G}$. We see also that our matrix +!bt +\[ +\bm{P} =\begin{bmatrix} 1 & 0\\ 0 & 0 \end{bmatrix} +\] +!et +is clearly positive semi-definite (all eigenvalues larger or equal zero). +Finally, the vector $\bm{h}$ is defined as +!bt +\[ +\bm{h} = \begin{bmatrix}0 \\ 0\\ -15 \\ 100 \\ 80\end{bmatrix}. +\] +!et -collapsed all inequality constraints into a single G matrix of the standard form. -Since there are no equality constraints, we do not need to provide the empty A, b. Note -that even though y -2 did not appear in the original objective, we had to include it with zero -coefficients in P because the solver parameters must be defined using the full set of variables. -Even if certain variables only appear in constraints, they will still need to be expressed with -zero coefficients in the objective parameters, and vice versa. -Let us first define the above parameters in Python. CVXOPT supplies its own matrix -object; all arguments given to its solvers must be in this matrix type. There are two ways -to do this. The first is to define the matrix directly with (potentially nested) lists: -from cvxopt import matrix + +Since we don't have any equalities the matrix $\bm{A}$ is set to zero +The following code does this for us !bc pycod # Import the necessary packages import numpy @@ -749,10 +762,30 @@ h = matrix(numpy.array([0,0,-15,100,80]), tc=’d’) # Construct the QP, invoke solver sol = solvers.qp(P,q,G,h) # Extract optimal value and solution -sol[’x’] # [7.13e-07, 5.00e+00] +sol[’x’] sol[’primal objective’] !ec +!split +===== Back to the more realistic cases ===== + +We are now ready to return to our setup of the optmization problem for a more realistic case. Introducint the _slack_ parameter $C$ we have +!bt +\[ +\frac{1}{2} \bm{\lambda}^T\begin{bmatrix} y_1y_1K(\bm{x}_1,\bm{x}_1) & y_1y_2K(\bm{x}_1,\bm{x}_2) & \dots & \dots & y_1y_nK(\bm{x}_1,\bm{x}_n) \\ +y_2y_1\bm{x}_2^T\bm{x}_1 & y_2y_2\bm{x}_2^T\bm{x}_2 & \dots & \dots & y_1y_n\bm{x}_2^T\bm{x}_n \\ +\dots & \dots & \dots & \dots & \dots \\ +\dots & \dots & \dots & \dots & \dots \\ +y_ny_1K(\bm{x}_n,\bm{x}_1) & y_ny_2K(\bm{x}_n\bm{x}_2) & \dots & \dots & y_ny_nK(\bm{x}_n,\bm{x}_n) \\ +\end{bmatrix}\bm{\lambda}-\mathbb{I}\bm{\lambda}, +\] +!et +subject to $\bm{y}^T\bm{\lambda}=0$. Here we defined the vectors $\bm{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n]$ and +$\bm{y}=[y_1,y_2,\dots,y_n]$. +With the slack constants this leads to the additional constraint $0\leq \lambda_i \leq C$. + +_code will be added_ + !split ===== Multiclass problems and regression with SVMs =====