diff --git a/doc/pub/week46/html/._week46-bs000.html b/doc/pub/week46/html/._week46-bs000.html index 64fb461b5..07c7b1a4d 100644 --- a/doc/pub/week46/html/._week46-bs000.html +++ b/doc/pub/week46/html/._week46-bs000.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -185,7 +195,7 @@ MathJax.Hub.Config({
    -

    Nov 12, 2022

    +

    Nov 13, 2022


    @@ -210,7 +220,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs001.html b/doc/pub/week46/html/._week46-bs001.html index 60ed29a13..4b3236834 100644 --- a/doc/pub/week46/html/._week46-bs001.html +++ b/doc/pub/week46/html/._week46-bs001.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -171,7 +181,7 @@ MathJax.Hub.Config({
    @@ -214,7 +224,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs002.html b/doc/pub/week46/html/._week46-bs002.html index a84277617..831f68202 100644 --- a/doc/pub/week46/html/._week46-bs002.html +++ b/doc/pub/week46/html/._week46-bs002.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,36 +177,20 @@ MathJax.Hub.Config({

     

     

     

    -

    Support Vector Machines, overarching aims

    +

    Eventual mini-workshop on project 3, Friday November 18

    -

    A Support Vector Machine (SVM) is a very powerful and versatile -Machine Learning method, capable of performing linear or nonlinear -classification, regression, and even outlier detection. It is one of -the most popular models in Machine Learning, and anyone interested in -Machine Learning should have it in their toolbox. SVMs are -particularly well suited for classification of complex but small-sized or -medium-sized datasets. -

    - -

    The case with two well-separated classes only can be understood in an -intuitive way in terms of lines in a two-dimensional space separating -the two classes (see figure below). -

    - -

    The basic mathematics behind the SVM is however less familiar to most of us. -It relies on the definition of hyperplanes and the -definition of a margin which separates classes (in case of -classification problems) of variables. It is also used for regression -problems. -

    - -

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

    +

    We have tried every year to organize a kind of mini-workshop on project 3. In 2020 the contributions were (and some of these ended up in thesis work and/or publications, online only due to Covid-19!)

    +

    diff --git a/doc/pub/week46/html/._week46-bs003.html b/doc/pub/week46/html/._week46-bs003.html index 5e5dc7b82..22fa5b46d 100644 --- a/doc/pub/week46/html/._week46-bs003.html +++ b/doc/pub/week46/html/._week46-bs003.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,109 +177,18 @@ MathJax.Hub.Config({

     

     

     

    -

    Hyperplanes and all that

    +

    Workshop topics 2021 (partly online)

    -

    The theory behind support vector machines (SVM hereafter) is based on -the mathematical description of so-called hyperplanes. Let us start -with a two-dimensional case. This will also allow us to introduce our -first SVM examples. These will be tailored to the case of two specific -classes, as displayed in the figure here based on the usage of the petal data. +

      +
    1. 1215-1225pm: Are Frode Helvig Kvanum, Gard Høivang, and David Andreas Bordvik, Next-day forecasts on spot prices for electricity
    2. +
    3. 1225-1235pm: Lidia Luque, Voxel-wise multi-label brain tumor classification
    4. +
    5. 1235-1245pm: Marcus Berget et al, Locating suspicious brain activity using neural networks
    6. +
    7. 1245-1255pm: William Ho and Tom-Ruben Traavik Kvalvaag, Comparing semi-supervised learning and supervised learning for image classification
    8. +
    +

    We would very much like to organize something similar this year as well. Feel free to come with sugesstions by Thursday November 17. We will then try to set up the various contributions for Friday November 18. +The presentations last normally 5-15 mins and span from loose ideas to more well-defined topics. Nothing pretentious, we wish to keep this as low-key as possible.

    -

    We assume here that our data set can be well separated into two -domains, where a straight line does the job in the separating the two -classes. Here the two classes are represented by either squares or -circles. -

    - - -
    -
    -
    -
    -
    -
    from sklearn import datasets
    -from sklearn.svm import SVC, LinearSVC
    -from sklearn.linear_model import SGDClassifier
    -from sklearn.preprocessing import StandardScaler
    -import matplotlib
    -import matplotlib.pyplot as plt
    -plt.rcParams['axes.labelsize'] = 14
    -plt.rcParams['xtick.labelsize'] = 12
    -plt.rcParams['ytick.labelsize'] = 12
    -
    -
    -iris = datasets.load_iris()
    -X = iris["data"][:, (2, 3)]  # petal length, petal width
    -y = iris["target"]
    -
    -setosa_or_versicolor = (y == 0) | (y == 1)
    -X = X[setosa_or_versicolor]
    -y = y[setosa_or_versicolor]
    -
    -
    -
    -C = 5
    -alpha = 1 / (C * len(X))
    -
    -lin_clf = LinearSVC(loss="hinge", C=C, random_state=42)
    -svm_clf = SVC(kernel="linear", C=C)
    -sgd_clf = SGDClassifier(loss="hinge", learning_rate="constant", eta0=0.001, alpha=alpha,
    -                        max_iter=100000, random_state=42)
    -
    -scaler = StandardScaler()
    -X_scaled = scaler.fit_transform(X)
    -
    -lin_clf.fit(X_scaled, y)
    -svm_clf.fit(X_scaled, y)
    -sgd_clf.fit(X_scaled, y)
    -
    -print("LinearSVC:                   ", lin_clf.intercept_, lin_clf.coef_)
    -print("SVC:                         ", svm_clf.intercept_, svm_clf.coef_)
    -print("SGDClassifier(alpha={:.5f}):".format(sgd_clf.alpha), sgd_clf.intercept_, sgd_clf.coef_)
    -
    -# Compute the slope and bias of each decision boundary
    -w1 = -lin_clf.coef_[0, 0]/lin_clf.coef_[0, 1]
    -b1 = -lin_clf.intercept_[0]/lin_clf.coef_[0, 1]
    -w2 = -svm_clf.coef_[0, 0]/svm_clf.coef_[0, 1]
    -b2 = -svm_clf.intercept_[0]/svm_clf.coef_[0, 1]
    -w3 = -sgd_clf.coef_[0, 0]/sgd_clf.coef_[0, 1]
    -b3 = -sgd_clf.intercept_[0]/sgd_clf.coef_[0, 1]
    -
    -# Transform the decision boundary lines back to the original scale
    -line1 = scaler.inverse_transform([[-10, -10 * w1 + b1], [10, 10 * w1 + b1]])
    -line2 = scaler.inverse_transform([[-10, -10 * w2 + b2], [10, 10 * w2 + b2]])
    -line3 = scaler.inverse_transform([[-10, -10 * w3 + b3], [10, 10 * w3 + b3]])
    -
    -# Plot all three decision boundaries
    -plt.figure(figsize=(11, 4))
    -plt.plot(line1[:, 0], line1[:, 1], "k:", label="LinearSVC")
    -plt.plot(line2[:, 0], line2[:, 1], "b--", linewidth=2, label="SVC")
    -plt.plot(line3[:, 0], line3[:, 1], "r-", label="SGDClassifier")
    -plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs") # label="Iris-Versicolor"
    -plt.plot(X[:, 0][y==0], X[:, 1][y==0], "yo") # label="Iris-Setosa"
    -plt.xlabel("Petal length", fontsize=14)
    -plt.ylabel("Petal width", fontsize=14)
    -plt.legend(loc="upper center", fontsize=14)
    -plt.axis([0, 5.5, 0, 2])
    -
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    diff --git a/doc/pub/week46/html/._week46-bs004.html b/doc/pub/week46/html/._week46-bs004.html index bd5fa5c15..b738f91ca 100644 --- a/doc/pub/week46/html/._week46-bs004.html +++ b/doc/pub/week46/html/._week46-bs004.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,33 +177,35 @@ MathJax.Hub.Config({

     

     

     

    -

    What is a hyperplane?

    +

    Support Vector Machines, overarching aims

    -

    The aim of the SVM algorithm is to find a hyperplane in a -\( p \)-dimensional space, where \( p \) is the number of features that -distinctly classifies the data points. +

    A Support Vector Machine (SVM) is a very powerful and versatile +Machine Learning method, capable of performing linear or nonlinear +classification, regression, and even outlier detection. It is one of +the most popular models in Machine Learning, and anyone interested in +Machine Learning should have it in their toolbox. SVMs are +particularly well suited for classification of complex but small-sized or +medium-sized datasets.

    -

    In a \( p \)-dimensional space, a hyperplane is what we call an affine subspace of dimension of \( p-1 \). -As an example, in two dimension, a hyperplane is simply as straight line while in three dimensions it is -a two-dimensional subspace, or stated simply, a plane. +

    The case with two well-separated classes only can be understood in an +intuitive way in terms of lines in a two-dimensional space separating +the two classes (see figure below).

    -

    In two dimensions, with the variables \( x_1 \) and \( x_2 \), the hyperplane is defined as

    -$$ -b+w_1x_1+w_2x_2=0, -$$ - -

    where \( b \) is the intercept and \( w_1 \) and \( w_2 \) define the elements of a vector orthogonal to the line -\( b+w_1x_1+w_2x_2=0 \). -In two dimensions we define the vectors \( \boldsymbol{x} =[x1,x2] \) and \( \boldsymbol{w}=[w1,w2] \). -We can then rewrite the above equation as +

    The basic mathematics behind the SVM is however less familiar to most of us. +It relies on the definition of hyperplanes and the +definition of a margin which separates classes (in case of +classification problems) of variables. It is also used for regression +problems.

    -$$ -\boldsymbol{x}^T\boldsymbol{w}+b=0. -$$ - +

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

    @@ -214,7 +226,7 @@ $$

  • 13
  • 14
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs005.html b/doc/pub/week46/html/._week46-bs005.html index 2ba60a3a0..c7211e214 100644 --- a/doc/pub/week46/html/._week46-bs005.html +++ b/doc/pub/week46/html/._week46-bs005.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,45 +177,108 @@ MathJax.Hub.Config({

     

     

     

    -

    A \( p \)-dimensional space of features

    +

    Hyperplanes and all that

    -

    We limit ourselves to two classes of outputs \( y_i \) and assign these classes the values \( y_i = \pm 1 \). -In a \( p \)-dimensional space of say \( p \) features we have a hyperplane defines as -

    -$$ -b+wx_1+w_2x_2+\dots +w_px_p=0. -$$ - -

    If we define a -matrix \( \boldsymbol{X}=\left[\boldsymbol{x}_1,\boldsymbol{x}_2,\dots, \boldsymbol{x}_p\right] \) -of dimension \( n\times p \), where \( n \) represents the observations for each feature and each vector \( x_i \) is a column vector of the matrix \( \boldsymbol{X} \), -

    -$$ -\boldsymbol{x}_i = \begin{bmatrix} x_{i1} \\ x_{i2} \\ \dots \\ \dots \\ x_{ip} \end{bmatrix}. -$$ - -

    If the above condition is not met for a given vector \( \boldsymbol{x}_i \) we have

    -$$ -b+w_1x_{i1}+w_2x_{i2}+\dots +w_px_{ip} >0, -$$ - -

    if our output \( y_i=1 \). -In this case we say that \( \boldsymbol{x}_i \) lies on one of the sides of the hyperplane and if -

    -$$ -b+w_1x_{i1}+w_2x_{i2}+\dots +w_px_{ip} < 0, -$$ - -

    for the class of observations \( y_i=-1 \), -then \( \boldsymbol{x}_i \) lies on the other side. +

    The theory behind support vector machines (SVM hereafter) is based on +the mathematical description of so-called hyperplanes. Let us start +with a two-dimensional case. This will also allow us to introduce our +first SVM examples. These will be tailored to the case of two specific +classes, as displayed in the figure here based on the usage of the petal data.

    -

    Equivalently, for the two classes of observations we have

    -$$ -y_i\left(b+w_1x_{i1}+w_2x_{i2}+\dots +w_px_{ip}\right) > 0. -$$ +

    We assume here that our data set can be well separated into two +domains, where a straight line does the job in the separating the two +classes. Here the two classes are represented by either squares or +circles. +

    + + +
    +
    +
    +
    +
    +
    from sklearn import datasets
    +from sklearn.svm import SVC, LinearSVC
    +from sklearn.linear_model import SGDClassifier
    +from sklearn.preprocessing import StandardScaler
    +import matplotlib
    +import matplotlib.pyplot as plt
    +plt.rcParams['axes.labelsize'] = 14
    +plt.rcParams['xtick.labelsize'] = 12
    +plt.rcParams['ytick.labelsize'] = 12
    +
    +
    +iris = datasets.load_iris()
    +X = iris["data"][:, (2, 3)]  # petal length, petal width
    +y = iris["target"]
    +
    +setosa_or_versicolor = (y == 0) | (y == 1)
    +X = X[setosa_or_versicolor]
    +y = y[setosa_or_versicolor]
    +
    +
    +
    +C = 5
    +alpha = 1 / (C * len(X))
    +
    +lin_clf = LinearSVC(loss="hinge", C=C, random_state=42)
    +svm_clf = SVC(kernel="linear", C=C)
    +sgd_clf = SGDClassifier(loss="hinge", learning_rate="constant", eta0=0.001, alpha=alpha,
    +                        max_iter=100000, random_state=42)
    +
    +scaler = StandardScaler()
    +X_scaled = scaler.fit_transform(X)
    +
    +lin_clf.fit(X_scaled, y)
    +svm_clf.fit(X_scaled, y)
    +sgd_clf.fit(X_scaled, y)
    +
    +print("LinearSVC:                   ", lin_clf.intercept_, lin_clf.coef_)
    +print("SVC:                         ", svm_clf.intercept_, svm_clf.coef_)
    +print("SGDClassifier(alpha={:.5f}):".format(sgd_clf.alpha), sgd_clf.intercept_, sgd_clf.coef_)
    +
    +# Compute the slope and bias of each decision boundary
    +w1 = -lin_clf.coef_[0, 0]/lin_clf.coef_[0, 1]
    +b1 = -lin_clf.intercept_[0]/lin_clf.coef_[0, 1]
    +w2 = -svm_clf.coef_[0, 0]/svm_clf.coef_[0, 1]
    +b2 = -svm_clf.intercept_[0]/svm_clf.coef_[0, 1]
    +w3 = -sgd_clf.coef_[0, 0]/sgd_clf.coef_[0, 1]
    +b3 = -sgd_clf.intercept_[0]/sgd_clf.coef_[0, 1]
    +
    +# Transform the decision boundary lines back to the original scale
    +line1 = scaler.inverse_transform([[-10, -10 * w1 + b1], [10, 10 * w1 + b1]])
    +line2 = scaler.inverse_transform([[-10, -10 * w2 + b2], [10, 10 * w2 + b2]])
    +line3 = scaler.inverse_transform([[-10, -10 * w3 + b3], [10, 10 * w3 + b3]])
    +
    +# Plot all three decision boundaries
    +plt.figure(figsize=(11, 4))
    +plt.plot(line1[:, 0], line1[:, 1], "k:", label="LinearSVC")
    +plt.plot(line2[:, 0], line2[:, 1], "b--", linewidth=2, label="SVC")
    +plt.plot(line3[:, 0], line3[:, 1], "r-", label="SGDClassifier")
    +plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs") # label="Iris-Versicolor"
    +plt.plot(X[:, 0][y==0], X[:, 1][y==0], "yo") # label="Iris-Setosa"
    +plt.xlabel("Petal length", fontsize=14)
    +plt.ylabel("Petal width", fontsize=14)
    +plt.legend(loc="upper center", fontsize=14)
    +plt.axis([0, 5.5, 0, 2])
    +
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    When we try to separate hyperplanes, if it exists, we can use it to construct a natural classifier: a test observation is assigned a given class depending on which side of the hyperplane it is located.

    @@ -227,7 +300,7 @@ $$

  • 14
  • 15
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs006.html b/doc/pub/week46/html/._week46-bs006.html index d6e66576c..51d308c1d 100644 --- a/doc/pub/week46/html/._week46-bs006.html +++ b/doc/pub/week46/html/._week46-bs006.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -166,31 +176,35 @@ MathJax.Hub.Config({

     

     

     

    - -

    The two-dimensional case

    + +

    What is a hyperplane?

    -

    Let us try to develop our intuition about SVMs by limiting ourselves to a two-dimensional -plane. To separate the two classes of data points, there are many -possible lines (hyperplanes if you prefer a more strict naming) -that could be chosen. Our objective is to find a -plane that has the maximum margin, i.e the maximum distance between -data points of both classes. Maximizing the margin distance provides -some reinforcement so that future data points can be classified with -more confidence. +

    The aim of the SVM algorithm is to find a hyperplane in a +\( p \)-dimensional space, where \( p \) is the number of features that +distinctly classifies the data points.

    -

    What a linear classifier attempts to accomplish is to split the -feature space into two half spaces by placing a hyperplane between the -data points. This hyperplane will be our decision boundary. All -points on one side of the plane will belong to class one and all points -on the other side of the plane will belong to the second class two. +

    In a \( p \)-dimensional space, a hyperplane is what we call an affine subspace of dimension of \( p-1 \). +As an example, in two dimension, a hyperplane is simply as straight line while in three dimensions it is +a two-dimensional subspace, or stated simply, a plane.

    -

    Unfortunately there are many ways in which we can place a hyperplane -to divide the data. Below is an example of two candidate hyperplanes -for our data sample. +

    In two dimensions, with the variables \( x_1 \) and \( x_2 \), the hyperplane is defined as

    +$$ +b+w_1x_1+w_2x_2=0, +$$ + +

    where \( b \) is the intercept and \( w_1 \) and \( w_2 \) define the elements of a vector orthogonal to the line +\( b+w_1x_1+w_2x_2=0 \). +In two dimensions we define the vectors \( \boldsymbol{x} =[x1,x2] \) and \( \boldsymbol{w}=[w1,w2] \). +We can then rewrite the above equation as

    +$$ +\boldsymbol{x}^T\boldsymbol{w}+b=0. +$$ + +

      @@ -212,7 +226,7 @@ for our data sample.
    • 15
    • 16
    • ...
    • -
    • 29
    • +
    • 31
    • »
    diff --git a/doc/pub/week46/html/._week46-bs007.html b/doc/pub/week46/html/._week46-bs007.html index 7eb15446e..0aad22506 100644 --- a/doc/pub/week46/html/._week46-bs007.html +++ b/doc/pub/week46/html/._week46-bs007.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,22 +177,45 @@ MathJax.Hub.Config({

     

     

     

    -

    Getting into the details

    +

    A \( p \)-dimensional space of features

    -

    Let us define the function

    +

    We limit ourselves to two classes of outputs \( y_i \) and assign these classes the values \( y_i = \pm 1 \). +In a \( p \)-dimensional space of say \( p \) features we have a hyperplane defines as +

    $$ -f(x) = \boldsymbol{w}^T\boldsymbol{x}+b = 0, +b+wx_1+w_2x_2+\dots +w_px_p=0. $$ -

    as the function that determines the line \( L \) that separates two classes (our two features), see the figure here.

    - -

    Any point defined by \( \boldsymbol{x}_i \) and \( \boldsymbol{x}_2 \) on the line \( L \) will satisfy \( \boldsymbol{w}^T(\boldsymbol{x}_1-\boldsymbol{x}_2)=0 \).

    - -

    The signed distance \( \delta \) from any point defined by a vector \( \boldsymbol{x} \) and a point \( \boldsymbol{x}_0 \) on the line \( L \) is then

    +

    If we define a +matrix \( \boldsymbol{X}=\left[\boldsymbol{x}_1,\boldsymbol{x}_2,\dots, \boldsymbol{x}_p\right] \) +of dimension \( n\times p \), where \( n \) represents the observations for each feature and each vector \( x_i \) is a column vector of the matrix \( \boldsymbol{X} \), +

    $$ -\delta = \frac{1}{\vert\vert \boldsymbol{w}\vert\vert}(\boldsymbol{w}^T\boldsymbol{x}+b). +\boldsymbol{x}_i = \begin{bmatrix} x_{i1} \\ x_{i2} \\ \dots \\ \dots \\ x_{ip} \end{bmatrix}. $$ +

    If the above condition is not met for a given vector \( \boldsymbol{x}_i \) we have

    +$$ +b+w_1x_{i1}+w_2x_{i2}+\dots +w_px_{ip} >0, +$$ + +

    if our output \( y_i=1 \). +In this case we say that \( \boldsymbol{x}_i \) lies on one of the sides of the hyperplane and if +

    +$$ +b+w_1x_{i1}+w_2x_{i2}+\dots +w_px_{ip} < 0, +$$ + +

    for the class of observations \( y_i=-1 \), +then \( \boldsymbol{x}_i \) lies on the other side. +

    + +

    Equivalently, for the two classes of observations we have

    +$$ +y_i\left(b+w_1x_{i1}+w_2x_{i2}+\dots +w_px_{ip}\right) > 0. +$$ + +

    When we try to separate hyperplanes, if it exists, we can use it to construct a natural classifier: a test observation is assigned a given class depending on which side of the hyperplane it is located.

    @@ -206,7 +239,7 @@ $$

  • 16
  • 17
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs008.html b/doc/pub/week46/html/._week46-bs008.html index 686322f59..145b0c326 100644 --- a/doc/pub/week46/html/._week46-bs008.html +++ b/doc/pub/week46/html/._week46-bs008.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -166,28 +176,30 @@ MathJax.Hub.Config({

     

     

     

    - -

    First attempt at a minimization approach

    + +

    The two-dimensional case

    -

    How do we find the parameter \( b \) and the vector \( \boldsymbol{w} \)? What we could -do is to define a cost function which now contains the set of all -misclassified points \( M \) and attempt to minimize this function +

    Let us try to develop our intuition about SVMs by limiting ourselves to a two-dimensional +plane. To separate the two classes of data points, there are many +possible lines (hyperplanes if you prefer a more strict naming) +that could be chosen. Our objective is to find a +plane that has the maximum margin, i.e the maximum distance between +data points of both classes. Maximizing the margin distance provides +some reinforcement so that future data points can be classified with +more confidence.

    -$$ -C(\boldsymbol{w},b) = -\sum_{i\in M} y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b). -$$ - -

    We could now for example define all values \( y_i =1 \) as misclassified in case we have \( \boldsymbol{w}^T\boldsymbol{x}_i+b < 0 \) and the opposite if we have \( y_i=-1 \). Taking the derivatives gives us

    -$$ -\frac{\partial C}{\partial b} = -\sum_{i\in M} y_i, -$$ - -

    and

    -$$ -\frac{\partial C}{\partial \boldsymbol{w}} = -\sum_{i\in M} y_ix_i. -$$ +

    What a linear classifier attempts to accomplish is to split the +feature space into two half spaces by placing a hyperplane between the +data points. This hyperplane will be our decision boundary. All +points on one side of the plane will belong to class one and all points +on the other side of the plane will belong to the second class two. +

    +

    Unfortunately there are many ways in which we can place a hyperplane +to divide the data. Below is an example of two candidate hyperplanes +for our data sample. +

    @@ -212,7 +224,7 @@ $$

  • 17
  • 18
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs009.html b/doc/pub/week46/html/._week46-bs009.html index 652bbfd87..ad1528f4a 100644 --- a/doc/pub/week46/html/._week46-bs009.html +++ b/doc/pub/week46/html/._week46-bs009.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,19 +177,22 @@ MathJax.Hub.Config({

     

     

     

    -

    Solving the equations

    +

    Getting into the details

    -

    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

    +

    Let us define the function

    $$ -b \leftarrow b +\eta \frac{\partial C}{\partial b}, +f(x) = \boldsymbol{w}^T\boldsymbol{x}+b = 0, $$ -

    and

    +

    as the function that determines the line \( L \) that separates two classes (our two features), see the figure here.

    + +

    Any point defined by \( \boldsymbol{x}_i \) and \( \boldsymbol{x}_2 \) on the line \( L \) will satisfy \( \boldsymbol{w}^T(\boldsymbol{x}_1-\boldsymbol{x}_2)=0 \).

    + +

    The signed distance \( \delta \) from any point defined by a vector \( \boldsymbol{x} \) and a point \( \boldsymbol{x}_0 \) on the line \( L \) is then

    $$ -\boldsymbol{w} \leftarrow \boldsymbol{w} +\eta \frac{\partial C}{\partial \boldsymbol{w}}, +\delta = \frac{1}{\vert\vert \boldsymbol{w}\vert\vert}(\boldsymbol{w}^T\boldsymbol{x}+b). $$ -

    where \( \eta \) is our by now well-known learning rate.

    @@ -205,7 +218,7 @@ $$

  • 18
  • 19
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs010.html b/doc/pub/week46/html/._week46-bs010.html index a08f4f449..117e3ba02 100644 --- a/doc/pub/week46/html/._week46-bs010.html +++ b/doc/pub/week46/html/._week46-bs010.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,34 +177,26 @@ MathJax.Hub.Config({

     

     

     

    -

    Code Example

    +

    First attempt at a minimization approach

    -

    The equations we discussed above can be coded rather easily (the -framework is similar to what we developed for logistic -regression). We are going to set up a simple case with two classes only and we want to find a line which separates them the best possible way. +

    How do we find the parameter \( b \) and the vector \( \boldsymbol{w} \)? What we could +do is to define a cost function which now contains the set of all +misclassified points \( M \) and attempt to minimize this function

    - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +$$ +C(\boldsymbol{w},b) = -\sum_{i\in M} y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b). +$$ + +

    We could now for example define all values \( y_i =1 \) as misclassified in case we have \( \boldsymbol{w}^T\boldsymbol{x}_i+b < 0 \) and the opposite if we have \( y_i=-1 \). Taking the derivatives gives us

    +$$ +\frac{\partial C}{\partial b} = -\sum_{i\in M} y_i, +$$ + +

    and

    +$$ +\frac{\partial C}{\partial \boldsymbol{w}} = -\sum_{i\in M} y_ix_i. +$$

    @@ -222,7 +224,7 @@ regression). We are going to set up a simple case with two classes only and we w

  • 19
  • 20
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs011.html b/doc/pub/week46/html/._week46-bs011.html index 29aacb6ac..e246f7838 100644 --- a/doc/pub/week46/html/._week46-bs011.html +++ b/doc/pub/week46/html/._week46-bs011.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,18 +177,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Problems with the Simpler Approach

    +

    Solving the equations

    -

    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. -

    +

    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}, +$$ -

    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. -

    +

    and

    +$$ +\boldsymbol{w} \leftarrow \boldsymbol{w} +\eta \frac{\partial C}{\partial \boldsymbol{w}}, +$$ + +

    where \( \eta \) is our by now well-known learning rate.

    @@ -205,7 +216,7 @@ at all.

  • 20
  • 21
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs012.html b/doc/pub/week46/html/._week46-bs012.html index 3337c7693..e8f241dc3 100644 --- a/doc/pub/week46/html/._week46-bs012.html +++ b/doc/pub/week46/html/._week46-bs012.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,44 +177,35 @@ 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 similar to what we developed for logistic +regression). We are going to set up a simple case with two classes only and we want to find a line which separates them the best possible way.

    -

    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. -

    @@ -231,7 +232,7 @@ about Lagrangian multipliers.

  • 21
  • 22
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs013.html b/doc/pub/week46/html/._week46-bs013.html index 0973bab77..25690c179 100644 --- a/doc/pub/week46/html/._week46-bs013.html +++ b/doc/pub/week46/html/._week46-bs013.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,53 +177,17 @@ 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.

    @@ -241,7 +215,7 @@ Then \( dz \) is no longer arbitrary.

  • 22
  • 23
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs014.html b/doc/pub/week46/html/._week46-bs014.html index 2386f232d..8e4dddfc7 100644 --- a/doc/pub/week46/html/._week46-bs014.html +++ b/doc/pub/week46/html/._week46-bs014.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,45 +177,44 @@ MathJax.Hub.Config({

     

     

     

    -

    Adding the Multiplier

    +

    A better approach

    + +

    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 +

    -

    However, we can add to

    $$ -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. $$ -

    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 +

    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

    $$ -\frac{\partial f}{\partial x_i}+\sum_k\lambda_k\frac{\partial \phi_k}{\partial x_i} =0. +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. +

    @@ -232,7 +241,7 @@ $$

  • 23
  • 24
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs015.html b/doc/pub/week46/html/._week46-bs015.html index 2d8716d5c..4e572864a 100644 --- a/doc/pub/week46/html/._week46-bs015.html +++ b/doc/pub/week46/html/._week46-bs015.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,41 +177,54 @@ 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], -$$ +

    A quick Reminder on Lagrangian Multipliers

    -

    where \( \lambda_i \) is a so-called Lagrange multiplier subject to the condition \( \lambda_i \geq 0 \).

    - -

    Taking the derivatives with respect to \( b \) and \( \boldsymbol{w} \) we obtain

    -$$ -\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0, -$$ - -

    and

    -$$ -\frac{\partial {\cal L}}{\partial \boldsymbol{w}} = 0 = \boldsymbol{w}-\sum_{i} \lambda_iy_i\boldsymbol{x}_i. -$$ - -

    Inserting these constraints into the equation for \( {\cal L} \) 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{x}_j, -$$ - -

    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 +

    Consider a function of three independent variables \( f(x,y,z) \) . For the function \( f \) to be an +extreme we have

    $$ -\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -1\right] \hspace{0.1cm}\forall i. +df=0. $$ -
      -
    1. 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.
    2. -
    3. 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 \).
    4. -
    -

    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 \).

    +

    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. +

    + +

    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. +

    @@ -228,7 +251,7 @@ $$

  • 24
  • 25
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs016.html b/doc/pub/week46/html/._week46-bs016.html index 8a10a3464..fdaeefc23 100644 --- a/doc/pub/week46/html/._week46-bs016.html +++ b/doc/pub/week46/html/._week46-bs016.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,26 +177,45 @@ MathJax.Hub.Config({

     

     

     

    -

    The problem to solve

    +

    Adding the Multiplier

    -

    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. +$$ +

    @@ -213,7 +242,7 @@ $$

  • 25
  • 26
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs017.html b/doc/pub/week46/html/._week46-bs017.html index 00e874794..6911265ce 100644 --- a/doc/pub/week46/html/._week46-bs017.html +++ b/doc/pub/week46/html/._week46-bs017.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,36 +177,41 @@ 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], +$$ -

    Solving the above problem, yields the values of \( \lambda_i \). -To find the coefficients of your hyperplane we need simply to compute +

    where \( \lambda_i \) is a so-called Lagrange multiplier subject to the condition \( \lambda_i \geq 0 \).

    + +

    Taking the derivatives with respect to \( b \) and \( \boldsymbol{w} \) we obtain

    +$$ +\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0, +$$ + +

    and

    +$$ +\frac{\partial {\cal L}}{\partial \boldsymbol{w}} = 0 = \boldsymbol{w}-\sum_{i} \lambda_iy_i\boldsymbol{x}_i. +$$ + +

    Inserting these constraints into the equation for \( {\cal L} \) 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{x}_j, +$$ + +

    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

    $$ -\boldsymbol{w}=\sum_{i} \lambda_iy_i\boldsymbol{x}_i. +\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -1\right] \hspace{0.1cm}\forall i. $$ -

    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, -$$ - -

    resulting in

    -$$ -b = \frac{1}{y_i}-\boldsymbol{w}^T\boldsymbol{x}_i, -$$ - -

    or if we write it out in terms of the support vectors only, with \( N_s \) being their number, we have

    -$$ -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). -$$ - -

    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.

    +
      +
    1. 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.
    2. +
    3. 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 \).
    4. +
    +

    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 \).

    @@ -223,7 +238,7 @@ $$

  • 26
  • 27
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs018.html b/doc/pub/week46/html/._week46-bs018.html index c13a0d6c5..7e3baa037 100644 --- a/doc/pub/week46/html/._week46-bs018.html +++ b/doc/pub/week46/html/._week46-bs018.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,36 +177,25 @@ 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] \).

    @@ -224,7 +223,7 @@ misclassifications.

  • 27
  • 28
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs019.html b/doc/pub/week46/html/._week46-bs019.html index c8db5b730..90d5328d9 100644 --- a/doc/pub/week46/html/._week46-bs019.html +++ b/doc/pub/week46/html/._week46-bs019.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,56 +177,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

    -$$ -{\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 \).

    - -

    Taking the derivatives with respect to \( b \) and \( \boldsymbol{w} \) we obtain

    -$$ -\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0, -$$ - -

    and

    -$$ -\frac{\partial {\cal L}}{\partial \boldsymbol{w}} = 0 = \boldsymbol{w}-\sum_{i} \lambda_iy_i\boldsymbol{x}_i, -$$ - -

    and

    -$$ -\lambda_i = C-\gamma_i \hspace{0.1cm}\forall i. -$$ - -

    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 +

    Solving the above problem, yields the values of \( \lambda_i \). +To find the coefficients of your hyperplane we need simply to compute

    $$ -\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -(1-\xi_)\right]=0 \hspace{0.1cm}\forall i, +\boldsymbol{w}=\sum_{i} \lambda_iy_i\boldsymbol{x}_i. $$ +

    With our vector \( \boldsymbol{w} \) we can in turn find the value of the intercept \( b \) (here in two dimensions) via

    $$ -\gamma_i\xi_i = 0, +y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1, $$ -

    and

    +

    resulting in

    $$ -y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -(1-\xi_) \geq 0 \hspace{0.1cm}\forall i. +b = \frac{1}{y_i}-\boldsymbol{w}^T\boldsymbol{x}_i, $$ +

    or if we write it out in terms of the support vectors only, with \( N_s \) being their number, we have

    +$$ +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). +$$ + +

    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.

    @@ -242,6 +232,8 @@ $$

  • 27
  • 28
  • 29
  • +
  • ...
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs020.html b/doc/pub/week46/html/._week46-bs020.html index 0299de352..159482b91 100644 --- a/doc/pub/week46/html/._week46-bs020.html +++ b/doc/pub/week46/html/._week46-bs020.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,95 +177,38 @@ MathJax.Hub.Config({

     

     

     

    -

    Kernels and non-linearity

    +

    A soft classifier

    -

    The cases we have studied till now, 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 as 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.

    + +

    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.

    -

    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. +

    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.

    -

    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. +

    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()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    diff --git a/doc/pub/week46/html/._week46-bs021.html b/doc/pub/week46/html/._week46-bs021.html index 823878b84..e9adcc6a1 100644 --- a/doc/pub/week46/html/._week46-bs021.html +++ b/doc/pub/week46/html/._week46-bs021.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,46 +177,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, $$ -

    With our new basis, the equations we solved earlier are basically the same, that is we have now (without the slack option for simplicity)

    +

    subject to

    $$ -{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\boldsymbol{z}_i^T\boldsymbol{z}_j, +y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1-\xi_i \hspace{0.1cm}\forall i, $$ -

    subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \), and for the support vectors

    +

    with the requirement \( \xi_i\geq 0 \).

    + +

    Taking the derivatives with respect to \( b \) and \( \boldsymbol{w} \) we obtain

    $$ -y_i(\boldsymbol{w}^T\boldsymbol{z}_i+b)= 1 \hspace{0.1cm}\forall i, +\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0, $$ -

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

    and

    +$$ +\frac{\partial {\cal L}}{\partial \boldsymbol{w}} = 0 = \boldsymbol{w}-\sum_{i} \lambda_iy_i\boldsymbol{x}_i, +$$ + +

    and

    +$$ +\lambda_i = C-\gamma_i \hspace{0.1cm}\forall i. +$$ + +

    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

    $$ -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\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -(1-\xi_)\right]=0 \hspace{0.1cm}\forall i, $$ -

    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. +\gamma_i\xi_i = 0, $$ -

    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 \). -

    +

    and

    +$$ +y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -(1-\xi_) \geq 0 \hspace{0.1cm}\forall i. +$$ -

    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. -

    @@ -230,6 +250,8 @@ the trouble of performing the transformation

  • 27
  • 28
  • 29
  • +
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs022.html b/doc/pub/week46/html/._week46-bs022.html index 217c7f12f..980e01112 100644 --- a/doc/pub/week46/html/._week46-bs022.html +++ b/doc/pub/week46/html/._week46-bs022.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,40 +177,95 @@ 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, -$$ +

    Kernels and non-linearity

    -

    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 \). +

    The cases we have studied till now, 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 as higher-order polynomials, +wavelets, splines etc.

    -

    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*} -$$ - -

    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()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

      @@ -222,6 +287,8 @@ Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up.
    • 27
    • 28
    • 29
    • +
    • 30
    • +
    • 31
    • »
    diff --git a/doc/pub/week46/html/._week46-bs023.html b/doc/pub/week46/html/._week46-bs023.html index 69f46ba79..3e9e1b396 100644 --- a/doc/pub/week46/html/._week46-bs023.html +++ b/doc/pub/week46/html/._week46-bs023.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,36 +177,45 @@ MathJax.Hub.Config({

     

     

     

    -

    Different kernels and Mercer's theorem

    - -

    There are several popular kernels being used. These are

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

    and many other ones.

    - -

    An important theorem for us is Mercer's -theorem. 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 -

    +

    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)

    $$ -K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). +z = \phi(x_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right). $$ -

    So you can use \( K \) as a kernel since you know \( \phi \) exists, even if -you don’t know what \( \phi \) is. +

    With our new basis, the equations we solved earlier are basically the same, that is we have now (without the slack option for simplicity)

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

    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 kernel \( 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 \).

    -

    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. +

    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.

    @@ -219,6 +238,8 @@ in practice.

  • 27
  • 28
  • 29
  • +
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs024.html b/doc/pub/week46/html/._week46-bs024.html index f8fdb893d..6dff8c2ce 100644 --- a/doc/pub/week46/html/._week46-bs024.html +++ b/doc/pub/week46/html/._week46-bs024.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,217 +177,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, +$$ - -
    -
    -
    -
    -
    -
    from __future__ import division, print_function, unicode_literals
    +

    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}, +$$ -import numpy as np -np.random.seed(42) +

    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 \). +

    -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() -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    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*} +$$ +

    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} \). +

    @@ -398,6 +230,8 @@ plt.show()

  • 27
  • 28
  • 29
  • +
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs025.html b/doc/pub/week46/html/._week46-bs025.html index f37c64b2f..85c4eefed 100644 --- a/doc/pub/week46/html/._week46-bs025.html +++ b/doc/pub/week46/html/._week46-bs025.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,26 +177,37 @@ 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

    -$$ -\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*} -$$ +

    There are several popular kernels being used. These are

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

    and many other ones.

    -

    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. +

    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

    -

    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. +$$ +K(\boldsymbol{x}_i,\boldsymbol{x}_j)=\phi(\boldsymbol{x}_i)^T\phi(\boldsymbol{x}_j). +$$ + +

    So you can use \( K \) as a kernel since you know \( \phi \) exists, even if +you don’t know what \( \phi \) is.

    -

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

    +

    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. +

    @@ -206,6 +227,8 @@ In our discussion on gradient descent methods we discussed at length the definit

  • 27
  • 28
  • 29
  • +
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs026.html b/doc/pub/week46/html/._week46-bs026.html index 8dce25949..69efb92e4 100644 --- a/doc/pub/week46/html/._week46-bs026.html +++ b/doc/pub/week46/html/._week46-bs026.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,19 +177,7 @@ 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

    @@ -187,8 +185,194 @@ converge. So, welcome to the promised land of quadratic programming.
    -
    import numpy
    -import cvxopt
    +  
    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()
     
    @@ -204,7 +388,6 @@ converge. So, welcome to the promised land of quadratic programming.
    -

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

    @@ -223,6 +406,8 @@ converge. So, welcome to the promised land of quadratic programming.

  • 27
  • 28
  • 29
  • +
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs027.html b/doc/pub/week46/html/._week46-bs027.html index 177dfc6a4..95f102630 100644 --- a/doc/pub/week46/html/._week46-bs027.html +++ b/doc/pub/week46/html/._week46-bs027.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,88 +177,26 @@ 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}. -$$ - -

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

    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.

    - -
    -
    -
    -
    -
    -
    # 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’]
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    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.

    @@ -266,6 +214,8 @@ sol[’primal objective’]

  • 27
  • 28
  • 29
  • +
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs028.html b/doc/pub/week46/html/._week46-bs028.html index 6913d0660..c411f9f87 100644 --- a/doc/pub/week46/html/._week46-bs028.html +++ b/doc/pub/week46/html/._week46-bs028.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -167,24 +177,44 @@ 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.

    @@ -201,6 +231,9 @@ With the slack constants this leads to the additional constraint \( 0\leq \lamb

  • 27
  • 28
  • 29
  • +
  • 30
  • +
  • 31
  • +
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs029.html b/doc/pub/week46/html/._week46-bs029.html index d96da2baf..0e5dff381 100644 --- a/doc/pub/week46/html/._week46-bs029.html +++ b/doc/pub/week46/html/._week46-bs029.html @@ -37,11 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Friday
  • -
  • Workshop plan Friday November 19 and the rest of the lecture
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • Support Vector Machines, overarching aims
  • Hyperplanes and all that
  • What is a hyperplane?
  • diff --git a/doc/pub/week46/html/week46-bs.html b/doc/pub/week46/html/week46-bs.html index 64fb461b5..07c7b1a4d 100644 --- a/doc/pub/week46/html/week46-bs.html +++ b/doc/pub/week46/html/week46-bs.html @@ -37,6 +37,14 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 46
  • -
  • Support Vector Machines, overarching aims
  • -
  • Hyperplanes and all that
  • -
  • What is a hyperplane?
  • -
  • A \( p \)-dimensional space of features
  • -
  • The two-dimensional case
  • -
  • Getting into the details
  • -
  • First attempt at a minimization approach
  • -
  • Solving the equations
  • -
  • Code Example
  • -
  • Problems with the Simpler Approach
  • -
  • A better approach
  • -
  • A quick Reminder on Lagrangian Multipliers
  • -
  • Adding the Multiplier
  • -
  • 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
  • +
  • Eventual mini-workshop on project 3, Friday November 18
  • +
  • Workshop topics 2021 (partly online)
  • +
  • Support Vector Machines, overarching aims
  • +
  • Hyperplanes and all that
  • +
  • What is a hyperplane?
  • +
  • A \( p \)-dimensional space of features
  • +
  • The two-dimensional case
  • +
  • Getting into the details
  • +
  • First attempt at a minimization approach
  • +
  • Solving the equations
  • +
  • Code Example
  • +
  • Problems with the Simpler Approach
  • +
  • A better approach
  • +
  • A quick Reminder on Lagrangian Multipliers
  • +
  • Adding the Multiplier
  • +
  • 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
  • @@ -185,7 +195,7 @@ MathJax.Hub.Config({
    -

    Nov 12, 2022

    +

    Nov 13, 2022


    @@ -210,7 +220,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 29
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/week46-reveal.html b/doc/pub/week46/html/week46-reveal.html index 8085e4565..898ce103c 100644 --- a/doc/pub/week46/html/week46-reveal.html +++ b/doc/pub/week46/html/week46-reveal.html @@ -184,7 +184,7 @@ MathJax.Hub.Config({
    -

    Nov 12, 2022

    +

    Nov 13, 2022


    @@ -199,7 +199,7 @@ MathJax.Hub.Config({

    • Thursday: Summary of Gradient Boosting. Start support Vector Machines
    • -

    • Friday: Eventual Workshop on project 3. Discussion of project 3.
    • +

    • Friday: Eventual Workshop on project 3. Discussion of project 3 and support vector machines

    @@ -225,6 +225,38 @@ MathJax.Hub.Config({
    +
    +

    Eventual mini-workshop on project 3, Friday November 18

    + +

    We have tried every year to organize a kind of mini-workshop on project 3. In 2020 the contributions were (and some of these ended up in thesis work and/or publications, online only due to Covid-19!)

    + +
      +

    • Maria Emine Nylund: Lego Bricks Classifier
    • +

    • Fabio Rodrigues Pereira: Financial Machine Learning
    • +

    • Markus Borud Pettersen: Machine Learning and Brain Grid Cells
    • +

    • Jing Sun and Endrias Getachew Asgedom: Machine learning-based approaches to denoising microseismic data
    • +

    • Felicia Jacobsen: Analysis of Breast Cancer Data
    • +

    • Simon Elias Schrader: Predicting atomization energies of molecules
    • +

    • Varvara Bazilova and Sergio Andres Diaz Mesa: Glacier Mapping and Machine Learning
    • +

    • Gert Werner Kluge, Hanna Alida Fossen Hardersen and Sushma Sharma Adhikari: Gamma ray signals stemming from dark matter in the galactic center
    • +
    +
    + +
    +

    Workshop topics 2021 (partly online)

    + +
      +

    1. 1215-1225pm: Are Frode Helvig Kvanum, Gard Høivang, and David Andreas Bordvik, Next-day forecasts on spot prices for electricity
    2. +

    3. 1225-1235pm: Lidia Luque, Voxel-wise multi-label brain tumor classification
    4. +

    5. 1235-1245pm: Marcus Berget et al, Locating suspicious brain activity using neural networks
    6. +

    7. 1245-1255pm: William Ho and Tom-Ruben Traavik Kvalvaag, Comparing semi-supervised learning and supervised learning for image classification
    8. +
    +

    +

    We would very much like to organize something similar this year as well. Feel free to come with sugesstions by Thursday November 17. We will then try to set up the various contributions for Friday November 18. +The presentations last normally 5-15 mins and span from loose ideas to more well-defined topics. Nothing pretentious, we wish to keep this as low-key as possible. +

    +
    +

    Support Vector Machines, overarching aims

    diff --git a/doc/pub/week46/html/week46-solarized.html b/doc/pub/week46/html/week46-solarized.html index 3fadaf2cf..300b613ff 100644 --- a/doc/pub/week46/html/week46-solarized.html +++ b/doc/pub/week46/html/week46-solarized.html @@ -64,6 +64,14 @@ div.toc p,a {
    @@ -167,7 +175,7 @@ MathJax.Hub.Config({
    • Thursday: Summary of Gradient Boosting. Start support Vector Machines
    • -
    • Friday: Eventual Workshop on project 3. Discussion of project 3.
    • +
    • Friday: Eventual Workshop on project 3. Discussion of project 3 and support vector machines
    Reading @@ -192,6 +200,34 @@ MathJax.Hub.Config({
    +









    +

    Eventual mini-workshop on project 3, Friday November 18

    + +

    We have tried every year to organize a kind of mini-workshop on project 3. In 2020 the contributions were (and some of these ended up in thesis work and/or publications, online only due to Covid-19!)

    + +
      +
    • Maria Emine Nylund: Lego Bricks Classifier
    • +
    • Fabio Rodrigues Pereira: Financial Machine Learning
    • +
    • Markus Borud Pettersen: Machine Learning and Brain Grid Cells
    • +
    • Jing Sun and Endrias Getachew Asgedom: Machine learning-based approaches to denoising microseismic data
    • +
    • Felicia Jacobsen: Analysis of Breast Cancer Data
    • +
    • Simon Elias Schrader: Predicting atomization energies of molecules
    • +
    • Varvara Bazilova and Sergio Andres Diaz Mesa: Glacier Mapping and Machine Learning
    • +
    • Gert Werner Kluge, Hanna Alida Fossen Hardersen and Sushma Sharma Adhikari: Gamma ray signals stemming from dark matter in the galactic center
    • +
    +









    +

    Workshop topics 2021 (partly online)

    + +
      +
    1. 1215-1225pm: Are Frode Helvig Kvanum, Gard Høivang, and David Andreas Bordvik, Next-day forecasts on spot prices for electricity
    2. +
    3. 1225-1235pm: Lidia Luque, Voxel-wise multi-label brain tumor classification
    4. +
    5. 1235-1245pm: Marcus Berget et al, Locating suspicious brain activity using neural networks
    6. +
    7. 1245-1255pm: William Ho and Tom-Ruben Traavik Kvalvaag, Comparing semi-supervised learning and supervised learning for image classification
    8. +
    +

    We would very much like to organize something similar this year as well. Feel free to come with sugesstions by Thursday November 17. We will then try to set up the various contributions for Friday November 18. +The presentations last normally 5-15 mins and span from loose ideas to more well-defined topics. Nothing pretentious, we wish to keep this as low-key as possible. +

    +









    Support Vector Machines, overarching aims

    diff --git a/doc/pub/week46/html/week46.html b/doc/pub/week46/html/week46.html index 260dc6c14..1c44a7b63 100644 --- a/doc/pub/week46/html/week46.html +++ b/doc/pub/week46/html/week46.html @@ -141,6 +141,14 @@ div.toc p,a {
    @@ -244,7 +252,7 @@ MathJax.Hub.Config({
    • Thursday: Summary of Gradient Boosting. Start support Vector Machines
    • -
    • Friday: Eventual Workshop on project 3. Discussion of project 3.
    • +
    • Friday: Eventual Workshop on project 3. Discussion of project 3 and support vector machines
    Reading @@ -269,6 +277,34 @@ MathJax.Hub.Config({
    +









    +

    Eventual mini-workshop on project 3, Friday November 18

    + +

    We have tried every year to organize a kind of mini-workshop on project 3. In 2020 the contributions were (and some of these ended up in thesis work and/or publications, online only due to Covid-19!)

    + +
      +
    • Maria Emine Nylund: Lego Bricks Classifier
    • +
    • Fabio Rodrigues Pereira: Financial Machine Learning
    • +
    • Markus Borud Pettersen: Machine Learning and Brain Grid Cells
    • +
    • Jing Sun and Endrias Getachew Asgedom: Machine learning-based approaches to denoising microseismic data
    • +
    • Felicia Jacobsen: Analysis of Breast Cancer Data
    • +
    • Simon Elias Schrader: Predicting atomization energies of molecules
    • +
    • Varvara Bazilova and Sergio Andres Diaz Mesa: Glacier Mapping and Machine Learning
    • +
    • Gert Werner Kluge, Hanna Alida Fossen Hardersen and Sushma Sharma Adhikari: Gamma ray signals stemming from dark matter in the galactic center
    • +
    +









    +

    Workshop topics 2021 (partly online)

    + +
      +
    1. 1215-1225pm: Are Frode Helvig Kvanum, Gard Høivang, and David Andreas Bordvik, Next-day forecasts on spot prices for electricity
    2. +
    3. 1225-1235pm: Lidia Luque, Voxel-wise multi-label brain tumor classification
    4. +
    5. 1235-1245pm: Marcus Berget et al, Locating suspicious brain activity using neural networks
    6. +
    7. 1245-1255pm: William Ho and Tom-Ruben Traavik Kvalvaag, Comparing semi-supervised learning and supervised learning for image classification
    8. +
    +

    We would very much like to organize something similar this year as well. Feel free to come with sugesstions by Thursday November 17. We will then try to set up the various contributions for Friday November 18. +The presentations last normally 5-15 mins and span from loose ideas to more well-defined topics. Nothing pretentious, we wish to keep this as low-key as possible. +

    +









    Support Vector Machines, overarching aims

    diff --git a/doc/pub/week46/ipynb/ipynb-week46-src.tar.gz b/doc/pub/week46/ipynb/ipynb-week46-src.tar.gz index bbc076ceb..e234ee44d 100644 Binary files a/doc/pub/week46/ipynb/ipynb-week46-src.tar.gz and b/doc/pub/week46/ipynb/ipynb-week46-src.tar.gz differ diff --git a/doc/pub/week46/ipynb/week46.ipynb b/doc/pub/week46/ipynb/week46.ipynb index 19524721a..2920828d8 100644 --- a/doc/pub/week46/ipynb/week46.ipynb +++ b/doc/pub/week46/ipynb/week46.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "fdaa20ed", + "id": "dadf1256", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "5e770c15", + "id": "51bdba1c", "metadata": { "editable": true }, @@ -22,14 +22,14 @@ "# Week 46: Support Vector Machines and Project 3\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 12, 2022**\n", + "Date: **Nov 13, 2022**\n", "\n", "Copyright 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license" ] }, { "cell_type": "markdown", - "id": "3fc1fc7b", + "id": "86b32972", "metadata": { "editable": true }, @@ -38,7 +38,7 @@ "\n", "* **Thursday**: Summary of Gradient Boosting. Start support Vector Machines\n", "\n", - "* **Friday**: Eventual Workshop on project 3. Discussion of project 3.\n", + "* **Friday**: Eventual Workshop on project 3. Discussion of project 3 and support vector machines\n", "\n", "**Reading.**\n", "\n", @@ -60,7 +60,56 @@ }, { "cell_type": "markdown", - "id": "9a070f4b", + "id": "879c4ad2", + "metadata": { + "editable": true + }, + "source": [ + "## Eventual mini-workshop on project 3, Friday November 18\n", + "\n", + "We have tried every year to organize a kind of mini-workshop on project 3. In 2020 the contributions were (and some of these ended up in thesis work and/or publications, online only due to Covid-19!)\n", + "\n", + "* Maria Emine Nylund: **Lego Bricks Classifier**\n", + "\n", + "* Fabio Rodrigues Pereira: **Financial Machine Learning**\n", + "\n", + "* Markus Borud Pettersen: **Machine Learning and Brain Grid Cells**\n", + "\n", + "* Jing Sun and Endrias Getachew Asgedom: **Machine learning-based approaches to denoising microseismic data**\n", + "\n", + "* Felicia Jacobsen: **Analysis of Breast Cancer Data**\n", + "\n", + "* Simon Elias Schrader: **Predicting atomization energies of molecules**\n", + "\n", + "* Varvara Bazilova and Sergio Andres Diaz Mesa: **Glacier Mapping and Machine Learning**\n", + "\n", + "* Gert Werner Kluge, Hanna Alida Fossen Hardersen and Sushma Sharma Adhikari: **Gamma ray signals stemming from dark matter in the galactic center**" + ] + }, + { + "cell_type": "markdown", + "id": "29732746", + "metadata": { + "editable": true + }, + "source": [ + "## Workshop topics 2021 (partly online)\n", + "\n", + "1. **1215-1225pm**: Are Frode Helvig Kvanum, Gard Høivang, and David Andreas Bordvik, *Next-day forecasts on spot prices for electricity*\n", + "\n", + "2. **1225-1235pm**: Lidia Luque, *Voxel-wise multi-label brain tumor classification*\n", + "\n", + "3. **1235-1245pm**: Marcus Berget et al, *Locating suspicious brain activity using neural networks*\n", + "\n", + "4. **1245-1255pm**: William Ho and Tom-Ruben Traavik Kvalvaag, *Comparing semi-supervised learning and supervised learning for image classification*\n", + "\n", + "We would very much like to organize something similar this year as well. Feel free to come with sugesstions by Thursday November 17. We will then try to set up the various contributions for Friday November 18.\n", + "The presentations last normally 5-15 mins and span from loose ideas to more well-defined topics. Nothing pretentious, we wish to keep this as low-key as possible." + ] + }, + { + "cell_type": "markdown", + "id": "47d56b53", "metadata": { "editable": true }, @@ -94,7 +143,7 @@ }, { "cell_type": "markdown", - "id": "00af38aa", + "id": "d63516ce", "metadata": { "editable": true }, @@ -116,7 +165,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "b3081144", + "id": "77d40ba6", "metadata": { "collapsed": false, "editable": true @@ -195,7 +244,7 @@ }, { "cell_type": "markdown", - "id": "eee872f9", + "id": "9bc64632", "metadata": { "editable": true }, @@ -215,7 +264,7 @@ }, { "cell_type": "markdown", - "id": "2cc70bd4", + "id": "0d57736f", "metadata": { "editable": true }, @@ -227,7 +276,7 @@ }, { "cell_type": "markdown", - "id": "8acca7a0", + "id": "1ecea9b2", "metadata": { "editable": true }, @@ -240,7 +289,7 @@ }, { "cell_type": "markdown", - "id": "6407e226", + "id": "b9d221fd", "metadata": { "editable": true }, @@ -252,7 +301,7 @@ }, { "cell_type": "markdown", - "id": "ed47c9e4", + "id": "7ab7e3e7", "metadata": { "editable": true }, @@ -265,7 +314,7 @@ }, { "cell_type": "markdown", - "id": "1c5b3515", + "id": "3b49c0b4", "metadata": { "editable": true }, @@ -277,7 +326,7 @@ }, { "cell_type": "markdown", - "id": "32d671fe", + "id": "57160727", "metadata": { "editable": true }, @@ -289,7 +338,7 @@ }, { "cell_type": "markdown", - "id": "4a5d2eec", + "id": "816d8851", "metadata": { "editable": true }, @@ -301,7 +350,7 @@ }, { "cell_type": "markdown", - "id": "f95d52d7", + "id": "62d20fdd", "metadata": { "editable": true }, @@ -311,7 +360,7 @@ }, { "cell_type": "markdown", - "id": "0a981fb4", + "id": "8668dede", "metadata": { "editable": true }, @@ -323,7 +372,7 @@ }, { "cell_type": "markdown", - "id": "7a3bc218", + "id": "635ad8f7", "metadata": { "editable": true }, @@ -334,7 +383,7 @@ }, { "cell_type": "markdown", - "id": "ef75d803", + "id": "98bddda9", "metadata": { "editable": true }, @@ -346,7 +395,7 @@ }, { "cell_type": "markdown", - "id": "fefaa223", + "id": "cdf9a3c1", "metadata": { "editable": true }, @@ -359,7 +408,7 @@ }, { "cell_type": "markdown", - "id": "c18c2546", + "id": "b6c2bf74", "metadata": { "editable": true }, @@ -371,7 +420,7 @@ }, { "cell_type": "markdown", - "id": "80c09fa0", + "id": "da69763e", "metadata": { "editable": true }, @@ -381,7 +430,7 @@ }, { "cell_type": "markdown", - "id": "577f153f", + "id": "551c98aa", "metadata": { "editable": true }, @@ -410,7 +459,7 @@ }, { "cell_type": "markdown", - "id": "bfc71c7a", + "id": "86fb7287", "metadata": { "editable": true }, @@ -422,7 +471,7 @@ }, { "cell_type": "markdown", - "id": "dc05e54b", + "id": "68ec5233", "metadata": { "editable": true }, @@ -434,7 +483,7 @@ }, { "cell_type": "markdown", - "id": "e350ea4c", + "id": "70e9b766", "metadata": { "editable": true }, @@ -448,7 +497,7 @@ }, { "cell_type": "markdown", - "id": "4c1af672", + "id": "a8fb7034", "metadata": { "editable": true }, @@ -460,7 +509,7 @@ }, { "cell_type": "markdown", - "id": "2d68a9e1", + "id": "d961679e", "metadata": { "editable": true }, @@ -474,7 +523,7 @@ }, { "cell_type": "markdown", - "id": "d3cd0ded", + "id": "e15124e6", "metadata": { "editable": true }, @@ -486,7 +535,7 @@ }, { "cell_type": "markdown", - "id": "1b27ce07", + "id": "c01a8a63", "metadata": { "editable": true }, @@ -496,7 +545,7 @@ }, { "cell_type": "markdown", - "id": "37b01022", + "id": "bfe93b9e", "metadata": { "editable": true }, @@ -508,7 +557,7 @@ }, { "cell_type": "markdown", - "id": "564d1cf7", + "id": "618d5bd2", "metadata": { "editable": true }, @@ -518,7 +567,7 @@ }, { "cell_type": "markdown", - "id": "a86038a0", + "id": "863c718b", "metadata": { "editable": true }, @@ -530,7 +579,7 @@ }, { "cell_type": "markdown", - "id": "7a63d750", + "id": "c3ae8213", "metadata": { "editable": true }, @@ -542,7 +591,7 @@ }, { "cell_type": "markdown", - "id": "be570dfb", + "id": "23f1468e", "metadata": { "editable": true }, @@ -554,7 +603,7 @@ }, { "cell_type": "markdown", - "id": "a2922b7f", + "id": "fb295d85", "metadata": { "editable": true }, @@ -564,7 +613,7 @@ }, { "cell_type": "markdown", - "id": "d6f23855", + "id": "bee53f21", "metadata": { "editable": true }, @@ -576,7 +625,7 @@ }, { "cell_type": "markdown", - "id": "2d4ad3ae", + "id": "8e362f58", "metadata": { "editable": true }, @@ -586,7 +635,7 @@ }, { "cell_type": "markdown", - "id": "2cc23968", + "id": "0053c378", "metadata": { "editable": true }, @@ -600,7 +649,7 @@ }, { "cell_type": "markdown", - "id": "dcee508e", + "id": "787e9c38", "metadata": { "editable": true }, @@ -619,7 +668,7 @@ }, { "cell_type": "markdown", - "id": "539441f5", + "id": "2a08e057", "metadata": { "editable": true }, @@ -635,7 +684,7 @@ }, { "cell_type": "markdown", - "id": "a6fe9031", + "id": "0c7c9163", "metadata": { "editable": true }, @@ -647,7 +696,7 @@ }, { "cell_type": "markdown", - "id": "9f442d27", + "id": "84f60ea4", "metadata": { "editable": true }, @@ -659,7 +708,7 @@ }, { "cell_type": "markdown", - "id": "dbc5a6b3", + "id": "14a28c43", "metadata": { "editable": true }, @@ -671,7 +720,7 @@ }, { "cell_type": "markdown", - "id": "773002da", + "id": "910d0f8a", "metadata": { "editable": true }, @@ -681,7 +730,7 @@ }, { "cell_type": "markdown", - "id": "8916c343", + "id": "caf8d17f", "metadata": { "editable": true }, @@ -693,7 +742,7 @@ }, { "cell_type": "markdown", - "id": "dbb1089b", + "id": "84153ace", "metadata": { "editable": true }, @@ -704,7 +753,7 @@ }, { "cell_type": "markdown", - "id": "77f73368", + "id": "68fac021", "metadata": { "editable": true }, @@ -716,7 +765,7 @@ }, { "cell_type": "markdown", - "id": "26cb9da7", + "id": "42403e3f", "metadata": { "editable": true }, @@ -729,7 +778,7 @@ }, { "cell_type": "markdown", - "id": "d41c488a", + "id": "d6688122", "metadata": { "editable": true }, @@ -742,7 +791,7 @@ }, { "cell_type": "markdown", - "id": "beddc517", + "id": "f4e4572f", "metadata": { "editable": true }, @@ -754,7 +803,7 @@ }, { "cell_type": "markdown", - "id": "b5846b0b", + "id": "413f6089", "metadata": { "editable": true }, @@ -764,7 +813,7 @@ }, { "cell_type": "markdown", - "id": "3703263d", + "id": "519cb613", "metadata": { "editable": true }, @@ -776,7 +825,7 @@ }, { "cell_type": "markdown", - "id": "4d6f538d", + "id": "298fb57a", "metadata": { "editable": true }, @@ -786,7 +835,7 @@ }, { "cell_type": "markdown", - "id": "4528ddb8", + "id": "6d2eda72", "metadata": { "editable": true }, @@ -798,7 +847,7 @@ }, { "cell_type": "markdown", - "id": "94aa4b98", + "id": "461b38c2", "metadata": { "editable": true }, @@ -815,7 +864,7 @@ }, { "cell_type": "markdown", - "id": "707ba0e7", + "id": "25661261", "metadata": { "editable": true }, @@ -827,7 +876,7 @@ }, { "cell_type": "markdown", - "id": "51539d68", + "id": "b1c639c3", "metadata": { "editable": true }, @@ -837,7 +886,7 @@ }, { "cell_type": "markdown", - "id": "2b4c5395", + "id": "2513220a", "metadata": { "editable": true }, @@ -849,7 +898,7 @@ }, { "cell_type": "markdown", - "id": "93ef8c1a", + "id": "1c2cc026", "metadata": { "editable": true }, @@ -859,7 +908,7 @@ }, { "cell_type": "markdown", - "id": "c3c720ba", + "id": "239c9f1e", "metadata": { "editable": true }, @@ -871,7 +920,7 @@ }, { "cell_type": "markdown", - "id": "9fc6c658", + "id": "69c99778", "metadata": { "editable": true }, @@ -884,7 +933,7 @@ }, { "cell_type": "markdown", - "id": "dbb40739", + "id": "2a7f03d2", "metadata": { "editable": true }, @@ -896,7 +945,7 @@ }, { "cell_type": "markdown", - "id": "299d9c43", + "id": "42e38dac", "metadata": { "editable": true }, @@ -908,7 +957,7 @@ }, { "cell_type": "markdown", - "id": "fbdf5d22", + "id": "0a0f9d48", "metadata": { "editable": true }, @@ -918,7 +967,7 @@ }, { "cell_type": "markdown", - "id": "3ecd29fa", + "id": "f5609acf", "metadata": { "editable": true }, @@ -932,7 +981,7 @@ }, { "cell_type": "markdown", - "id": "c912e415", + "id": "811fbf9c", "metadata": { "editable": true }, @@ -942,7 +991,7 @@ }, { "cell_type": "markdown", - "id": "44cc2f6d", + "id": "0e77e9c9", "metadata": { "editable": true }, @@ -954,7 +1003,7 @@ }, { "cell_type": "markdown", - "id": "e3563988", + "id": "89a8bdb4", "metadata": { "editable": true }, @@ -964,7 +1013,7 @@ }, { "cell_type": "markdown", - "id": "91f05ec9", + "id": "f55cf982", "metadata": { "editable": true }, @@ -976,7 +1025,7 @@ }, { "cell_type": "markdown", - "id": "2d866501", + "id": "74a2b112", "metadata": { "editable": true }, @@ -986,7 +1035,7 @@ }, { "cell_type": "markdown", - "id": "557f0f5a", + "id": "793d983e", "metadata": { "editable": true }, @@ -998,7 +1047,7 @@ }, { "cell_type": "markdown", - "id": "e75cd54d", + "id": "809c79a6", "metadata": { "editable": true }, @@ -1012,7 +1061,7 @@ }, { "cell_type": "markdown", - "id": "0540b257", + "id": "182e3dd3", "metadata": { "editable": true }, @@ -1024,7 +1073,7 @@ }, { "cell_type": "markdown", - "id": "039fbfd4", + "id": "5be18bee", "metadata": { "editable": true }, @@ -1035,7 +1084,7 @@ }, { "cell_type": "markdown", - "id": "c674c921", + "id": "b2c80cb9", "metadata": { "editable": true }, @@ -1047,7 +1096,7 @@ }, { "cell_type": "markdown", - "id": "27fc7fdf", + "id": "904f7809", "metadata": { "editable": true }, @@ -1059,7 +1108,7 @@ }, { "cell_type": "markdown", - "id": "a29297a5", + "id": "19c89f7b", "metadata": { "editable": true }, @@ -1071,7 +1120,7 @@ }, { "cell_type": "markdown", - "id": "6067646e", + "id": "b770c888", "metadata": { "editable": true }, @@ -1081,7 +1130,7 @@ }, { "cell_type": "markdown", - "id": "8f11d134", + "id": "5d6972a6", "metadata": { "editable": true }, @@ -1093,7 +1142,7 @@ }, { "cell_type": "markdown", - "id": "f80a1e21", + "id": "8afac0bd", "metadata": { "editable": true }, @@ -1103,7 +1152,7 @@ }, { "cell_type": "markdown", - "id": "3b8c8bbb", + "id": "42a65296", "metadata": { "editable": true }, @@ -1115,7 +1164,7 @@ }, { "cell_type": "markdown", - "id": "399662d1", + "id": "23d71397", "metadata": { "editable": true }, @@ -1126,7 +1175,7 @@ }, { "cell_type": "markdown", - "id": "be96c8df", + "id": "45a66cda", "metadata": { "editable": true }, @@ -1138,7 +1187,7 @@ }, { "cell_type": "markdown", - "id": "94d38036", + "id": "2a04278d", "metadata": { "editable": true }, @@ -1152,7 +1201,7 @@ }, { "cell_type": "markdown", - "id": "204326ba", + "id": "8786abf6", "metadata": { "editable": true }, @@ -1164,7 +1213,7 @@ }, { "cell_type": "markdown", - "id": "930989cb", + "id": "fcdb0379", "metadata": { "editable": true }, @@ -1176,7 +1225,7 @@ }, { "cell_type": "markdown", - "id": "dee7875c", + "id": "ad92ac06", "metadata": { "editable": true }, @@ -1186,7 +1235,7 @@ }, { "cell_type": "markdown", - "id": "70b43c94", + "id": "4469299b", "metadata": { "editable": true }, @@ -1203,7 +1252,7 @@ }, { "cell_type": "markdown", - "id": "1b462027", + "id": "5766833a", "metadata": { "editable": true }, @@ -1214,7 +1263,7 @@ }, { "cell_type": "markdown", - "id": "1b31f910", + "id": "f358922f", "metadata": { "editable": true }, @@ -1227,7 +1276,7 @@ }, { "cell_type": "markdown", - "id": "c7b97ef1", + "id": "c82fb30f", "metadata": { "editable": true }, @@ -1239,7 +1288,7 @@ }, { "cell_type": "markdown", - "id": "2d37439b", + "id": "db870dc2", "metadata": { "editable": true }, @@ -1249,7 +1298,7 @@ }, { "cell_type": "markdown", - "id": "bc7856b0", + "id": "1ed0d422", "metadata": { "editable": true }, @@ -1261,7 +1310,7 @@ }, { "cell_type": "markdown", - "id": "718a26f2", + "id": "296a4d2f", "metadata": { "editable": true }, @@ -1271,7 +1320,7 @@ }, { "cell_type": "markdown", - "id": "5cabcadb", + "id": "d7135a70", "metadata": { "editable": true }, @@ -1283,7 +1332,7 @@ }, { "cell_type": "markdown", - "id": "0242a045", + "id": "945202a8", "metadata": { "editable": true }, @@ -1293,7 +1342,7 @@ }, { "cell_type": "markdown", - "id": "0ddc6cf4", + "id": "1ddd92f3", "metadata": { "editable": true }, @@ -1305,7 +1354,7 @@ }, { "cell_type": "markdown", - "id": "87aee740", + "id": "6454c347", "metadata": { "editable": true }, @@ -1315,7 +1364,7 @@ }, { "cell_type": "markdown", - "id": "cde4a279", + "id": "a2354e90", "metadata": { "editable": true }, @@ -1327,7 +1376,7 @@ }, { "cell_type": "markdown", - "id": "42158438", + "id": "02bfba2d", "metadata": { "editable": true }, @@ -1337,7 +1386,7 @@ }, { "cell_type": "markdown", - "id": "af22d92e", + "id": "bce7dc04", "metadata": { "editable": true }, @@ -1357,7 +1406,7 @@ }, { "cell_type": "markdown", - "id": "57050b81", + "id": "7cb11af4", "metadata": { "editable": true }, @@ -1369,7 +1418,7 @@ }, { "cell_type": "markdown", - "id": "49274350", + "id": "648209c1", "metadata": { "editable": true }, @@ -1379,7 +1428,7 @@ }, { "cell_type": "markdown", - "id": "c7897f75", + "id": "c387bedc", "metadata": { "editable": true }, @@ -1391,7 +1440,7 @@ }, { "cell_type": "markdown", - "id": "7827f433", + "id": "8431ac8a", "metadata": { "editable": true }, @@ -1407,7 +1456,7 @@ }, { "cell_type": "markdown", - "id": "818ba3db", + "id": "59e4e54a", "metadata": { "editable": true }, @@ -1419,7 +1468,7 @@ }, { "cell_type": "markdown", - "id": "7b6e3768", + "id": "1d4b0f2c", "metadata": { "editable": true }, @@ -1431,7 +1480,7 @@ }, { "cell_type": "markdown", - "id": "b201effc", + "id": "86cb41cf", "metadata": { "editable": true }, @@ -1441,7 +1490,7 @@ }, { "cell_type": "markdown", - "id": "1fcee60a", + "id": "9bd30520", "metadata": { "editable": true }, @@ -1453,7 +1502,7 @@ }, { "cell_type": "markdown", - "id": "5a72560e", + "id": "7cf7cafb", "metadata": { "editable": true }, @@ -1465,7 +1514,7 @@ }, { "cell_type": "markdown", - "id": "184e84d0", + "id": "9a941f2e", "metadata": { "editable": true }, @@ -1477,7 +1526,7 @@ }, { "cell_type": "markdown", - "id": "894cb0ce", + "id": "2bbd2f06", "metadata": { "editable": true }, @@ -1487,7 +1536,7 @@ }, { "cell_type": "markdown", - "id": "2b69737b", + "id": "7a70852e", "metadata": { "editable": true }, @@ -1499,7 +1548,7 @@ }, { "cell_type": "markdown", - "id": "152d0174", + "id": "c527c9ea", "metadata": { "editable": true }, @@ -1509,7 +1558,7 @@ }, { "cell_type": "markdown", - "id": "db35a010", + "id": "81d1cfc7", "metadata": { "editable": true }, @@ -1521,7 +1570,7 @@ }, { "cell_type": "markdown", - "id": "774b38be", + "id": "94d41684", "metadata": { "editable": true }, @@ -1531,7 +1580,7 @@ }, { "cell_type": "markdown", - "id": "393526ac", + "id": "ddb09360", "metadata": { "editable": true }, @@ -1543,7 +1592,7 @@ }, { "cell_type": "markdown", - "id": "461142ba", + "id": "eea21e1a", "metadata": { "editable": true }, @@ -1554,7 +1603,7 @@ }, { "cell_type": "markdown", - "id": "46c9f47a", + "id": "acb853ae", "metadata": { "editable": true }, @@ -1566,7 +1615,7 @@ }, { "cell_type": "markdown", - "id": "49a4d011", + "id": "b729b07c", "metadata": { "editable": true }, @@ -1578,7 +1627,7 @@ }, { "cell_type": "markdown", - "id": "1fec7c9e", + "id": "6485283a", "metadata": { "editable": true }, @@ -1588,7 +1637,7 @@ }, { "cell_type": "markdown", - "id": "cd8bc345", + "id": "28688145", "metadata": { "editable": true }, @@ -1600,7 +1649,7 @@ }, { "cell_type": "markdown", - "id": "d9cbf55e", + "id": "d21b4270", "metadata": { "editable": true }, @@ -1626,7 +1675,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "0db994f1", + "id": "69abf14b", "metadata": { "collapsed": false, "editable": true @@ -1683,7 +1732,7 @@ }, { "cell_type": "markdown", - "id": "8a0057dc", + "id": "09ac41a5", "metadata": { "editable": true }, @@ -1695,7 +1744,7 @@ }, { "cell_type": "markdown", - "id": "abc0c595", + "id": "717bd799", "metadata": { "editable": true }, @@ -1707,7 +1756,7 @@ }, { "cell_type": "markdown", - "id": "d71d8791", + "id": "da6f4551", "metadata": { "editable": true }, @@ -1717,7 +1766,7 @@ }, { "cell_type": "markdown", - "id": "4c3c1113", + "id": "ee1bce7c", "metadata": { "editable": true }, @@ -1729,7 +1778,7 @@ }, { "cell_type": "markdown", - "id": "c66cc7d2", + "id": "8fc3487a", "metadata": { "editable": true }, @@ -1739,7 +1788,7 @@ }, { "cell_type": "markdown", - "id": "e184524a", + "id": "9f02aed6", "metadata": { "editable": true }, @@ -1751,7 +1800,7 @@ }, { "cell_type": "markdown", - "id": "142f8d50", + "id": "7500279f", "metadata": { "editable": true }, @@ -1762,7 +1811,7 @@ }, { "cell_type": "markdown", - "id": "31fd828f", + "id": "c27b445d", "metadata": { "editable": true }, @@ -1774,7 +1823,7 @@ }, { "cell_type": "markdown", - "id": "3b0d653a", + "id": "31ae411b", "metadata": { "editable": true }, @@ -1784,7 +1833,7 @@ }, { "cell_type": "markdown", - "id": "9a727bf4", + "id": "a5e8e767", "metadata": { "editable": true }, @@ -1796,7 +1845,7 @@ }, { "cell_type": "markdown", - "id": "2b663b7e", + "id": "ba307326", "metadata": { "editable": true }, @@ -1814,7 +1863,7 @@ }, { "cell_type": "markdown", - "id": "c3e77b31", + "id": "7cab3225", "metadata": { "editable": true }, @@ -1825,7 +1874,7 @@ }, { "cell_type": "markdown", - "id": "2f17dcaf", + "id": "11c6ff4d", "metadata": { "editable": true }, @@ -1837,7 +1886,7 @@ }, { "cell_type": "markdown", - "id": "be5e27f0", + "id": "6c8f7506", "metadata": { "editable": true }, @@ -1847,7 +1896,7 @@ }, { "cell_type": "markdown", - "id": "112c23b0", + "id": "a45e6e64", "metadata": { "editable": true }, @@ -1864,7 +1913,7 @@ }, { "cell_type": "markdown", - "id": "87b1f8b0", + "id": "46ed81a4", "metadata": { "editable": true }, @@ -1878,7 +1927,7 @@ }, { "cell_type": "markdown", - "id": "af672dec", + "id": "3ff6f1da", "metadata": { "editable": true }, @@ -1893,7 +1942,7 @@ }, { "cell_type": "markdown", - "id": "d402eb2a", + "id": "538f20df", "metadata": { "editable": true }, @@ -1905,7 +1954,7 @@ }, { "cell_type": "markdown", - "id": "38931e4b", + "id": "0fbfd074", "metadata": { "editable": true }, @@ -1933,7 +1982,7 @@ }, { "cell_type": "markdown", - "id": "a1773101", + "id": "704cd85d", "metadata": { "editable": true }, @@ -1945,7 +1994,7 @@ }, { "cell_type": "markdown", - "id": "5167cd90", + "id": "856099b1", "metadata": { "editable": true }, @@ -1960,7 +2009,7 @@ }, { "cell_type": "markdown", - "id": "c9dcb083", + "id": "e589ef9b", "metadata": { "editable": true }, @@ -1971,7 +2020,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "49af7f92", + "id": "883ce376", "metadata": { "collapsed": false, "editable": true @@ -2170,7 +2219,7 @@ }, { "cell_type": "markdown", - "id": "99b01441", + "id": "e0b07242", "metadata": { "editable": true }, @@ -2182,7 +2231,7 @@ }, { "cell_type": "markdown", - "id": "7ce54aca", + "id": "71b7dd16", "metadata": { "editable": true }, @@ -2197,7 +2246,7 @@ }, { "cell_type": "markdown", - "id": "cac73c40", + "id": "dfbc6f87", "metadata": { "editable": true }, @@ -2214,7 +2263,7 @@ }, { "cell_type": "markdown", - "id": "aece7452", + "id": "df108e07", "metadata": { "editable": true }, @@ -2235,7 +2284,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "cbdb6008", + "id": "552c81d8", "metadata": { "collapsed": false, "editable": true @@ -2248,7 +2297,7 @@ }, { "cell_type": "markdown", - "id": "26bb80f7", + "id": "994935a4", "metadata": { "editable": true }, @@ -2258,7 +2307,7 @@ }, { "cell_type": "markdown", - "id": "fbd38783", + "id": "ffb2a7c0", "metadata": { "editable": true }, @@ -2270,7 +2319,7 @@ }, { "cell_type": "markdown", - "id": "1fa4fdbf", + "id": "5259f6a6", "metadata": { "editable": true }, @@ -2285,7 +2334,7 @@ }, { "cell_type": "markdown", - "id": "0d6c84fb", + "id": "bf9f261c", "metadata": { "editable": true }, @@ -2295,7 +2344,7 @@ }, { "cell_type": "markdown", - "id": "a069c872", + "id": "ee8c54a5", "metadata": { "editable": true }, @@ -2314,7 +2363,7 @@ }, { "cell_type": "markdown", - "id": "9a4c0894", + "id": "006254c3", "metadata": { "editable": true }, @@ -2324,7 +2373,7 @@ }, { "cell_type": "markdown", - "id": "8612c078", + "id": "4d527503", "metadata": { "editable": true }, @@ -2336,7 +2385,7 @@ }, { "cell_type": "markdown", - "id": "85ec4a5c", + "id": "612c3b4d", "metadata": { "editable": true }, @@ -2346,7 +2395,7 @@ }, { "cell_type": "markdown", - "id": "994b8395", + "id": "b6fc7d61", "metadata": { "editable": true }, @@ -2358,7 +2407,7 @@ }, { "cell_type": "markdown", - "id": "1fbb16a6", + "id": "b2f621ba", "metadata": { "editable": true }, @@ -2368,7 +2417,7 @@ }, { "cell_type": "markdown", - "id": "af89e786", + "id": "f3dc8b7a", "metadata": { "editable": true }, @@ -2380,7 +2429,7 @@ }, { "cell_type": "markdown", - "id": "016c22ed", + "id": "6d437cb7", "metadata": { "editable": true }, @@ -2391,7 +2440,7 @@ }, { "cell_type": "markdown", - "id": "ecdcfe97", + "id": "1c964d4d", "metadata": { "editable": true }, @@ -2403,7 +2452,7 @@ }, { "cell_type": "markdown", - "id": "16e0c215", + "id": "777f34e1", "metadata": { "editable": true }, @@ -2415,7 +2464,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "1781bfa9", + "id": "dace596a", "metadata": { "collapsed": false, "editable": true @@ -2439,7 +2488,7 @@ }, { "cell_type": "markdown", - "id": "9013d663", + "id": "d9094685", "metadata": { "editable": true }, @@ -2451,7 +2500,7 @@ }, { "cell_type": "markdown", - "id": "67964577", + "id": "26142331", "metadata": { "editable": true }, @@ -2468,7 +2517,7 @@ }, { "cell_type": "markdown", - "id": "13711084", + "id": "4cee7167", "metadata": { "editable": true }, diff --git a/doc/src/week46/week46.do.txt b/doc/src/week46/week46.do.txt index 83c685f9f..c6ca6e80c 100644 --- a/doc/src/week46/week46.do.txt +++ b/doc/src/week46/week46.do.txt @@ -6,7 +6,7 @@ DATE: today ===== Overview of week 46 ===== * _Thursday_: Summary of Gradient Boosting. Start support Vector Machines -* _Friday_: Eventual Workshop on project 3. Discussion of project 3. +* _Friday_: Eventual Workshop on project 3. Discussion of project 3 and support vector machines !bblock Reading @@ -24,6 +24,34 @@ o "Excellent videos on Gradient Boosting":"https://www.youtube.com/watch?v=3CC4N !eblock + +!split +===== Eventual mini-workshop on project 3, Friday November 18 ===== + +We have tried every year to organize a kind of mini-workshop on project 3. In 2020 the contributions were (and some of these ended up in thesis work and/or publications, online only due to Covid-19!) + +* Maria Emine Nylund: _Lego Bricks Classifier_ +* Fabio Rodrigues Pereira: _Financial Machine Learning_ +* Markus Borud Pettersen: _Machine Learning and Brain Grid Cells_ +* Jing Sun and Endrias Getachew Asgedom: _Machine learning-based approaches to denoising microseismic data_ +* Felicia Jacobsen: _Analysis of Breast Cancer Data_ +* Simon Elias Schrader: _Predicting atomization energies of molecules_ +* Varvara Bazilova and Sergio Andres Diaz Mesa: _Glacier Mapping and Machine Learning_ +* Gert Werner Kluge, Hanna Alida Fossen Hardersen and Sushma Sharma Adhikari: _Gamma ray signals stemming from dark matter in the galactic center_ + +!split +===== Workshop topics 2021 (partly online) ===== + +o _1215-1225pm_: Are Frode Helvig Kvanum, Gard Høivang, and David Andreas Bordvik, *Next-day forecasts on spot prices for electricity* +o _1225-1235pm_: Lidia Luque, *Voxel-wise multi-label brain tumor classification* +o _1235-1245pm_: Marcus Berget et al, *Locating suspicious brain activity using neural networks* +o _1245-1255pm_: William Ho and Tom-Ruben Traavik Kvalvaag, *Comparing semi-supervised learning and supervised learning for image classification* +We would very much like to organize something similar this year as well. Feel free to come with sugesstions by Thursday November 17. We will then try to set up the various contributions for Friday November 18. +The presentations last normally 5-15 mins and span from loose ideas to more well-defined topics. Nothing pretentious, we wish to keep this as low-key as possible. + + + + !split ===== Support Vector Machines, overarching aims ===== diff --git a/doc/src/week46/workshop.do.txt b/doc/src/week46/workshop.do.txt new file mode 100644 index 000000000..9de861131 --- /dev/null +++ b/doc/src/week46/workshop.do.txt @@ -0,0 +1,49 @@ +TITLE: Week 46: Support Vector Machines and Project 3 +AUTHOR: Morten Hjorth-Jensen {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +DATE: today + +!split +===== Overview of week 46 ===== + +* _Thursday_: Summary of Gradient Boosting. Start support Vector Machines +* _Friday_: Eventual Workshop on project 3. Discussion of project 3. + + +!bblock Reading +Reading recommendations: + o See lecture notes for week 46 at https://compphysics.github.io/MachineLearning/doc/web/course.html. + o Hastie et al chapter 12 + o Bishop chapter 7.1 and 7.2 +!eblock + + +!bblock Videos +o "Overview video on Support Vector Machines":"https://www.youtube.com/watch?v=efR1C6CvhmE&ab_channel=StatQuestwithJoshStarmer" +o See also "this video":"https://www.youtube.com/watch?v=N1vOgolbjSc&ab_channel=AliceZhao". +o "Excellent videos on Gradient Boosting":"https://www.youtube.com/watch?v=3CC4N4z3GJc&ab_channel=StatQuestwithJoshStarmer" +!eblock + + +!split +===== project 3 workshop ===== + +We have tried every year to organize a kind of mini-workshop on project 3. In 2020 the contributions were (and some of these ended up in thesis work and/or publications!) + +* Maria Emine Nylund: _Lego Bricks Classifier_ +* Fabio Rodrigues Pereira: _Financial Machine Learning_ +* Markus Borud Pettersen: _Machine Learning and Brain Grid Cells_ +* Jing Sun and Endrias Getachew Asgedom: _Machine learning-based approaches to denoising microseismic data_ +* Felicia Jacobsen: _Analysis of Breast Cancer Data_ +* Simon Elias Schrader: _Predicting atomization energies of molecules_ +* Varvara Bazilova and Sergio Andres Diaz Mesa: _Glacier Mapping and Machine Learning_ +* Gert Werner Kluge, Hanna Alida Fossen Hardersen and Sushma Sharma Adhikari: _Gamma ray signals stemming from dark matter in the galactic center_ + +!split +===== Workshop topics 2021 ===== + +o _1215-1225pm_: Are Frode Helvig Kvanum, Gard Høivang, and David Andreas Bordvik, *Next-day forecasts on spot prices for electricity* +o _1225-1235pm_: Lidia Luque, *Voxel-wise multi-label brain tumor classification* +o _1235-1245pm_: Marcus Berget et al, *Locating suspicious brain activity using neural networks* +o _1245-1255pm_: William Ho and Tom-Ruben Traavik Kvalvaag, *Comparing semi-supervised learning and supervised learning for image classification* +We would very much like to organize something similar this year as well. Feel free to come with sugesstions by Thursday November 17. We will then try to set up the various contributions for Friday November 18. +The presentations last normally 5-15 mins and span from loose ideas to more well-defined topics. Nothing pretentious, we wish to keep this as low-key as possible.