diff --git a/doc/pub/svm/html/._svm-bs000.html b/doc/pub/svm/html/._svm-bs000.html
index 6fb243975..811e86f4d 100644
--- a/doc/pub/svm/html/._svm-bs000.html
+++ b/doc/pub/svm/html/._svm-bs000.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -170,7 +174,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Nov 15, 2019
+Nov 16, 2019
@@ -194,7 +198,7 @@ MathJax.Hub.Config({
9
10
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs001.html b/doc/pub/svm/html/._svm-bs001.html
index edb9268bf..bfb7ac6b8 100644
--- a/doc/pub/svm/html/._svm-bs001.html
+++ b/doc/pub/svm/html/._svm-bs001.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -196,7 +200,7 @@ unlikely that we can separate classes easily by say straight lines.
10
11
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs002.html b/doc/pub/svm/html/._svm-bs002.html
index bb5af5309..1751f46d8 100644
--- a/doc/pub/svm/html/._svm-bs002.html
+++ b/doc/pub/svm/html/._svm-bs002.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -253,7 +257,7 @@ plt.show()
11
12
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs003.html b/doc/pub/svm/html/._svm-bs003.html
index 3d295f011..4283e0279 100644
--- a/doc/pub/svm/html/._svm-bs003.html
+++ b/doc/pub/svm/html/._svm-bs003.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -194,7 +198,7 @@ $$
12
13
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs004.html b/doc/pub/svm/html/._svm-bs004.html
index 3a87906a9..80a25a37c 100644
--- a/doc/pub/svm/html/._svm-bs004.html
+++ b/doc/pub/svm/html/._svm-bs004.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -210,7 +214,7 @@ When we try to separate hyperplanes, if it exists, we can use it to construct a
13
14
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs005.html b/doc/pub/svm/html/._svm-bs005.html
index d1e920a97..e173f9bc4 100644
--- a/doc/pub/svm/html/._svm-bs005.html
+++ b/doc/pub/svm/html/._svm-bs005.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -196,7 +200,7 @@ for our data sample.
14
15
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs006.html b/doc/pub/svm/html/._svm-bs006.html
index 436d6cc85..f32cde5f5 100644
--- a/doc/pub/svm/html/._svm-bs006.html
+++ b/doc/pub/svm/html/._svm-bs006.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -192,7 +196,7 @@ $$
15
16
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs007.html b/doc/pub/svm/html/._svm-bs007.html
index b3ad07f9d..b66e1dc7f 100644
--- a/doc/pub/svm/html/._svm-bs007.html
+++ b/doc/pub/svm/html/._svm-bs007.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -196,7 +200,7 @@ $$
16
17
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs008.html b/doc/pub/svm/html/._svm-bs008.html
index 9310989f2..4e45296b0 100644
--- a/doc/pub/svm/html/._svm-bs008.html
+++ b/doc/pub/svm/html/._svm-bs008.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -154,7 +158,7 @@ MathJax.Hub.Config({
Solving the equations
-We can now use the Newton-Raphson method or gradient descent to solve the equations
+We can now use the Newton-Raphson method or different variants of the gradient descent family (from plain gradient descent to various stochastic gradient descent approaches) to solve the equations
$$
b \leftarrow b +\eta \frac{\partial C}{\partial b},
$$
@@ -166,16 +170,6 @@ $$
where \( \eta \) is our by now well-known learning rate.
-
-There are however problems with this approach, although it looks
-pretty straightforward to implement. In case we separate our data into
-two distinct classes, we may up with many possible lines, as indicated
-in the figure and shown by running the following program. For small
-gaps between the entries, we may also end up needing many iterations
-before the solutions converge and if the data cannot be separated
-properly into two distinct classes, we may not experience a converge
-at all.
-
@@ -200,7 +194,7 @@ at all.
17
18
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs009.html b/doc/pub/svm/html/._svm-bs009.html
index 403a65868..2b389e3b0 100644
--- a/doc/pub/svm/html/._svm-bs009.html
+++ b/doc/pub/svm/html/._svm-bs009.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,42 +155,18 @@ MathJax.Hub.Config({
-A better approach
+Code Example
-A better approach is rather to try to define a large margin between
-the two classes (if they are well separated from the beginning).
-
+The equations we discussed above can be coded rather easily (the
+framework is rather similar to what we developed for logistic
+regression). We use the standard moons example to set up our data
+set. We want to find a line which separates the two classes
-Thus, we wish to find a margin \( M \) with \( \boldsymbol{w} \) normalized to
-\( \vert\vert \boldsymbol{w}\vert\vert =1 \) subject to the condition
-
-$$
-y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq M \hspace{0.1cm}\forall i=1,2,\dots, p.
-$$
-
-All points are thus at a signed distance from the decision boundary defined by the line \( L \). The parameters \( b \) and \( w_1 \) and \( w_2 \) define this line.
-
-
-We seek thus the largest value \( M \) defined by
-$$
-\frac{1}{\vert \vert \boldsymbol{w}\vert\vert}y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq M \hspace{0.1cm}\forall i=1,2,\dots, n,
-$$
-
-or just
-$$
-y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq M\vert \vert \boldsymbol{w}\vert\vert \hspace{0.1cm}\forall i.
-$$
-
-If we scale the equation so that \( \vert \vert \boldsymbol{w}\vert\vert = 1/M \), we have to find the minimum of
-\( \boldsymbol{w}^T\boldsymbol{w}=\vert \vert \boldsymbol{w}\vert\vert \) (the norm) subject to the condition
-$$
-y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq 1 \hspace{0.1cm}\forall i.
-$$
-
-
-We have thus defined our margin as the invers of the norm of \( \boldsymbol{w} \). We want to minimize the norm in order to have a as large as possible margin \( M \). Before we proceed, we need to remind ourselves about Lagrangian multipliers.
+
+
@@ -212,7 +192,7 @@ We have thus defined our margin as the invers of the norm of \( \boldsymbol{w} \
18
19
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs010.html b/doc/pub/svm/html/._svm-bs010.html
index 553790da7..432f59530 100644
--- a/doc/pub/svm/html/._svm-bs010.html
+++ b/doc/pub/svm/html/._svm-bs010.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,52 +155,18 @@ MathJax.Hub.Config({
-A quick reminder on Lagrangian multipliers
+Problems with the Simpler Approach
-Consider a function of three independent variables \( f(x,y,z) \) . For the function \( f \) to be an
-extreme we have
-$$
-df=0.
-$$
-
-A necessary and sufficient condition is
-$$
-\frac{\partial f}{\partial x} =\frac{\partial f}{\partial y}=\frac{\partial f}{\partial z}=0,
-$$
-
-due to
-$$
-df = \frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\frac{\partial f}{\partial z}dz.
-$$
-
-In many problems the variables \( x,y,z \) are often subject to constraints (such as those above for the margin)
-so that they are no longer all independent. It is possible at least in principle to use each
-constraint to eliminate one variable
-and to proceed with a new and smaller set of independent varables.
+There are however problems with this approach, although it looks
+pretty straightforward to implement. When running the above code, we see that we can easily end up with many diffeent lines which separate the two classes.
-The use of so-called Lagrangian multipliers is an alternative technique when the elimination
-of variables is incovenient or undesirable. Assume that we have an equation of constraint on
-the variables \( x,y,z \)
-$$
-\phi(x,y,z) = 0,
-$$
-
- resulting in
-$$
-d\phi = \frac{\partial \phi}{\partial x}dx+\frac{\partial \phi}{\partial y}dy+\frac{\partial \phi}{\partial z}dz =0.
-$$
-
-Now we cannot set anymore
-$$
-\frac{\partial f}{\partial x} =\frac{\partial f}{\partial y}=\frac{\partial f}{\partial z}=0,
-$$
-
-if \( df=0 \) is wanted
-because there are now only two independent variables! Assume \( x \) and \( y \) are the independent
-variables.
-Then \( dz \) is no longer arbitrary.
+For small
+gaps between the entries, we may also end up needing many iterations
+before the solutions converge and if the data cannot be separated
+properly into two distinct classes, we may not experience a converge
+at all.
@@ -224,7 +194,7 @@ Then \( dz \) is no longer arbitrary.
19
20
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs011.html b/doc/pub/svm/html/._svm-bs011.html
index 9f522eef9..316db0caa 100644
--- a/doc/pub/svm/html/._svm-bs011.html
+++ b/doc/pub/svm/html/._svm-bs011.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,45 +155,44 @@ MathJax.Hub.Config({
-Adding the muliplier
+A better approach
-However, we can add to
+A better approach is rather to try to define a large margin between
+the two classes (if they are well separated from the beginning).
+
+
+Thus, we wish to find a margin \( M \) with \( \boldsymbol{w} \) normalized to
+\( \vert\vert \boldsymbol{w}\vert\vert =1 \) subject to the condition
+
$$
-df = \frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\frac{\partial f}{\partial z}dz,
+y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq M \hspace{0.1cm}\forall i=1,2,\dots, p.
$$
-a multiplum of \( d\phi \), viz. \( \lambda d\phi \), resulting in
+All points are thus at a signed distance from the decision boundary defined by the line \( L \). The parameters \( b \) and \( w_1 \) and \( w_2 \) define this line.
+
+
+We seek thus the largest value \( M \) defined by
$$
-df+\lambda d\phi = (\frac{\partial f}{\partial z}+\lambda
-\frac{\partial \phi}{\partial x})dx+(\frac{\partial f}{\partial y}+\lambda\frac{\partial \phi}{\partial y})dy+
-(\frac{\partial f}{\partial z}+\lambda\frac{\partial \phi}{\partial z})dz =0.
+\frac{1}{\vert \vert \boldsymbol{w}\vert\vert}y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq M \hspace{0.1cm}\forall i=1,2,\dots, n,
$$
-Our multiplier is chosen so that
+or just
$$
-\frac{\partial f}{\partial z}+\lambda\frac{\partial \phi}{\partial z} =0.
+y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq M\vert \vert \boldsymbol{w}\vert\vert \hspace{0.1cm}\forall i.
+$$
+
+If we scale the equation so that \( \vert \vert \boldsymbol{w}\vert\vert = 1/M \), we have to find the minimum of
+\( \boldsymbol{w}^T\boldsymbol{w}=\vert \vert \boldsymbol{w}\vert\vert \) (the norm) subject to the condition
+$$
+y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq 1 \hspace{0.1cm}\forall i.
$$
-We need to remember that we took \( dx \) and \( dy \) to be arbitrary and thus we must have
-$$
-\frac{\partial f}{\partial x}+\lambda\frac{\partial \phi}{\partial x} =0,
-$$
-
-and
-$$
-\frac{\partial f}{\partial y}+\lambda\frac{\partial \phi}{\partial y} =0.
-$$
-
-When all these equations are satisfied, \( df=0 \). We have four unknowns, \( x,y,z \) and
-\( \lambda \). Actually we want only \( x,y,z \), \( \lambda \) needs not to be determined,
-it is therefore often called
-Lagrange's undetermined multiplier.
-If we have a set of constraints \( \phi_k \) we have the equations
-$$
-\frac{\partial f}{\partial x_i}+\sum_k\lambda_k\frac{\partial \phi_k}{\partial x_i} =0.
-$$
+We have thus defined our margin as the invers of the norm of
+\( \boldsymbol{w} \). We want to minimize the norm in order to have a as large as
+possible margin \( M \). Before we proceed, we need to remind ourselves
+about Lagrangian multipliers.
@@ -217,7 +220,7 @@ $$
20
21
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs012.html b/doc/pub/svm/html/._svm-bs012.html
index f3c3baf16..b600ced75 100644
--- a/doc/pub/svm/html/._svm-bs012.html
+++ b/doc/pub/svm/html/._svm-bs012.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,43 +155,52 @@ MathJax.Hub.Config({
-Setting up the problem
-In order to solve the above problem, we define the following Lagrangian function to be minimized
-$$
-{\cal L}(\lambda,b,\boldsymbol{w})=\frac{1}{2}\boldsymbol{w}^T\boldsymbol{w}-\sum_{i=1}^n\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)-1\right],
-$$
-
-where \( \lambda_i \) is a so-called Lagrange multiplier subject to the condition \( \lambda_i \geq 0 \).
+A quick reminder on Lagrangian multipliers
-Taking the derivatives with respect to \( b \) and \( \boldsymbol{w} \) we obtain
+Consider a function of three independent variables \( f(x,y,z) \) . For the function \( f \) to be an
+extreme we have
$$
-\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0,
+df=0.
$$
-and
+A necessary and sufficient condition is
$$
-\frac{\partial {\cal L}}{\partial \boldsymbol{w}} = 0 = \boldsymbol{w}-\sum_{i} \lambda_iy_i\boldsymbol{x}_i.
+\frac{\partial f}{\partial x} =\frac{\partial f}{\partial y}=\frac{\partial f}{\partial z}=0,
$$
-Inserting these constraints into the equation for \( {\cal L} \) we obtain
+due to
$$
-{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{x}_j,
+df = \frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\frac{\partial f}{\partial z}dz.
$$
-subject to the constraints \( \lambda_i\geq 0 \) and \( \sum_i\lambda_iy_i=0 \).
-We must in addition satisfy the Karush-Kuhn-Tucker (KKT) condition
+In many problems the variables \( x,y,z \) are often subject to constraints (such as those above for the margin)
+so that they are no longer all independent. It is possible at least in principle to use each
+constraint to eliminate one variable
+and to proceed with a new and smaller set of independent varables.
+
+
+The use of so-called Lagrangian multipliers is an alternative technique when the elimination
+of variables is incovenient or undesirable. Assume that we have an equation of constraint on
+the variables \( x,y,z \)
$$
-\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -1\right] \hspace{0.1cm}\forall i.
+\phi(x,y,z) = 0,
$$
+ resulting in
+$$
+d\phi = \frac{\partial \phi}{\partial x}dx+\frac{\partial \phi}{\partial y}dy+\frac{\partial \phi}{\partial z}dz =0.
+$$
-
-- If \( \lambda_i > 0 \), then \( y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1 \) and we say that \( x_i \) is on the boundary.
-- If \( y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)> 1 \), we say \( x_i \) is not on the boundary and we set \( \lambda_i=0 \).
-
+Now we cannot set anymore
+$$
+\frac{\partial f}{\partial x} =\frac{\partial f}{\partial y}=\frac{\partial f}{\partial z}=0,
+$$
-When \( \lambda_i > 0 \), the vectors \( \boldsymbol{x}_i \) are called support vectors. They are the vectors closest to the line (or hyperplane) and define the margin \( M \).
+if \( df=0 \) is wanted
+because there are now only two independent variables! Assume \( x \) and \( y \) are the independent
+variables.
+Then \( dz \) is no longer arbitrary.
@@ -215,7 +228,7 @@ When \( \lambda_i > 0 \), the vectors \( \boldsymbol{x}_i \) are called support
21
22
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs013.html b/doc/pub/svm/html/._svm-bs013.html
index 1ce154cf5..302ea6e65 100644
--- a/doc/pub/svm/html/._svm-bs013.html
+++ b/doc/pub/svm/html/._svm-bs013.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,26 +155,45 @@ MathJax.Hub.Config({
-The problem to solve
+Adding the muliplier
-We can rewrite
+However, we can add to
$$
-{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{x}_j,
+df = \frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\frac{\partial f}{\partial z}dz,
$$
-and its constraints in terms of a matrix-vector problem where we minimize w.r.t. \( \lambda \) the following problem
+a multiplum of \( d\phi \), viz. \( \lambda d\phi \), resulting in
$$
-\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1\boldsymbol{x}_1^T\boldsymbol{x}_1 & y_1y_2\boldsymbol{x}_1^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_1^T\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_1\boldsymbol{x}_n^T\boldsymbol{x}_1 & y_ny_2\boldsymbol{x}_n^T\boldsymbol{x}_2 & \dots & \dots & y_ny_n\boldsymbol{x}_n^T\boldsymbol{x}_n \\
-\end{bmatrix}\boldsymbol{\lambda}-\mathbb{1}\boldsymbol{\lambda},
+df+\lambda d\phi = (\frac{\partial f}{\partial z}+\lambda
+\frac{\partial \phi}{\partial x})dx+(\frac{\partial f}{\partial y}+\lambda\frac{\partial \phi}{\partial y})dy+
+(\frac{\partial f}{\partial z}+\lambda\frac{\partial \phi}{\partial z})dz =0.
$$
-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] \).
+Our multiplier is chosen so that
+$$
+\frac{\partial f}{\partial z}+\lambda\frac{\partial \phi}{\partial z} =0.
+$$
+
+
+We need to remember that we took \( dx \) and \( dy \) to be arbitrary and thus we must have
+$$
+\frac{\partial f}{\partial x}+\lambda\frac{\partial \phi}{\partial x} =0,
+$$
+
+and
+$$
+\frac{\partial f}{\partial y}+\lambda\frac{\partial \phi}{\partial y} =0.
+$$
+
+When all these equations are satisfied, \( df=0 \). We have four unknowns, \( x,y,z \) and
+\( \lambda \). Actually we want only \( x,y,z \), \( \lambda \) needs not to be determined,
+it is therefore often called
+Lagrange's undetermined multiplier.
+If we have a set of constraints \( \phi_k \) we have the equations
+$$
+\frac{\partial f}{\partial x_i}+\sum_k\lambda_k\frac{\partial \phi_k}{\partial x_i} =0.
+$$
@@ -198,7 +221,7 @@ subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vec
22
23
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs014.html b/doc/pub/svm/html/._svm-bs014.html
index 47f389a3b..562fea828 100644
--- a/doc/pub/svm/html/._svm-bs014.html
+++ b/doc/pub/svm/html/._svm-bs014.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,36 +155,43 @@ MathJax.Hub.Config({
-The last steps
+Setting up the problem
+In order to solve the above problem, we define the following Lagrangian function to be minimized
+$$
+{\cal L}(\lambda,b,\boldsymbol{w})=\frac{1}{2}\boldsymbol{w}^T\boldsymbol{w}-\sum_{i=1}^n\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)-1\right],
+$$
+
+where \( \lambda_i \) is a so-called Lagrange multiplier subject to the condition \( \lambda_i \geq 0 \).
-Solving the above problem, yields the values of \( \lambda_i \).
-To find the coefficients of your hyperplane we need simply to compute
+Taking the derivatives with respect to \( b \) and \( \boldsymbol{w} \) we obtain
$$
-\boldsymbol{w}=\sum_{i} \lambda_iy_i\boldsymbol{x}_i.
+\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0,
$$
-With our vector \( \boldsymbol{w} \) we can in turn find the value of the intercept \( b \) (here in two dimensions) via
+and
$$
-y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1,
+\frac{\partial {\cal L}}{\partial \boldsymbol{w}} = 0 = \boldsymbol{w}-\sum_{i} \lambda_iy_i\boldsymbol{x}_i.
$$
-resulting in
+Inserting these constraints into the equation for \( {\cal L} \) we obtain
$$
-b = \frac{1}{y_i}-\boldsymbol{w}^T\boldsymbol{x}_i,
+{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{x}_j,
$$
-or if we write it out in terms of the support vectors only, with \( N_s \) being their number, we have
+subject to the constraints \( \lambda_i\geq 0 \) and \( \sum_i\lambda_iy_i=0 \).
+We must in addition satisfy the Karush-Kuhn-Tucker (KKT) condition
$$
-b = \frac{1}{N_s}\sum_{j\in N_s}\left(y_j-\sum_{i=1}^n\lambda_iy_i\boldsymbol{x}_i^T\boldsymbol{x}_j\right).
+\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -1\right] \hspace{0.1cm}\forall i.
$$
-With our hyperplane coefficients we can use our classifier to assign any observation by simply using
-$$
-y_i = \mathrm{sign}(\boldsymbol{w}^T\boldsymbol{x}_i+b).
-$$
-Below we discuss how to find the optimal values of \( \lambda_i \). Before we proceed however, we discuss now the so-called soft classifier.
+
+- If \( \lambda_i > 0 \), then \( y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1 \) and we say that \( x_i \) is on the boundary.
+- If \( y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)> 1 \), we say \( x_i \) is not on the boundary and we set \( \lambda_i=0 \).
+
+
+When \( \lambda_i > 0 \), the vectors \( \boldsymbol{x}_i \) are called support vectors. They are the vectors closest to the line (or hyperplane) and define the margin \( M \).
@@ -208,7 +219,7 @@ Below we discuss how to find the optimal values of \( \lambda_i \). Before we pr
23
24
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs015.html b/doc/pub/svm/html/._svm-bs015.html
index 49fe21701..fde86dc1a 100644
--- a/doc/pub/svm/html/._svm-bs015.html
+++ b/doc/pub/svm/html/._svm-bs015.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,37 +155,26 @@ MathJax.Hub.Config({
-A soft classifier
+The problem to solve
-Till now, the margin is strictly defined by the support vectors. This defines what is called a hard classifier, that is the margins are well defined.
-
-
-Suppose now that classes overlap in feature space, as shown in the
-figure here. One way to deal with this problem before we define the
-so-called kernel approach, is to allow a kind of slack in the sense
-that we allow some points to be on the wrong side of the margin.
-
-
-We introduce thus the so-called slack variables \( \boldsymbol{\xi} =[\xi_1,x_2,\dots,x_n] \) and
-modify our previous equation
+We can rewrite
$$
-y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1,
+{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{x}_j,
$$
-to
+and its constraints in terms of a matrix-vector problem where we minimize w.r.t. \( \lambda \) the following problem
$$
-y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1-\xi_i,
+\frac{1}{2} \boldsymbol{\lambda}^T\begin{bmatrix} y_1y_1\boldsymbol{x}_1^T\boldsymbol{x}_1 & y_1y_2\boldsymbol{x}_1^T\boldsymbol{x}_2 & \dots & \dots & y_1y_n\boldsymbol{x}_1^T\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_1\boldsymbol{x}_n^T\boldsymbol{x}_1 & y_ny_2\boldsymbol{x}_n^T\boldsymbol{x}_2 & \dots & \dots & y_ny_n\boldsymbol{x}_n^T\boldsymbol{x}_n \\
+\end{bmatrix}\boldsymbol{\lambda}-\mathbb{1}\boldsymbol{\lambda},
$$
-with the requirement \( \xi_i\geq 0 \). The total violation is now \( \sum_i\xi \).
-The value \( \xi_i \) in the constraint the last constraint corresponds to the amount by which the prediction
-\( y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1 \) is on the wrong side of its margin. Hence by bounding the sum \( \sum_i \xi_i \),
-we bound the total amount by which predictions fall on the wrong side of their margins.
-
-
-Misclassifications occur when \( \xi_i > 1 \). Thus bounding the total sum by some value \( C \) bounds in turn the total number of
-misclassifications.
+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] \).
@@ -209,7 +202,7 @@ misclassifications.
24
25
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs016.html b/doc/pub/svm/html/._svm-bs016.html
index 868552403..496a4d385 100644
--- a/doc/pub/svm/html/._svm-bs016.html
+++ b/doc/pub/svm/html/._svm-bs016.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,56 +155,36 @@ MathJax.Hub.Config({
-Soft optmization problem
+The last steps
-This has in turn the consequences that we change our optmization problem to finding the minimum of
+Solving the above problem, yields the values of \( \lambda_i \).
+To find the coefficients of your hyperplane we need simply to compute
$$
-{\cal L}=\frac{1}{2}\boldsymbol{w}^T\boldsymbol{w}-\sum_{i=1}^n\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)-(1-\xi_)\right]+C\sum_{i=1}^n\xi_i-\sum_{i=1}^n\gamma_i\xi_i,
+\boldsymbol{w}=\sum_{i} \lambda_iy_i\boldsymbol{x}_i.
$$
-subject to
+With our vector \( \boldsymbol{w} \) we can in turn find the value of the intercept \( b \) (here in two dimensions) via
$$
-y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1-\xi_i \hspace{0.1cm}\forall i,
+y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1,
$$
-with the requirement \( \xi_i\geq 0 \).
-
-
-Taking the derivatives with respect to \( b \) and \( \boldsymbol{w} \) we obtain
+resulting in
$$
-\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0,
+b = \frac{1}{y_i}-\boldsymbol{w}^T\boldsymbol{x}_i,
$$
-and
+or if we write it out in terms of the support vectors only, with \( N_s \) being their number, we have
$$
-\frac{\partial {\cal L}}{\partial \boldsymbol{w}} = 0 = \boldsymbol{w}-\sum_{i} \lambda_iy_i\boldsymbol{x}_i,
+b = \frac{1}{N_s}\sum_{j\in N_s}\left(y_j-\sum_{i=1}^n\lambda_iy_i\boldsymbol{x}_i^T\boldsymbol{x}_j\right).
$$
-and
+With our hyperplane coefficients we can use our classifier to assign any observation by simply using
$$
-\lambda_i = C-\gamma_i \hspace{0.1cm}\forall i.
+y_i = \mathrm{sign}(\boldsymbol{w}^T\boldsymbol{x}_i+b).
$$
-Inserting these constraints into the equation for \( {\cal L} \) we obtain the same equation as before
-$$
-{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{x}_j,
-$$
-
-but now subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \) and \( 0\leq\lambda_i \leq C \).
-We must in addition satisfy the Karush-Kuhn-Tucker condition which now reads
-$$
-\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -(1-\xi_)\right]=0 \hspace{0.1cm}\forall i,
-$$
-
-$$
-\gamma_i\xi_i = 0,
-$$
-
-and
-$$
-y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -(1-\xi_) \geq 0 \hspace{0.1cm}\forall i.
-$$
+Below we discuss how to find the optimal values of \( \lambda_i \). Before we proceed however, we discuss now the so-called soft classifier.
@@ -228,7 +212,7 @@ $$
25
26
...
- 27
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs017.html b/doc/pub/svm/html/._svm-bs017.html
index c89ed61be..d3188a034 100644
--- a/doc/pub/svm/html/._svm-bs017.html
+++ b/doc/pub/svm/html/._svm-bs017.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,76 +155,38 @@ MathJax.Hub.Config({
-Kernels and non-linearity
+A soft classifier
-The cases we have studied till were all characterized by two classes
-with a close to linear separability. The classifiers we have described
-so far find linear boundaries in our input feature space. It is
-possible to make our procedure more flexible by exploring the feature
-space using other basis expansions such higher-order polynomials,
-wavelets, splines etc.
+Till now, the margin is strictly defined by the support vectors. This defines what is called a hard classifier, that is the margins are well defined.
-If our feature space is not easy to separate, as shown in the figure
-here, we can achieve a better separation by introducing more complex
-basis functions. The ideal would be, as shown in the next figure, to, via a specific transformation to
-obtain a separation between the classes which is almost linear.
+Suppose now that classes overlap in feature space, as shown in the
+figure here. One way to deal with this problem before we define the
+so-called kernel approach, is to allow a kind of slack in the sense
+that we allow some points to be on the wrong side of the margin.
-The change of basis, from \( x\rightarrow z=\phi(x) \) leads to the same type of equations to be solved, except that
-we need to introduce for example a polynomial transformation to a two-dimensional training set.
+We introduce thus the so-called slack variables \( \boldsymbol{\xi} =[\xi_1,x_2,\dots,x_n] \) and
+modify our previous equation
+$$
+y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1,
+$$
+
+to
+$$
+y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1-\xi_i,
+$$
+
+with the requirement \( \xi_i\geq 0 \). The total violation is now \( \sum_i\xi \).
+The value \( \xi_i \) in the constraint the last constraint corresponds to the amount by which the prediction
+\( y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1 \) is on the wrong side of its margin. Hence by bounding the sum \( \sum_i \xi_i \),
+we bound the total amount by which predictions fall on the wrong side of their margins.
+Misclassifications occur when \( \xi_i > 1 \). Thus bounding the total sum by some value \( C \) bounds in turn the total number of
+misclassifications.
-
-
import numpy as np
-import os
-
-np.random.seed(42)
-
-# To plot pretty figures
-import matplotlib
-import matplotlib.pyplot as plt
-plt.rcParams['axes.labelsize'] = 14
-plt.rcParams['xtick.labelsize'] = 12
-plt.rcParams['ytick.labelsize'] = 12
-
-
-from sklearn.svm import SVC
-from sklearn import datasets
-
-
-
-X1D = np.linspace(-4, 4, 9).reshape(-1, 1)
-X2D = np.c_[X1D, X1D**2]
-y = np.array([0, 0, 1, 1, 1, 1, 1, 0, 0])
-
-plt.figure(figsize=(11, 4))
-
-plt.subplot(121)
-plt.grid(True, which='both')
-plt.axhline(y=0, color='k')
-plt.plot(X1D[:, 0][y==0], np.zeros(4), "bs")
-plt.plot(X1D[:, 0][y==1], np.zeros(5), "g^")
-plt.gca().get_yaxis().set_ticks([])
-plt.xlabel(r"$x_1$", fontsize=20)
-plt.axis([-4.5, 4.5, -0.2, 0.2])
-
-plt.subplot(122)
-plt.grid(True, which='both')
-plt.axhline(y=0, color='k')
-plt.axvline(x=0, color='k')
-plt.plot(X2D[:, 0][y==0], X2D[:, 1][y==0], "bs")
-plt.plot(X2D[:, 0][y==1], X2D[:, 1][y==1], "g^")
-plt.xlabel(r"$x_1$", fontsize=20)
-plt.ylabel(r"$x_2$", fontsize=20, rotation=0)
-plt.gca().get_yaxis().set_ticks([0, 4, 8, 12, 16])
-plt.plot([-4.5, 4.5], [6.5, 6.5], "r--", linewidth=3)
-plt.axis([-4.5, 4.5, -1, 17])
-plt.subplots_adjust(right=1)
-plt.show()
-
@@ -246,6 +212,8 @@ plt.show()
25
26
27
+ ...
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs018.html b/doc/pub/svm/html/._svm-bs018.html
index e5914bda7..7f64bc0d4 100644
--- a/doc/pub/svm/html/._svm-bs018.html
+++ b/doc/pub/svm/html/._svm-bs018.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,44 +155,56 @@ MathJax.Hub.Config({
-The equations
+Soft optmization problem
-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)
+This has in turn the consequences that we change our optmization problem to finding the minimum of
$$
-z = \phi(x_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right).
+{\cal L}=\frac{1}{2}\boldsymbol{w}^T\boldsymbol{w}-\sum_{i=1}^n\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)-(1-\xi_)\right]+C\sum_{i=1}^n\xi_i-\sum_{i=1}^n\gamma_i\xi_i,
$$
+subject to
+$$
+y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1-\xi_i \hspace{0.1cm}\forall i,
+$$
+
+with the requirement \( \xi_i\geq 0 \).
+
-With our new basis, the equations we solved earlier are basically the same, that is we have now (without the slack option for simplicity)
+Taking the derivatives with respect to \( b \) and \( \boldsymbol{w} \) we obtain
$$
-{\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,
+\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0,
$$
-subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \), and for the support vectors
+and
$$
-y_i(\boldsymbol{w}^T\boldsymbol{z}_i+b)= 1 \hspace{0.1cm}\forall i,
+\frac{\partial {\cal L}}{\partial \boldsymbol{w}} = 0 = \boldsymbol{w}-\sum_{i} \lambda_iy_i\boldsymbol{x}_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
+and
$$
-K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\boldsymbol{z}_i^T\boldsymbol{z}_j= \phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j).
+\lambda_i = C-\gamma_i \hspace{0.1cm}\forall i.
$$
-For the above example, the kernel reads
+Inserting these constraints into the equation for \( {\cal L} \) we obtain the same equation as before
$$
-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_ix_jy_iy_j+y_i^2y_j^2.
+{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{x}_i^T\boldsymbol{x}_j,
$$
-
-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{z}_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.
+but now subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \) and \( 0\leq\lambda_i \leq C \).
+We must in addition satisfy the Karush-Kuhn-Tucker condition which now reads
+$$
+\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -(1-\xi_)\right]=0 \hspace{0.1cm}\forall i,
+$$
+
+$$
+\gamma_i\xi_i = 0,
+$$
+
+and
+$$
+y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -(1-\xi_) \geq 0 \hspace{0.1cm}\forall i.
+$$
@@ -214,6 +230,9 @@ the trouble of performing the transformation
25
26
27
+ 28
+ ...
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs019.html b/doc/pub/svm/html/._svm-bs019.html
index 25b07df62..8c92dae33 100644
--- a/doc/pub/svm/html/._svm-bs019.html
+++ b/doc/pub/svm/html/._svm-bs019.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,39 +155,76 @@ MathJax.Hub.Config({
-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_1K(\boldsymbol{x}_2,\boldsymbol{x}_1) & y_2y_2(\boldsymbol{x}_2,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_2,\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{1}\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 \).
+Kernels and non-linearity
-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\hspace{0.1cm}to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \wedge \boldsymbol{A}\boldsymbol{\lambda}=f.
-\end{align*}
-$$
+The cases we have studied till were all characterized by two classes
+with a close to linear separability. The classifiers we have described
+so far find linear boundaries in our input feature space. It is
+possible to make our procedure more flexible by exploring the feature
+space using other basis expansions such higher-order polynomials,
+wavelets, splines etc.
-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} \).
+
+If our feature space is not easy to separate, as shown in the figure
+here, we can achieve a better separation by introducing more complex
+basis functions. The ideal would be, as shown in the next figure, to, via a specific transformation to
+obtain a separation between the classes which is almost linear.
+
+The change of basis, from \( x\rightarrow z=\phi(x) \) leads to the same type of equations to be solved, except that
+we need to introduce for example a polynomial transformation to a two-dimensional training set.
+
+
+
+
+
import numpy as np
+import os
+
+np.random.seed(42)
+
+# To plot pretty figures
+import matplotlib
+import matplotlib.pyplot as plt
+plt.rcParams['axes.labelsize'] = 14
+plt.rcParams['xtick.labelsize'] = 12
+plt.rcParams['ytick.labelsize'] = 12
+
+
+from sklearn.svm import SVC
+from sklearn import datasets
+
+
+
+X1D = np.linspace(-4, 4, 9).reshape(-1, 1)
+X2D = np.c_[X1D, X1D**2]
+y = np.array([0, 0, 1, 1, 1, 1, 1, 0, 0])
+
+plt.figure(figsize=(11, 4))
+
+plt.subplot(121)
+plt.grid(True, which='both')
+plt.axhline(y=0, color='k')
+plt.plot(X1D[:, 0][y==0], np.zeros(4), "bs")
+plt.plot(X1D[:, 0][y==1], np.zeros(5), "g^")
+plt.gca().get_yaxis().set_ticks([])
+plt.xlabel(r"$x_1$", fontsize=20)
+plt.axis([-4.5, 4.5, -0.2, 0.2])
+
+plt.subplot(122)
+plt.grid(True, which='both')
+plt.axhline(y=0, color='k')
+plt.axvline(x=0, color='k')
+plt.plot(X2D[:, 0][y==0], X2D[:, 1][y==0], "bs")
+plt.plot(X2D[:, 0][y==1], X2D[:, 1][y==1], "g^")
+plt.xlabel(r"$x_1$", fontsize=20)
+plt.ylabel(r"$x_2$", fontsize=20, rotation=0)
+plt.gca().get_yaxis().set_ticks([0, 4, 8, 12, 16])
+plt.plot([-4.5, 4.5], [6.5, 6.5], "r--", linewidth=3)
+plt.axis([-4.5, 4.5, -1, 17])
+plt.subplots_adjust(right=1)
+plt.show()
+
@@ -207,6 +248,8 @@ Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up.
25
26
27
+ 28
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs020.html b/doc/pub/svm/html/._svm-bs020.html
index bd289d77f..9e90df4cc 100644
--- a/doc/pub/svm/html/._svm-bs020.html
+++ b/doc/pub/svm/html/._svm-bs020.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,33 +155,44 @@ MathJax.Hub.Config({
-Different kernels and Mercer's theorem
+The equations
-There are several popular kernels being used. These are
-
-
-- Linear: \( K(\boldsymbol{x},\boldsymbol{y})=\boldsymbol{x}^T\boldsymbol{y} \),
-- Polynomial: \( K(\boldsymbol{x},\boldsymbol{y})=(\boldsymbol{x}^T\boldsymbol{y}+\gamma)^d \),
-- Gaussian Radial Basis Function: \( K(\boldsymbol{x},\boldsymbol{y})=\exp{\left(-\gamma\vert\vert\boldsymbol{x}-\boldsymbol{y}\vert\vert^2\right)} \),
-- Tanh: \( K(\boldsymbol{x},\boldsymbol{y})=\tanh{(\boldsymbol{x}^T\boldsymbol{y}+\gamma)} \),
-
-
-and many other ones.
+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_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right).
+$$
-An important theorem for us is Mercer's 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
+With our new basis, the equations we solved earlier are basically the same, that is we have now (without the slack option for simplicity)
$$
-K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_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,
$$
-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.
+subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \), and for the support vectors
+$$
+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_ix_jy_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{z}_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.
@@ -201,6 +216,8 @@ well in practice.
25
26
27
+ 28
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs021.html b/doc/pub/svm/html/._svm-bs021.html
index 8af5cea84..814f24f67 100644
--- a/doc/pub/svm/html/._svm-bs021.html
+++ b/doc/pub/svm/html/._svm-bs021.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,199 +155,39 @@ MathJax.Hub.Config({
-The moons example
+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_1K(\boldsymbol{x}_2,\boldsymbol{x}_1) & y_2y_2(\boldsymbol{x}_2,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_2,\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{1}\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\hspace{0.1cm}to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \hspace{0.2cm} \wedge \boldsymbol{A}\boldsymbol{\lambda}=f.
+\end{align*}
+$$
-
-
from __future__ import division, print_function, unicode_literals
+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} \).
-import numpy as np
-np.random.seed(42)
-
-import matplotlib
-import matplotlib.pyplot as plt
-plt.rcParams['axes.labelsize'] = 14
-plt.rcParams['xtick.labelsize'] = 12
-plt.rcParams['ytick.labelsize'] = 12
-
-
-from sklearn.svm import SVC
-from sklearn import datasets
-
-
-
-from sklearn.pipeline import Pipeline
-from sklearn.preprocessing import StandardScaler
-from sklearn.svm import LinearSVC
-
-
-from sklearn.datasets import make_moons
-X, y = make_moons(n_samples=100, noise=0.15, random_state=42)
-
-def plot_dataset(X, y, axes):
- plt.plot(X[:, 0][y==0], X[:, 1][y==0], "bs")
- plt.plot(X[:, 0][y==1], X[:, 1][y==1], "g^")
- plt.axis(axes)
- plt.grid(True, which='both')
- plt.xlabel(r"$x_1$", fontsize=20)
- plt.ylabel(r"$x_2$", fontsize=20, rotation=0)
-
-plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
-plt.show()
-
-from sklearn.datasets import make_moons
-from sklearn.pipeline import Pipeline
-from sklearn.preprocessing import PolynomialFeatures
-
-polynomial_svm_clf = Pipeline([
- ("poly_features", PolynomialFeatures(degree=3)),
- ("scaler", StandardScaler()),
- ("svm_clf", LinearSVC(C=10, loss="hinge", random_state=42))
- ])
-
-polynomial_svm_clf.fit(X, y)
-
-def plot_predictions(clf, axes):
- x0s = np.linspace(axes[0], axes[1], 100)
- x1s = np.linspace(axes[2], axes[3], 100)
- x0, x1 = np.meshgrid(x0s, x1s)
- X = np.c_[x0.ravel(), x1.ravel()]
- y_pred = clf.predict(X).reshape(x0.shape)
- y_decision = clf.decision_function(X).reshape(x0.shape)
- plt.contourf(x0, x1, y_pred, cmap=plt.cm.brg, alpha=0.2)
- plt.contourf(x0, x1, y_decision, cmap=plt.cm.brg, alpha=0.1)
-
-plot_predictions(polynomial_svm_clf, [-1.5, 2.5, -1, 1.5])
-plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
-
-plt.show()
-
-
-from sklearn.svm import SVC
-
-poly_kernel_svm_clf = Pipeline([
- ("scaler", StandardScaler()),
- ("svm_clf", SVC(kernel="poly", degree=3, coef0=1, C=5))
- ])
-poly_kernel_svm_clf.fit(X, y)
-
-poly100_kernel_svm_clf = Pipeline([
- ("scaler", StandardScaler()),
- ("svm_clf", SVC(kernel="poly", degree=10, coef0=100, C=5))
- ])
-poly100_kernel_svm_clf.fit(X, y)
-
-plt.figure(figsize=(11, 4))
-
-plt.subplot(121)
-plot_predictions(poly_kernel_svm_clf, [-1.5, 2.5, -1, 1.5])
-plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
-plt.title(r"$d=3, r=1, C=5$", fontsize=18)
-
-plt.subplot(122)
-plot_predictions(poly100_kernel_svm_clf, [-1.5, 2.5, -1, 1.5])
-plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
-plt.title(r"$d=10, r=100, C=5$", fontsize=18)
-
-plt.show()
-
-def gaussian_rbf(x, landmark, gamma):
- return np.exp(-gamma * np.linalg.norm(x - landmark, axis=1)**2)
-
-gamma = 0.3
-
-x1s = np.linspace(-4.5, 4.5, 200).reshape(-1, 1)
-x2s = gaussian_rbf(x1s, -2, gamma)
-x3s = gaussian_rbf(x1s, 1, gamma)
-
-XK = np.c_[gaussian_rbf(X1D, -2, gamma), gaussian_rbf(X1D, 1, gamma)]
-yk = np.array([0, 0, 1, 1, 1, 1, 1, 0, 0])
-
-plt.figure(figsize=(11, 4))
-
-plt.subplot(121)
-plt.grid(True, which='both')
-plt.axhline(y=0, color='k')
-plt.scatter(x=[-2, 1], y=[0, 0], s=150, alpha=0.5, c="red")
-plt.plot(X1D[:, 0][yk==0], np.zeros(4), "bs")
-plt.plot(X1D[:, 0][yk==1], np.zeros(5), "g^")
-plt.plot(x1s, x2s, "g--")
-plt.plot(x1s, x3s, "b:")
-plt.gca().get_yaxis().set_ticks([0, 0.25, 0.5, 0.75, 1])
-plt.xlabel(r"$x_1$", fontsize=20)
-plt.ylabel(r"Similarity", fontsize=14)
-plt.annotate(r'$\mathbf{x}$',
- xy=(X1D[3, 0], 0),
- xytext=(-0.5, 0.20),
- ha="center",
- arrowprops=dict(facecolor='black', shrink=0.1),
- fontsize=18,
- )
-plt.text(-2, 0.9, "$x_2$", ha="center", fontsize=20)
-plt.text(1, 0.9, "$x_3$", ha="center", fontsize=20)
-plt.axis([-4.5, 4.5, -0.1, 1.1])
-
-plt.subplot(122)
-plt.grid(True, which='both')
-plt.axhline(y=0, color='k')
-plt.axvline(x=0, color='k')
-plt.plot(XK[:, 0][yk==0], XK[:, 1][yk==0], "bs")
-plt.plot(XK[:, 0][yk==1], XK[:, 1][yk==1], "g^")
-plt.xlabel(r"$x_2$", fontsize=20)
-plt.ylabel(r"$x_3$ ", fontsize=20, rotation=0)
-plt.annotate(r'$\phi\left(\mathbf{x}\right)$',
- xy=(XK[3, 0], XK[3, 1]),
- xytext=(0.65, 0.50),
- ha="center",
- arrowprops=dict(facecolor='black', shrink=0.1),
- fontsize=18,
- )
-plt.plot([-0.1, 1.1], [0.57, -0.1], "r--", linewidth=3)
-plt.axis([-0.1, 1.1, -0.1, 1.1])
-
-plt.subplots_adjust(right=1)
-
-plt.show()
-
-
-x1_example = X1D[3, 0]
-for landmark in (-2, 1):
- k = gaussian_rbf(np.array([[x1_example]]), np.array([[landmark]]), gamma)
- print("Phi({}, {}) = {}".format(x1_example, landmark, k))
-
-rbf_kernel_svm_clf = Pipeline([
- ("scaler", StandardScaler()),
- ("svm_clf", SVC(kernel="rbf", gamma=5, C=0.001))
- ])
-rbf_kernel_svm_clf.fit(X, y)
-
-
-from sklearn.svm import SVC
-
-gamma1, gamma2 = 0.1, 5
-C1, C2 = 0.001, 1000
-hyperparams = (gamma1, C1), (gamma1, C2), (gamma2, C1), (gamma2, C2)
-
-svm_clfs = []
-for gamma, C in hyperparams:
- rbf_kernel_svm_clf = Pipeline([
- ("scaler", StandardScaler()),
- ("svm_clf", SVC(kernel="rbf", gamma=gamma, C=C))
- ])
- rbf_kernel_svm_clf.fit(X, y)
- svm_clfs.append(rbf_kernel_svm_clf)
-
-plt.figure(figsize=(11, 7))
-
-for i, svm_clf in enumerate(svm_clfs):
- plt.subplot(221 + i)
- plot_predictions(svm_clf, [-1.5, 2.5, -1, 1.5])
- plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
- gamma, C = hyperparams[i]
- plt.title(r"$\gamma = {}, C = {}$".format(gamma, C), fontsize=16)
-
-plt.show()
-
@@ -365,6 +209,8 @@ plt.show()
25
26
27
+ 28
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs022.html b/doc/pub/svm/html/._svm-bs022.html
index 1cb7942ac..a529ff2e2 100644
--- a/doc/pub/svm/html/._svm-bs022.html
+++ b/doc/pub/svm/html/._svm-bs022.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,27 +155,33 @@ MathJax.Hub.Config({
-Mathematical optimization of convex functions
+Different kernels and Mercer's theorem
-A mathematical (quadratic) optimization problem, or just optimization problem, has the form
+There are several popular kernels being used. These are
+
+
+- Linear: \( K(\boldsymbol{x},\boldsymbol{y})=\boldsymbol{x}^T\boldsymbol{y} \),
+- Polynomial: \( K(\boldsymbol{x},\boldsymbol{y})=(\boldsymbol{x}^T\boldsymbol{y}+\gamma)^d \),
+- Gaussian Radial Basis Function: \( K(\boldsymbol{x},\boldsymbol{y})=\exp{\left(-\gamma\vert\vert\boldsymbol{x}-\boldsymbol{y}\vert\vert^2\right)} \),
+- Tanh: \( K(\boldsymbol{x},\boldsymbol{y})=\tanh{(\boldsymbol{x}^T\boldsymbol{y}+\gamma)} \),
+
+
+and many other ones.
+
+
+An important theorem for us is Mercer's 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
$$
-\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\hspace{0.1cm}to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \wedge \boldsymbol{A}\boldsymbol{\lambda}=f.
-\end{align*}
+K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j).
$$
-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 discussion 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.
+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.
@@ -193,6 +203,8 @@ Convex optimization problems play a central role in applied mathematics and we r
25
26
27
+ 28
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs023.html b/doc/pub/svm/html/._svm-bs023.html
index c03305e33..7523745b2 100644
--- a/doc/pub/svm/html/._svm-bs023.html
+++ b/doc/pub/svm/html/._svm-bs023.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,29 +155,199 @@ MathJax.Hub.Config({
-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
-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.
-
-
-The functions we need are contained in the quadratic programming package CVXOPT and we need to import it together with numpy as
-
+
The moons example
-
import numpy
-import cvxopt
-
-
-This will make our life much easier. You don't need t write your own optimizer.
+
from __future__ import division, print_function, unicode_literals
+import numpy as np
+np.random.seed(42)
+
+import matplotlib
+import matplotlib.pyplot as plt
+plt.rcParams['axes.labelsize'] = 14
+plt.rcParams['xtick.labelsize'] = 12
+plt.rcParams['ytick.labelsize'] = 12
+
+
+from sklearn.svm import SVC
+from sklearn import datasets
+
+
+
+from sklearn.pipeline import Pipeline
+from sklearn.preprocessing import StandardScaler
+from sklearn.svm import LinearSVC
+
+
+from sklearn.datasets import make_moons
+X, y = make_moons(n_samples=100, noise=0.15, random_state=42)
+
+def plot_dataset(X, y, axes):
+ plt.plot(X[:, 0][y==0], X[:, 1][y==0], "bs")
+ plt.plot(X[:, 0][y==1], X[:, 1][y==1], "g^")
+ plt.axis(axes)
+ plt.grid(True, which='both')
+ plt.xlabel(r"$x_1$", fontsize=20)
+ plt.ylabel(r"$x_2$", fontsize=20, rotation=0)
+
+plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
+plt.show()
+
+from sklearn.datasets import make_moons
+from sklearn.pipeline import Pipeline
+from sklearn.preprocessing import PolynomialFeatures
+
+polynomial_svm_clf = Pipeline([
+ ("poly_features", PolynomialFeatures(degree=3)),
+ ("scaler", StandardScaler()),
+ ("svm_clf", LinearSVC(C=10, loss="hinge", random_state=42))
+ ])
+
+polynomial_svm_clf.fit(X, y)
+
+def plot_predictions(clf, axes):
+ x0s = np.linspace(axes[0], axes[1], 100)
+ x1s = np.linspace(axes[2], axes[3], 100)
+ x0, x1 = np.meshgrid(x0s, x1s)
+ X = np.c_[x0.ravel(), x1.ravel()]
+ y_pred = clf.predict(X).reshape(x0.shape)
+ y_decision = clf.decision_function(X).reshape(x0.shape)
+ plt.contourf(x0, x1, y_pred, cmap=plt.cm.brg, alpha=0.2)
+ plt.contourf(x0, x1, y_decision, cmap=plt.cm.brg, alpha=0.1)
+
+plot_predictions(polynomial_svm_clf, [-1.5, 2.5, -1, 1.5])
+plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
+
+plt.show()
+
+
+from sklearn.svm import SVC
+
+poly_kernel_svm_clf = Pipeline([
+ ("scaler", StandardScaler()),
+ ("svm_clf", SVC(kernel="poly", degree=3, coef0=1, C=5))
+ ])
+poly_kernel_svm_clf.fit(X, y)
+
+poly100_kernel_svm_clf = Pipeline([
+ ("scaler", StandardScaler()),
+ ("svm_clf", SVC(kernel="poly", degree=10, coef0=100, C=5))
+ ])
+poly100_kernel_svm_clf.fit(X, y)
+
+plt.figure(figsize=(11, 4))
+
+plt.subplot(121)
+plot_predictions(poly_kernel_svm_clf, [-1.5, 2.5, -1, 1.5])
+plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
+plt.title(r"$d=3, r=1, C=5$", fontsize=18)
+
+plt.subplot(122)
+plot_predictions(poly100_kernel_svm_clf, [-1.5, 2.5, -1, 1.5])
+plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
+plt.title(r"$d=10, r=100, C=5$", fontsize=18)
+
+plt.show()
+
+def gaussian_rbf(x, landmark, gamma):
+ return np.exp(-gamma * np.linalg.norm(x - landmark, axis=1)**2)
+
+gamma = 0.3
+
+x1s = np.linspace(-4.5, 4.5, 200).reshape(-1, 1)
+x2s = gaussian_rbf(x1s, -2, gamma)
+x3s = gaussian_rbf(x1s, 1, gamma)
+
+XK = np.c_[gaussian_rbf(X1D, -2, gamma), gaussian_rbf(X1D, 1, gamma)]
+yk = np.array([0, 0, 1, 1, 1, 1, 1, 0, 0])
+
+plt.figure(figsize=(11, 4))
+
+plt.subplot(121)
+plt.grid(True, which='both')
+plt.axhline(y=0, color='k')
+plt.scatter(x=[-2, 1], y=[0, 0], s=150, alpha=0.5, c="red")
+plt.plot(X1D[:, 0][yk==0], np.zeros(4), "bs")
+plt.plot(X1D[:, 0][yk==1], np.zeros(5), "g^")
+plt.plot(x1s, x2s, "g--")
+plt.plot(x1s, x3s, "b:")
+plt.gca().get_yaxis().set_ticks([0, 0.25, 0.5, 0.75, 1])
+plt.xlabel(r"$x_1$", fontsize=20)
+plt.ylabel(r"Similarity", fontsize=14)
+plt.annotate(r'$\mathbf{x}$',
+ xy=(X1D[3, 0], 0),
+ xytext=(-0.5, 0.20),
+ ha="center",
+ arrowprops=dict(facecolor='black', shrink=0.1),
+ fontsize=18,
+ )
+plt.text(-2, 0.9, "$x_2$", ha="center", fontsize=20)
+plt.text(1, 0.9, "$x_3$", ha="center", fontsize=20)
+plt.axis([-4.5, 4.5, -0.1, 1.1])
+
+plt.subplot(122)
+plt.grid(True, which='both')
+plt.axhline(y=0, color='k')
+plt.axvline(x=0, color='k')
+plt.plot(XK[:, 0][yk==0], XK[:, 1][yk==0], "bs")
+plt.plot(XK[:, 0][yk==1], XK[:, 1][yk==1], "g^")
+plt.xlabel(r"$x_2$", fontsize=20)
+plt.ylabel(r"$x_3$ ", fontsize=20, rotation=0)
+plt.annotate(r'$\phi\left(\mathbf{x}\right)$',
+ xy=(XK[3, 0], XK[3, 1]),
+ xytext=(0.65, 0.50),
+ ha="center",
+ arrowprops=dict(facecolor='black', shrink=0.1),
+ fontsize=18,
+ )
+plt.plot([-0.1, 1.1], [0.57, -0.1], "r--", linewidth=3)
+plt.axis([-0.1, 1.1, -0.1, 1.1])
+
+plt.subplots_adjust(right=1)
+
+plt.show()
+
+
+x1_example = X1D[3, 0]
+for landmark in (-2, 1):
+ k = gaussian_rbf(np.array([[x1_example]]), np.array([[landmark]]), gamma)
+ print("Phi({}, {}) = {}".format(x1_example, landmark, k))
+
+rbf_kernel_svm_clf = Pipeline([
+ ("scaler", StandardScaler()),
+ ("svm_clf", SVC(kernel="rbf", gamma=5, C=0.001))
+ ])
+rbf_kernel_svm_clf.fit(X, y)
+
+
+from sklearn.svm import SVC
+
+gamma1, gamma2 = 0.1, 5
+C1, C2 = 0.001, 1000
+hyperparams = (gamma1, C1), (gamma1, C2), (gamma2, C1), (gamma2, C2)
+
+svm_clfs = []
+for gamma, C in hyperparams:
+ rbf_kernel_svm_clf = Pipeline([
+ ("scaler", StandardScaler()),
+ ("svm_clf", SVC(kernel="rbf", gamma=gamma, C=C))
+ ])
+ rbf_kernel_svm_clf.fit(X, y)
+ svm_clfs.append(rbf_kernel_svm_clf)
+
+plt.figure(figsize=(11, 7))
+
+for i, svm_clf in enumerate(svm_clfs):
+ plt.subplot(221 + i)
+ plot_predictions(svm_clf, [-1.5, 2.5, -1, 1.5])
+ plot_dataset(X, y, [-1.5, 2.5, -1, 1.5])
+ gamma, C = hyperparams[i]
+ plt.title(r"$\gamma = {}, C = {}$".format(gamma, C), fontsize=16)
+
+plt.show()
+
@@ -193,6 +367,8 @@ This will make our life much easier. You don't need t write your own optimizer.
25
26
27
+ 28
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs024.html b/doc/pub/svm/html/._svm-bs024.html
index d0ae1ed08..276edbbfc 100644
--- a/doc/pub/svm/html/._svm-bs024.html
+++ b/doc/pub/svm/html/._svm-bs024.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,71 +155,28 @@ MathJax.Hub.Config({
-A simple example
+Mathematical optimization of convex functions
-We remind ourselves about the general problem we want to solve
+A mathematical (quadratic) optimization problem, or just optimization problem, has the form
$$
\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\hspace{0.1cm} to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{x} \preceq \boldsymbol{h} \wedge \boldsymbol{A}\boldsymbol{x}=f.
+ &\mathrm{min}_{\lambda}\hspace{0.2cm} \frac{1}{2}\boldsymbol{\lambda}^T\boldsymbol{P}\boldsymbol{\lambda}+\boldsymbol{q}^T\boldsymbol{\lambda},\\ \nonumber
+ &\mathrm{subject\hspace{0.1cm}to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{\lambda} \preceq \boldsymbol{h} \wedge \boldsymbol{A}\boldsymbol{\lambda}=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{bmatrix}\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}.
-$$
+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.
-Since we don't have any equalities the matrix \( \boldsymbol{A} \) is set to zero
-The following code solves the equations for us
-
+In our case we are particularly interested in a class of optimization problems called convex optmization problems.
+In our discussion 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.
-
-
# Import the necessary packages
-import numpy
-from cvxopt import matrix
-from cvxopt import solvers
-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’]
-
@@ -234,6 +195,8 @@ sol[’primal objective’]
25
26
27
+ 28
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs025.html b/doc/pub/svm/html/._svm-bs025.html
index 432960660..e857d117b 100644
--- a/doc/pub/svm/html/._svm-bs025.html
+++ b/doc/pub/svm/html/._svm-bs025.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,25 +155,28 @@ MathJax.Hub.Config({
-Back to the more realistic cases
+How do we solve these problems?
-We are now ready to return to our setup of the optmization problem for a more realistic case. Introducing 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_1K(\boldsymbol{x}_2,\boldsymbol{x}_1) & y_2y_2K(\boldsymbol{x}_2,\boldsymbol{x}_2) & \dots & \dots & y_1y_nK(\boldsymbol{x}_2,\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 \).
+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.
-code will be added
+The functions we need are contained in the quadratic programming package CVXOPT and we need to import it together with numpy as
+
+
+
+
+
import numpy
+import cvxopt
+
+
+This will make our life much easier. You don't need t write your own optimizer.
@@ -188,6 +195,8 @@ With the slack constants this leads to the additional constraint \( 0\leq \lamb
25
26
27
+ 28
+ 29
»
diff --git a/doc/pub/svm/html/._svm-bs026.html b/doc/pub/svm/html/._svm-bs026.html
index 18b76c041..09c865519 100644
--- a/doc/pub/svm/html/._svm-bs026.html
+++ b/doc/pub/svm/html/._svm-bs026.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
- A better approach
- A quick reminder on Lagrangian multipliers
- Adding the muliplier
- Setting up the problem
- The problem to solve
- The last steps
- A soft classifier
- Soft optmization problem
- Kernels and non-linearity
- The equations
- The problem to solve
- Different kernels and Mercer's theorem
- The moons example
- Mathematical optimization of convex functions
- How do we solve these problems?
- A simple example
- Back to the more realistic cases
- Code Example
+ Code Example
+ Problems with the Simpler Approach
+ A better approach
+ A quick reminder on Lagrangian multipliers
+ Adding the muliplier
+ Setting up the problem
+ The problem to solve
+ The last steps
+ A soft classifier
+ Soft optmization problem
+ Kernels and non-linearity
+ The equations
+ The problem to solve
+ Different kernels and Mercer's theorem
+ The moons example
+ Mathematical optimization of convex functions
+ How do we solve these problems?
+ A simple example
+ Back to the more realistic cases
+ Code Example
@@ -151,37 +155,72 @@ MathJax.Hub.Config({
-Code Example
+A simple 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\hspace{0.1cm} to} \hspace{0.2cm} \boldsymbol{G}\boldsymbol{x} \preceq \boldsymbol{h} \wedge \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{bmatrix}\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 solves the equations for us
-
import numpy as np
-from scipy.optimize import minimize
-def rosen(x):
- return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)
-def rosen_der(x):
- xm = x[1:-1]
- xm_m1 = x[:-2]
- xm_p1 = x[2:]
- der = np.zeros_like(x)
- der[1:-1] = 200*(xm-xm_m1**2) - 400*(xm_p1 - xm**2)*xm - 2*(1-xm)
- der[0] = -400*x[0]*(x[1]-x[0]**2) - 2*(1-x[0])
- der[-1] = 200*(x[-1]-x[-2]**2)
- return der
-
-
-
-x0 = np.array([1.2, 0.1, 0.8, 1.9, 1.2])
-print(x0)
-res = minimize(rosen, x0, method='nelder-mead',options={'xtol': 1e-8, 'disp': True})
-print(x0)
-
-
-res2 = minimize(rosen, x0, method='BFGS', jac=rosen_der, options={'disp': True})
-print(x0)
+# Import the necessary packages
+import numpy
+from cvxopt import matrix
+from cvxopt import solvers
+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-bs.html b/doc/pub/svm/html/svm-bs.html
index 6fb243975..811e86f4d 100644
--- a/doc/pub/svm/html/svm-bs.html
+++ b/doc/pub/svm/html/svm-bs.html
@@ -49,30 +49,32 @@ Automatically generated HTML file from DocOnce source
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -118,24 +120,26 @@ MathJax.Hub.Config({
Getting into the details
First attempt at a minimization approach
Solving the equations
-
A better approach
-
A quick reminder on Lagrangian multipliers
-
Adding the muliplier
-
Setting up the problem
-
The problem to solve
-
The last steps
-
A soft classifier
-
Soft optmization problem
-
Kernels and non-linearity
-
The equations
-
The problem to solve
-
Different kernels and Mercer's theorem
-
The moons example
-
Mathematical optimization of convex functions
-
How do we solve these problems?
-
A simple example
-
Back to the more realistic cases
-
Code Example
+
Code Example
+
Problems with the Simpler Approach
+
A better approach
+
A quick reminder on Lagrangian multipliers
+
Adding the muliplier
+
Setting up the problem
+
The problem to solve
+
The last steps
+
A soft classifier
+
Soft optmization problem
+
Kernels and non-linearity
+
The equations
+
The problem to solve
+
Different kernels and Mercer's theorem
+
The moons example
+
Mathematical optimization of convex functions
+
How do we solve these problems?
+
A simple example
+
Back to the more realistic cases
+
Code Example
@@ -170,7 +174,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Nov 15, 2019
+
Nov 16, 2019
@@ -194,7 +198,7 @@ MathJax.Hub.Config({
9
10
...
-
27
+
29
»
diff --git a/doc/pub/svm/html/svm-reveal.html b/doc/pub/svm/html/svm-reveal.html
index 0de24dc3a..941055f1b 100644
--- a/doc/pub/svm/html/svm-reveal.html
+++ b/doc/pub/svm/html/svm-reveal.html
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Nov 15, 2019
+
Nov 16, 2019
@@ -448,7 +448,7 @@ $$
Solving the equations
-We can now use the Newton-Raphson method or gradient descent to solve the equations
+We can now use the Newton-Raphson method or different variants of the gradient descent family (from plain gradient descent to various stochastic gradient descent approaches) to solve the equations
$$
b \leftarrow b +\eta \frac{\partial C}{\partial b},
@@ -463,12 +463,34 @@ $$
where \( \eta \) is our by now well-known learning rate.
+
+
+
+
+Code Example
+
+
+The equations we discussed above can be coded rather easily (the
+framework is rather similar to what we developed for logistic
+regression). We use the standard moons example to set up our data
+set. We want to find a line which separates the two classes
+
+
+
+
+
+
+
+
+Problems with the Simpler Approach
There are however problems with this approach, although it looks
-pretty straightforward to implement. In case we separate our data into
-two distinct classes, we may up with many possible lines, as indicated
-in the figure and shown by running the following program. For small
+pretty straightforward to implement. When running the above code, we see that we can easily end up with many diffeent lines which separate the two classes.
+
+
+For small
gaps between the entries, we may also end up needing many iterations
before the solutions converge and if the data cannot be separated
properly into two distinct classes, we may not experience a converge
@@ -477,7 +499,7 @@ at all.
-A better approach
+A better approach
A better approach is rather to try to define a large margin between
@@ -519,12 +541,15 @@ $$
-We have thus defined our margin as the invers of the norm of \( \boldsymbol{w} \). We want to minimize the norm in order to have a as large as possible margin \( M \). Before we proceed, we need to remind ourselves about Lagrangian multipliers.
+We have thus defined our margin as the invers of the norm of
+\( \boldsymbol{w} \). We want to minimize the norm in order to have a as large as
+possible margin \( M \). Before we proceed, we need to remind ourselves
+about Lagrangian multipliers.
-A quick reminder on Lagrangian multipliers
+A quick reminder on Lagrangian multipliers
Consider a function of three independent variables \( f(x,y,z) \) . For the function \( f \) to be an
@@ -586,7 +611,7 @@ Then \( dz \) is no longer arbitrary.
-Adding the muliplier
+Adding the muliplier
However, we can add to
@@ -641,7 +666,7 @@ $$
-Setting up the problem
+Setting up the problem
In order to solve the above problem, we define the following Lagrangian function to be minimized
$$
@@ -693,7 +718,7 @@ When \( \lambda_i > 0 \), the vectors \( \boldsymbol{x}_i \) are called support
-The problem to solve
+The problem to solve
We can rewrite
@@ -721,7 +746,7 @@ subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vec
-The last steps
+The last steps
Solving the above problem, yields the values of \( \lambda_i \).
@@ -765,7 +790,7 @@ Below we discuss how to find the optimal values of \( \lambda_i \). Before we pr
-A soft classifier
+A soft classifier
Till now, the margin is strictly defined by the support vectors. This defines what is called a hard classifier, that is the margins are well defined.
@@ -804,7 +829,7 @@ misclassifications.
-Soft optmization problem
+Soft optmization problem
This has in turn the consequences that we change our optmization problem to finding the minimum of
@@ -876,7 +901,7 @@ $$
-Kernels and non-linearity
+Kernels and non-linearity
The cases we have studied till were all characterized by two classes
@@ -950,7 +975,7 @@ plt.show()
-The equations
+The equations
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)
@@ -1002,7 +1027,7 @@ the trouble of performing the transformation
-The problem to solve
+The problem to solve
Using our definition of the kernel We can rewrite again the Lagrangian
$$
@@ -1044,7 +1069,7 @@ Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up.
-Different kernels and Mercer's theorem
+Different kernels and Mercer's theorem
There are several popular kernels being used. These are
@@ -1078,7 +1103,7 @@ well in practice.
-The moons example
+The moons example
@@ -1275,7 +1300,7 @@ plt.show()
-Mathematical optimization of convex functions
+Mathematical optimization of convex functions
A mathematical (quadratic) optimization problem, or just optimization problem, has the form
@@ -1302,7 +1327,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
@@ -1328,7 +1353,7 @@ This will make our life much easier. You don't need t write your own optimizer.
-A simple example
+A simple example
We remind ourselves about the general problem we want to solve
@@ -1409,7 +1434,7 @@ sol[’primal obj
-Back to the more realistic cases
+Back to the more realistic cases
We are now ready to return to our setup of the optmization problem for a more realistic case. Introducing the slack parameter \( C \) we have
@@ -1434,7 +1459,7 @@ With the slack constants this leads to the additional constraint \( 0\leq \lamb
-Code Example
+Code Example
diff --git a/doc/pub/svm/html/svm-solarized.html b/doc/pub/svm/html/svm-solarized.html
index 6d50f6a4e..c4b108daf 100644
--- a/doc/pub/svm/html/svm-solarized.html
+++ b/doc/pub/svm/html/svm-solarized.html
@@ -43,30 +43,32 @@ div { text-align: justify; text-justify: inter-word; }
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -108,7 +110,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Nov 15, 2019
+Nov 16, 2019
@@ -377,7 +379,7 @@ $$
Solving the equations
-We can now use the Newton-Raphson method or gradient descent to solve the equations
+We can now use the Newton-Raphson method or different variants of the gradient descent family (from plain gradient descent to various stochastic gradient descent approaches) to solve the equations
$$
b \leftarrow b +\eta \frac{\partial C}{\partial b},
$$
@@ -389,11 +391,32 @@ $$
where \( \eta \) is our by now well-known learning rate.
+
+
+
+
Code Example
+
+
+The equations we discussed above can be coded rather easily (the
+framework is rather similar to what we developed for logistic
+regression). We use the standard moons example to set up our data
+set. We want to find a line which separates the two classes
+
+
+
+
+
+
+
+
Problems with the Simpler Approach
+
There are however problems with this approach, although it looks
-pretty straightforward to implement. In case we separate our data into
-two distinct classes, we may up with many possible lines, as indicated
-in the figure and shown by running the following program. For small
+pretty straightforward to implement. When running the above code, we see that we can easily end up with many diffeent lines which separate the two classes.
+
+
+For small
gaps between the entries, we may also end up needing many iterations
before the solutions converge and if the data cannot be separated
properly into two distinct classes, we may not experience a converge
@@ -402,7 +425,7 @@ at all.
-
A better approach
+A better approach
A better approach is rather to try to define a large margin between
@@ -436,12 +459,15 @@ y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq 1 \hspace{0.1cm}\forall i.
$$
-We have thus defined our margin as the invers of the norm of \( \boldsymbol{w} \). We want to minimize the norm in order to have a as large as possible margin \( M \). Before we proceed, we need to remind ourselves about Lagrangian multipliers.
+We have thus defined our margin as the invers of the norm of
+\( \boldsymbol{w} \). We want to minimize the norm in order to have a as large as
+possible margin \( M \). Before we proceed, we need to remind ourselves
+about Lagrangian multipliers.
-
A quick reminder on Lagrangian multipliers
+A quick reminder on Lagrangian multipliers
Consider a function of three independent variables \( f(x,y,z) \) . For the function \( f \) to be an
@@ -491,7 +517,7 @@ Then \( dz \) is no longer arbitrary.
-
Adding the muliplier
+Adding the muliplier
However, we can add to
@@ -534,7 +560,7 @@ $$
-
Setting up the problem
+Setting up the problem
In order to solve the above problem, we define the following Lagrangian function to be minimized
$$
{\cal L}(\lambda,b,\boldsymbol{w})=\frac{1}{2}\boldsymbol{w}^T\boldsymbol{w}-\sum_{i=1}^n\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)-1\right],
@@ -575,7 +601,7 @@ When \( \lambda_i > 0 \), the vectors \( \boldsymbol{x}_i \) are called support
-
The problem to solve
+The problem to solve
We can rewrite
@@ -599,7 +625,7 @@ subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vec
-
The last steps
+The last steps
Solving the above problem, yields the values of \( \lambda_i \).
@@ -633,7 +659,7 @@ Below we discuss how to find the optimal values of \( \lambda_i \). Before we pr
-
A soft classifier
+A soft classifier
Till now, the margin is strictly defined by the support vectors. This defines what is called a hard classifier, that is the margins are well defined.
@@ -668,7 +694,7 @@ misclassifications.
-
Soft optmization problem
+Soft optmization problem
This has in turn the consequences that we change our optmization problem to finding the minimum of
@@ -722,7 +748,7 @@ $$
-
Kernels and non-linearity
+Kernels and non-linearity
The cases we have studied till were all characterized by two classes
@@ -795,7 +821,7 @@ plt.show()
-
The equations
+The equations
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)
@@ -837,7 +863,7 @@ the trouble of performing the transformation
-
The problem to solve
+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,
@@ -873,7 +899,7 @@ Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up.
-
Different kernels and Mercer's theorem
+Different kernels and Mercer's theorem
There are several popular kernels being used. These are
@@ -904,7 +930,7 @@ well in practice.
-
The moons example
+The moons example
@@ -1100,7 +1126,7 @@ plt.show()
-
Mathematical optimization of convex functions
+Mathematical optimization of convex functions
A mathematical (quadratic) optimization problem, or just optimization problem, has the form
@@ -1125,7 +1151,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
@@ -1151,7 +1177,7 @@ This will make our life much easier. You don't need t write your own optimizer.
-
A simple example
+A simple example
We remind ourselves about the general problem we want to solve
@@ -1219,7 +1245,7 @@ sol[’primal obj
-
Back to the more realistic cases
+Back to the more realistic cases
We are now ready to return to our setup of the optmization problem for a more realistic case. Introducing the slack parameter \( C \) we have
@@ -1242,7 +1268,7 @@ With the slack constants this leads to the additional constraint \( 0\leq \lamb
-
Code Example
+Code Example
diff --git a/doc/pub/svm/html/svm.html b/doc/pub/svm/html/svm.html
index 0ac067ea2..ad3d86721 100644
--- a/doc/pub/svm/html/svm.html
+++ b/doc/pub/svm/html/svm.html
@@ -48,30 +48,32 @@ div { text-align: justify; text-justify: inter-word; }
('Getting into the details', 2, None, '___sec5'),
('First attempt at a minimization approach', 2, None, '___sec6'),
('Solving the equations', 2, None, '___sec7'),
- ('A better approach', 2, None, '___sec8'),
+ ('Code Example', 2, None, '___sec8'),
+ ('Problems with the Simpler Approach', 2, None, '___sec9'),
+ ('A better approach', 2, None, '___sec10'),
('A quick reminder on Lagrangian multipliers',
2,
None,
- '___sec9'),
- ('Adding the muliplier', 2, None, '___sec10'),
- ('Setting up the problem', 2, None, '___sec11'),
- ('The problem to solve', 2, None, '___sec12'),
- ('The last steps', 2, None, '___sec13'),
- ('A soft classifier', 2, None, '___sec14'),
- ('Soft optmization problem', 2, None, '___sec15'),
- ('Kernels and non-linearity', 2, None, '___sec16'),
- ('The equations', 2, None, '___sec17'),
- ('The problem to solve', 2, None, '___sec18'),
- ("Different kernels and Mercer's theorem", 2, None, '___sec19'),
- ('The moons example', 2, None, '___sec20'),
+ '___sec11'),
+ ('Adding the muliplier', 2, None, '___sec12'),
+ ('Setting up the problem', 2, None, '___sec13'),
+ ('The problem to solve', 2, None, '___sec14'),
+ ('The last steps', 2, None, '___sec15'),
+ ('A soft classifier', 2, None, '___sec16'),
+ ('Soft optmization problem', 2, None, '___sec17'),
+ ('Kernels and non-linearity', 2, None, '___sec18'),
+ ('The equations', 2, None, '___sec19'),
+ ('The problem to solve', 2, None, '___sec20'),
+ ("Different kernels and Mercer's theorem", 2, None, '___sec21'),
+ ('The moons example', 2, None, '___sec22'),
('Mathematical optimization of convex functions',
2,
None,
- '___sec21'),
- ('How do we solve these problems?', 2, None, '___sec22'),
- ('A simple example', 2, None, '___sec23'),
- ('Back to the more realistic cases', 2, None, '___sec24'),
- ('Code Example', 2, None, '___sec25')]}
+ '___sec23'),
+ ('How do we solve these problems?', 2, None, '___sec24'),
+ ('A simple example', 2, None, '___sec25'),
+ ('Back to the more realistic cases', 2, None, '___sec26'),
+ ('Code Example', 2, None, '___sec27')]}
end of tocinfo -->
@@ -113,7 +115,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Nov 15, 2019
+Nov 16, 2019
@@ -382,7 +384,7 @@ $$
Solving the equations
-We can now use the Newton-Raphson method or gradient descent to solve the equations
+We can now use the Newton-Raphson method or different variants of the gradient descent family (from plain gradient descent to various stochastic gradient descent approaches) to solve the equations
$$
b \leftarrow b +\eta \frac{\partial C}{\partial b},
$$
@@ -394,11 +396,32 @@ $$
where \( \eta \) is our by now well-known learning rate.
+
+
+
+
Code Example
+
+
+The equations we discussed above can be coded rather easily (the
+framework is rather similar to what we developed for logistic
+regression). We use the standard moons example to set up our data
+set. We want to find a line which separates the two classes
+
+
+
+
+
+
+
+
Problems with the Simpler Approach
+
There are however problems with this approach, although it looks
-pretty straightforward to implement. In case we separate our data into
-two distinct classes, we may up with many possible lines, as indicated
-in the figure and shown by running the following program. For small
+pretty straightforward to implement. When running the above code, we see that we can easily end up with many diffeent lines which separate the two classes.
+
+
+For small
gaps between the entries, we may also end up needing many iterations
before the solutions converge and if the data cannot be separated
properly into two distinct classes, we may not experience a converge
@@ -407,7 +430,7 @@ at all.
-
A better approach
+A better approach
A better approach is rather to try to define a large margin between
@@ -441,12 +464,15 @@ y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) \geq 1 \hspace{0.1cm}\forall i.
$$
-We have thus defined our margin as the invers of the norm of \( \boldsymbol{w} \). We want to minimize the norm in order to have a as large as possible margin \( M \). Before we proceed, we need to remind ourselves about Lagrangian multipliers.
+We have thus defined our margin as the invers of the norm of
+\( \boldsymbol{w} \). We want to minimize the norm in order to have a as large as
+possible margin \( M \). Before we proceed, we need to remind ourselves
+about Lagrangian multipliers.
-
A quick reminder on Lagrangian multipliers
+A quick reminder on Lagrangian multipliers
Consider a function of three independent variables \( f(x,y,z) \) . For the function \( f \) to be an
@@ -496,7 +522,7 @@ Then \( dz \) is no longer arbitrary.
-
Adding the muliplier
+Adding the muliplier
However, we can add to
@@ -539,7 +565,7 @@ $$
-
Setting up the problem
+Setting up the problem
In order to solve the above problem, we define the following Lagrangian function to be minimized
$$
{\cal L}(\lambda,b,\boldsymbol{w})=\frac{1}{2}\boldsymbol{w}^T\boldsymbol{w}-\sum_{i=1}^n\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)-1\right],
@@ -580,7 +606,7 @@ When \( \lambda_i > 0 \), the vectors \( \boldsymbol{x}_i \) are called support
-
The problem to solve
+The problem to solve
We can rewrite
@@ -604,7 +630,7 @@ subject to \( \boldsymbol{y}^T\boldsymbol{\lambda}=0 \). Here we defined the vec
-
The last steps
+The last steps
Solving the above problem, yields the values of \( \lambda_i \).
@@ -638,7 +664,7 @@ Below we discuss how to find the optimal values of \( \lambda_i \). Before we pr
-
A soft classifier
+A soft classifier
Till now, the margin is strictly defined by the support vectors. This defines what is called a hard classifier, that is the margins are well defined.
@@ -673,7 +699,7 @@ misclassifications.
-
Soft optmization problem
+Soft optmization problem
This has in turn the consequences that we change our optmization problem to finding the minimum of
@@ -727,7 +753,7 @@ $$
-
Kernels and non-linearity
+Kernels and non-linearity
The cases we have studied till were all characterized by two classes
@@ -800,7 +826,7 @@ plt.show()
-
The equations
+The equations
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)
@@ -842,7 +868,7 @@ the trouble of performing the transformation
-
The problem to solve
+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,
@@ -878,7 +904,7 @@ Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up.
-
Different kernels and Mercer's theorem
+Different kernels and Mercer's theorem
There are several popular kernels being used. These are
@@ -909,7 +935,7 @@ well in practice.
-
The moons example
+The moons example
@@ -1105,7 +1131,7 @@ plt.show()
-
Mathematical optimization of convex functions
+Mathematical optimization of convex functions
A mathematical (quadratic) optimization problem, or just optimization problem, has the form
@@ -1130,7 +1156,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
@@ -1156,7 +1182,7 @@ This will make our life much easier. You don't need t write your own optimizer.
-
A simple example
+A simple example
We remind ourselves about the general problem we want to solve
@@ -1224,7 +1250,7 @@ sol[’primal objective’]
-
Back to the more realistic cases
+Back to the more realistic cases
We are now ready to return to our setup of the optmization problem for a more realistic case. Introducing the slack parameter \( C \) we have
@@ -1247,7 +1273,7 @@ With the slack constants this leads to the additional constraint \( 0\leq \lamb
-
Code Example
+Code Example
diff --git a/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz b/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz
index ce0d030c0..ab001d657 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 32030fd82..5dc073bd4 100644
--- a/doc/pub/svm/ipynb/svm.ipynb
+++ b/doc/pub/svm/ipynb/svm.ipynb
@@ -10,7 +10,7 @@
" \n",
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
"\n",
- "Date: **Nov 15, 2019**\n",
+ "Date: **Nov 16, 2019**\n",
"\n",
"Copyright 1999-2019, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
@@ -385,7 +385,7 @@
"source": [
"## Solving the equations\n",
"\n",
- "We can now use the Newton-Raphson method or gradient descent to solve the equations"
+ "We can now use the Newton-Raphson method or different variants of the gradient descent family (from plain gradient descent to various stochastic gradient descent approaches) to solve the equations"
]
},
{
@@ -419,10 +419,27 @@
"source": [
"where $\\eta$ is our by now well-known learning rate. \n",
"\n",
+ "\n",
+ "## Code Example\n",
+ "\n",
+ "The equations we discussed above can be coded rather easily (the\n",
+ "framework is rather similar to what we developed for logistic\n",
+ "regression). We use the standard moons example to set up our data\n",
+ "set. We want to find a line which separates the two classes"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Problems with the Simpler Approach\n",
+ "\n",
+ "\n",
"There are however problems with this approach, although it looks\n",
- "pretty straightforward to implement. In case we separate our data into\n",
- "two distinct classes, we may up with many possible lines, as indicated\n",
- "in the figure and shown by running the following program. For small\n",
+ "pretty straightforward to implement. When running the above code, we see that we can easily end up with many diffeent lines which separate the two classes.\n",
+ "\n",
+ "\n",
+ "For small\n",
"gaps between the entries, we may also end up needing many iterations\n",
"before the solutions converge and if the data cannot be separated\n",
"properly into two distinct classes, we may not experience a converge\n",
@@ -501,7 +518,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We have thus defined our margin as the invers of the norm of $\\boldsymbol{w}$. We want to minimize the norm in order to have a as large as possible margin $M$. Before we proceed, we need to remind ourselves about Lagrangian multipliers. \n",
+ "We have thus defined our margin as the invers of the norm of\n",
+ "$\\boldsymbol{w}$. We want to minimize the norm in order to have a as large as\n",
+ "possible margin $M$. Before we proceed, we need to remind ourselves\n",
+ "about Lagrangian multipliers.\n",
"\n",
"## A quick reminder on Lagrangian multipliers\n",
"\n",
diff --git a/doc/pub/svm/pdf/svm-minted.pdf b/doc/pub/svm/pdf/svm-minted.pdf
index e2221619b..7bcee8577 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 2467a8efe..fda01db6e 100644
--- a/doc/src/SupportVMachines/svm.do.txt
+++ b/doc/src/SupportVMachines/svm.do.txt
@@ -110,11 +110,6 @@ plt.show()
-
-
-
-
-
!ec
@@ -260,7 +255,7 @@ and
!split
===== Solving the equations =====
-We can now use the Newton-Raphson method or gradient descent to solve the equations
+We can now use the Newton-Raphson method or different variants of the gradient descent family (from plain gradient descent to various stochastic gradient descent approaches) to solve the equations
!bt
\[
b \leftarrow b +\eta \frac{\partial C}{\partial b},
@@ -274,10 +269,27 @@ and
!et
where $\eta$ is our by now well-known learning rate.
+
+!split
+===== Code Example =====
+
+The equations we discussed above can be coded rather easily (the
+framework is rather similar to what we developed for logistic
+regression). We use the standard moons example to set up our data
+set. We want to find a line which separates the two classes
+!bc pycod
+
+!ec
+
+!split
+===== Problems with the Simpler Approach =====
+
+
There are however problems with this approach, although it looks
-pretty straightforward to implement. In case we separate our data into
-two distinct classes, we may up with many possible lines, as indicated
-in the figure and shown by running the following program. For small
+pretty straightforward to implement. When running the above code, we see that we can easily end up with many diffeent lines which separate the two classes.
+
+
+For small
gaps between the entries, we may also end up needing many iterations
before the solutions converge and if the data cannot be separated
properly into two distinct classes, we may not experience a converge
@@ -319,7 +331,10 @@ y_i(\bm{w}^T\bm{x}_i+b) \geq 1 \hspace{0.1cm}\forall i.
\]
!et
-We have thus defined our margin as the invers of the norm of $\bm{w}$. We want to minimize the norm in order to have a as large as possible margin $M$. Before we proceed, we need to remind ourselves about Lagrangian multipliers.
+We have thus defined our margin as the invers of the norm of
+$\bm{w}$. We want to minimize the norm in order to have a as large as
+possible margin $M$. Before we proceed, we need to remind ourselves
+about Lagrangian multipliers.
!split
===== A quick reminder on Lagrangian multipliers =====