diff --git a/doc/pub/week46/html/._week46-bs000.html b/doc/pub/week46/html/._week46-bs000.html index b621492c7..4a81a76eb 100644 --- a/doc/pub/week46/html/._week46-bs000.html +++ b/doc/pub/week46/html/._week46-bs000.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -187,7 +192,7 @@ MathJax.Hub.Config({
-

Nov 18, 2021

+

Nov 19, 2021


@@ -212,7 +217,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs001.html b/doc/pub/week46/html/._week46-bs001.html index 77bf2a74a..407a58412 100644 --- a/doc/pub/week46/html/._week46-bs001.html +++ b/doc/pub/week46/html/._week46-bs001.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -218,7 +223,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs002.html b/doc/pub/week46/html/._week46-bs002.html index da878a229..0a3a14dc1 100644 --- a/doc/pub/week46/html/._week46-bs002.html +++ b/doc/pub/week46/html/._week46-bs002.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -206,7 +211,7 @@ Feel free to suggest topics.
  • 11
  • 12
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs003.html b/doc/pub/week46/html/._week46-bs003.html index f8f9ae8c8..45a6c90ef 100644 --- a/doc/pub/week46/html/._week46-bs003.html +++ b/doc/pub/week46/html/._week46-bs003.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,35 +174,15 @@ MathJax.Hub.Config({

     

     

     

    -

    Support Vector Machines, overarching aims

    +

    Workshop plan Friday November 19 and the rest of the lecture

    -

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

    +
      +
    1. 1215-1225pm: Are Frode Helvi Kvanum, Gard Høivang, and David Andreas Bordvik, Next-day forecasts on spot rices 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 will use the second part of the lecture for further discussions of projects 2 and 3 and a summary on boosting methods from last week. Feel free to bring your laptops.

    @@ -217,7 +202,7 @@ unlikely that we can separate classes easily by say straight lines.

  • 12
  • 13
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs004.html b/doc/pub/week46/html/._week46-bs004.html index dc8633f90..aa405f9dd 100644 --- a/doc/pub/week46/html/._week46-bs004.html +++ b/doc/pub/week46/html/._week46-bs004.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,108 +174,35 @@ MathJax.Hub.Config({

     

     

     

    -

    Hyperplanes and all that

    +

    Support Vector Machines, overarching aims

    -

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

    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.

    -

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

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

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

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

    @@ -291,7 +223,7 @@ plt.show()

  • 13
  • 14
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs005.html b/doc/pub/week46/html/._week46-bs005.html index eb0008270..64917d238 100644 --- a/doc/pub/week46/html/._week46-bs005.html +++ b/doc/pub/week46/html/._week46-bs005.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,32 +174,107 @@ MathJax.Hub.Config({

     

     

     

    -

    What is a hyperplane?

    +

    Hyperplanes and all that

    -

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

    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.

    -

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

    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.

    -

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

    -$$ -b+w_1x_1+w_2x_2=0, -$$ + +
    +
    +
    +
    +
    +
    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
     
    -

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

    @@ -217,7 +297,7 @@ $$

  • 14
  • 15
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs006.html b/doc/pub/week46/html/._week46-bs006.html index 12cb78e12..c185e3b0a 100644 --- a/doc/pub/week46/html/._week46-bs006.html +++ b/doc/pub/week46/html/._week46-bs006.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,45 +174,33 @@ MathJax.Hub.Config({

     

     

     

    -

    A \( p \)-dimensional space of features

    +

    What is a hyperplane?

    -

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

    -

    Equivalently, for the two classes of observations we have

    +

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

    + +

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

    $$ -y_i\left(b+w_1x_{i1}+w_2x_{i2}+\dots +w_px_{ip}\right) > 0. +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. $$ -

    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.

    @@ -230,7 +223,7 @@ $$

  • 15
  • 16
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs007.html b/doc/pub/week46/html/._week46-bs007.html index bac666519..3db00d5c6 100644 --- a/doc/pub/week46/html/._week46-bs007.html +++ b/doc/pub/week46/html/._week46-bs007.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -168,30 +173,46 @@ MathJax.Hub.Config({

     

     

     

    - -

    The two-dimensional case

    + +

    A \( p \)-dimensional space of features

    -

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

    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.

    -

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

    +

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

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

    +

    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.

    @@ -215,7 +236,7 @@ for our data sample.

  • 16
  • 17
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs008.html b/doc/pub/week46/html/._week46-bs008.html index af1b460a8..3a07d05ef 100644 --- a/doc/pub/week46/html/._week46-bs008.html +++ b/doc/pub/week46/html/._week46-bs008.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -168,23 +173,30 @@ MathJax.Hub.Config({

     

     

     

    - -

    Getting into the details

    + +

    The two-dimensional case

    -

    Let us define the function

    -$$ -f(x) = \boldsymbol{w}^T\boldsymbol{x}+b = 0, -$$ +

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

    -

    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

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

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

    @@ -209,7 +221,7 @@ $$

  • 17
  • 18
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs009.html b/doc/pub/week46/html/._week46-bs009.html index 0999dc24f..a58888d25 100644 --- a/doc/pub/week46/html/._week46-bs009.html +++ b/doc/pub/week46/html/._week46-bs009.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,25 +174,20 @@ MathJax.Hub.Config({

     

     

     

    -

    First attempt at a minimization approach

    - -

    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 -

    +

    Getting into the details

    +

    Let us define the function

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

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

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

    -

    and

    +

    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

    $$ -\frac{\partial C}{\partial \boldsymbol{w}} = -\sum_{i\in M} y_ix_i. +\delta = \frac{1}{\vert\vert \boldsymbol{w}\vert\vert}(\boldsymbol{w}^T\boldsymbol{x}+b). $$ @@ -215,7 +215,7 @@ $$
  • 18
  • 19
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs010.html b/doc/pub/week46/html/._week46-bs010.html index 99dfadce0..41f0e1101 100644 --- a/doc/pub/week46/html/._week46-bs010.html +++ b/doc/pub/week46/html/._week46-bs010.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,19 +174,27 @@ MathJax.Hub.Config({

     

     

     

    -

    Solving the equations

    +

    First attempt at a minimization approach

    + +

    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 +

    -

    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}, +C(\boldsymbol{w},b) = -\sum_{i\in M} y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b). $$ -

    and

    +

    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

    $$ -\boldsymbol{w} \leftarrow \boldsymbol{w} +\eta \frac{\partial C}{\partial \boldsymbol{w}}, +\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. $$ -

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

    @@ -208,7 +221,7 @@ $$

  • 19
  • 20
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs011.html b/doc/pub/week46/html/._week46-bs011.html index fc7df67aa..4329e6107 100644 --- a/doc/pub/week46/html/._week46-bs011.html +++ b/doc/pub/week46/html/._week46-bs011.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,35 +174,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Code Example

    +

    Solving the equations

    -

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

    +

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

    and

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

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

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

  • 20
  • 21
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs012.html b/doc/pub/week46/html/._week46-bs012.html index 45cd4b4af..2013063b5 100644 --- a/doc/pub/week46/html/._week46-bs012.html +++ b/doc/pub/week46/html/._week46-bs012.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,18 +174,35 @@ MathJax.Hub.Config({

     

     

     

    -

    Problems with the Simpler Approach

    +

    Code Example

    -

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

    -

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

    + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    @@ -207,7 +229,7 @@ at all.

  • 21
  • 22
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs013.html b/doc/pub/week46/html/._week46-bs013.html index d170402b3..2e4504c1c 100644 --- a/doc/pub/week46/html/._week46-bs013.html +++ b/doc/pub/week46/html/._week46-bs013.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,43 +174,17 @@ MathJax.Hub.Config({

     

     

     

    -

    A better approach

    +

    Problems with the Simpler 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). +

    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.

    -

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

    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.

    @@ -233,7 +212,7 @@ about Lagrangian multipliers.

  • 22
  • 23
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs014.html b/doc/pub/week46/html/._week46-bs014.html index 81625e9ed..a11d76e9f 100644 --- a/doc/pub/week46/html/._week46-bs014.html +++ b/doc/pub/week46/html/._week46-bs014.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,53 +174,43 @@ MathJax.Hub.Config({

     

     

     

    -

    A quick Reminder on Lagrangian Multipliers

    +

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

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

    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

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

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

    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.

    @@ -243,7 +238,7 @@ Then \( dz \) is no longer arbitrary.

  • 23
  • 24
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs015.html b/doc/pub/week46/html/._week46-bs015.html index cb264dab7..029f3f444 100644 --- a/doc/pub/week46/html/._week46-bs015.html +++ b/doc/pub/week46/html/._week46-bs015.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,45 +174,54 @@ MathJax.Hub.Config({

     

     

     

    -

    Adding the Multiplier

    +

    A quick Reminder on Lagrangian Multipliers

    -

    However, we can add to

    -$$ -df = \frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\frac{\partial f}{\partial z}dz, -$$ - -

    a multiplum of \( d\phi \), viz. \( \lambda d\phi \), resulting in

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

    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 +

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

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

    + +

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

    @@ -234,7 +248,7 @@ $$

  • 24
  • 25
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs016.html b/doc/pub/week46/html/._week46-bs016.html index fa58a569f..7c8741cab 100644 --- a/doc/pub/week46/html/._week46-bs016.html +++ b/doc/pub/week46/html/._week46-bs016.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,41 +174,45 @@ MathJax.Hub.Config({

     

     

     

    -

    Setting up the Problem

    -

    In order to solve the above problem, we define the following Lagrangian function to be minimized

    +

    Adding the Multiplier

    + +

    However, we can add to

    $$ -{\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], +df = \frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\frac{\partial f}{\partial z}dz, $$ -

    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

    +

    a multiplum of \( d\phi \), viz. \( \lambda d\phi \), resulting in

    $$ -\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0, +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. $$ -

    and

    +

    Our multiplier is chosen so that

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

    Inserting these constraints into the equation for \( {\cal L} \) we obtain

    +

    We need to remember that we took \( dx \) and \( dy \) to be arbitrary and thus we must have

    $$ -{\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, +\frac{\partial f}{\partial x}+\lambda\frac{\partial \phi}{\partial x} =0, $$ -

    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 +

    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

    $$ -\lambda_i\left[y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b) -1\right] \hspace{0.1cm}\forall i. +\frac{\partial f}{\partial x_i}+\sum_k\lambda_k\frac{\partial \phi_k}{\partial x_i} =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 \).

    @@ -230,7 +239,7 @@ $$

  • 25
  • 26
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs017.html b/doc/pub/week46/html/._week46-bs017.html index 9829adefe..5931e53e6 100644 --- a/doc/pub/week46/html/._week46-bs017.html +++ b/doc/pub/week46/html/._week46-bs017.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,26 +174,41 @@ MathJax.Hub.Config({

     

     

     

    -

    The problem to solve

    +

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

    We can rewrite

    +

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

    and its constraints in terms of a matrix-vector problem where we minimize w.r.t. \( \lambda \) the following problem

    +

    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 +

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

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

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

    @@ -215,7 +235,7 @@ $$

  • 26
  • 27
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs018.html b/doc/pub/week46/html/._week46-bs018.html index 39c0c924a..220c3f4f1 100644 --- a/doc/pub/week46/html/._week46-bs018.html +++ b/doc/pub/week46/html/._week46-bs018.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,36 +174,26 @@ MathJax.Hub.Config({

     

     

     

    -

    The last steps

    +

    The problem to solve

    -

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

    We can rewrite

    +$$ +{\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, +$$ + +

    and its constraints in terms of a matrix-vector problem where we minimize w.r.t. \( \lambda \) the following problem

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

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

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

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

    @@ -225,7 +220,7 @@ $$

  • 27
  • 28
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs019.html b/doc/pub/week46/html/._week46-bs019.html index 40dcea620..9b4bcb338 100644 --- a/doc/pub/week46/html/._week46-bs019.html +++ b/doc/pub/week46/html/._week46-bs019.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,37 +174,36 @@ MathJax.Hub.Config({

     

     

     

    -

    A soft classifier

    +

    The last steps

    -

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

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

    +$$ +\boldsymbol{w}=\sum_{i} \lambda_iy_i\boldsymbol{x}_i. +$$ -

    We introduce thus the so-called slack variables \( \boldsymbol{\xi} =[\xi_1,x_2,\dots,x_n] \) and -modify our previous equation -

    +

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

    to

    +

    resulting in

    $$ -y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1-\xi_i, +b = \frac{1}{y_i}-\boldsymbol{w}^T\boldsymbol{x}_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. -

    +

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

    Misclassifications occur when \( \xi_i > 1 \). Thus bounding the total sum by some value \( C \) bounds in turn the total number of -misclassifications. -

    +

    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.

    @@ -226,7 +230,7 @@ misclassifications.

  • 28
  • 29
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs020.html b/doc/pub/week46/html/._week46-bs020.html index fc0960e18..540f2f916 100644 --- a/doc/pub/week46/html/._week46-bs020.html +++ b/doc/pub/week46/html/._week46-bs020.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,56 +174,37 @@ MathJax.Hub.Config({

     

     

     

    -

    Soft optmization problem

    +

    A soft classifier

    -

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

    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.

    -

    subject to

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

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

    -

    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 +

    We introduce thus the so-called slack variables \( \boldsymbol{\xi} =[\xi_1,x_2,\dots,x_n] \) and +modify our previous equation

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

    to

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

    and

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

    with the requirement \( \xi_i\geq 0 \). The total violation is now \( \sum_i\xi \). +The value \( \xi_i \) in the constraint the last constraint corresponds to the amount by which the prediction +\( y_i(\boldsymbol{w}^T\boldsymbol{x}_i+b)=1 \) is on the wrong side of its margin. Hence by bounding the sum \( \sum_i \xi_i \), +we bound the total amount by which predictions fall on the wrong side of their margins. +

    +

    Misclassifications occur when \( \xi_i > 1 \). Thus bounding the total sum by some value \( C \) bounds in turn the total number of +misclassifications. +

    @@ -244,6 +230,8 @@ $$

  • 28
  • 29
  • 30
  • +
  • ...
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs021.html b/doc/pub/week46/html/._week46-bs021.html index 96aad1691..f76611f08 100644 --- a/doc/pub/week46/html/._week46-bs021.html +++ b/doc/pub/week46/html/._week46-bs021.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,93 +174,55 @@ MathJax.Hub.Config({

     

     

     

    -

    Kernels and non-linearity

    +

    Soft optmization problem

    -

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

    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

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

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

    +$$ +\gamma_i\xi_i = 0, +$$ -

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

    and

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

    @@ -281,6 +248,7 @@ plt.show()

  • 28
  • 29
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs022.html b/doc/pub/week46/html/._week46-bs022.html index 99fa9d815..c2a80a9bb 100644 --- a/doc/pub/week46/html/._week46-bs022.html +++ b/doc/pub/week46/html/._week46-bs022.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,47 +174,95 @@ MathJax.Hub.Config({

     

     

     

    -

    The equations

    +

    Kernels and non-linearity

    -

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

    -$$ -z = \phi(x_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right). -$$ - -

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

    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.

    -

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

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

    diff --git a/doc/pub/week46/html/._week46-bs023.html b/doc/pub/week46/html/._week46-bs023.html index 3a9551131..3a9334e73 100644 --- a/doc/pub/week46/html/._week46-bs023.html +++ b/doc/pub/week46/html/._week46-bs023.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,38 +174,45 @@ MathJax.Hub.Config({

     

     

     

    -

    The problem to solve

    -

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

    +

    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)

    $$ -{\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, +z = \phi(x_i) =\left(x_i^2, y_i^2, \sqrt{2}x_iy_i\right). $$ -

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

    +

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

    $$ -\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}, +{\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 \( \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 \). +

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

    -

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

    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.

    @@ -224,6 +236,7 @@ Given a kernel \( K \) and the targets \( y_i \) this matrix is easy to set up.

  • 28
  • 29
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs024.html b/doc/pub/week46/html/._week46-bs024.html index ce78f31f4..92e0ef84a 100644 --- a/doc/pub/week46/html/._week46-bs024.html +++ b/doc/pub/week46/html/._week46-bs024.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,36 +174,38 @@ 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 problem to solve

    +

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

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

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

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

    -

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

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

    @@ -221,6 +228,7 @@ in practice.

  • 28
  • 29
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs025.html b/doc/pub/week46/html/._week46-bs025.html index a29620c79..ec82f978d 100644 --- a/doc/pub/week46/html/._week46-bs025.html +++ b/doc/pub/week46/html/._week46-bs025.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,217 +174,37 @@ MathJax.Hub.Config({

     

     

     

    -

    The moons example

    +

    Different kernels and Mercer's theorem

    - -
    -
    -
    -
    -
    -
    from __future__ import division, print_function, unicode_literals
    +

    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.

    -import numpy as np -np.random.seed(42) +

    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 +

    -import matplotlib -import matplotlib.pyplot as plt -plt.rcParams['axes.labelsize'] = 14 -plt.rcParams['xtick.labelsize'] = 12 -plt.rcParams['ytick.labelsize'] = 12 +$$ +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. +

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

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

    @@ -400,6 +225,7 @@ plt.show()

  • 28
  • 29
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs026.html b/doc/pub/week46/html/._week46-bs026.html index 26d44604d..6a8d47061 100644 --- a/doc/pub/week46/html/._week46-bs026.html +++ b/doc/pub/week46/html/._week46-bs026.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,26 +174,217 @@ MathJax.Hub.Config({

     

     

     

    -

    Mathematical optimization of convex functions

    +

    The moons example

    -

    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*} -$$ + +
    +
    +
    +
    +
    +
    from __future__ import division, print_function, unicode_literals
     
    -

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

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

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

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

    @@ -208,6 +404,7 @@ In our discussion on gradient descent methods we discussed at length the definit

  • 28
  • 29
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs027.html b/doc/pub/week46/html/._week46-bs027.html index 6660e728f..11d270a20 100644 --- a/doc/pub/week46/html/._week46-bs027.html +++ b/doc/pub/week46/html/._week46-bs027.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,44 +174,26 @@ MathJax.Hub.Config({

     

     

     

    -

    How do we solve these problems?

    +

    Mathematical optimization of convex functions

    -

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

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

    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.

    -

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

    +

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

    - - -
    -
    -
    -
    -
    -
    import numpy
    -import cvxopt
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

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

    +

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

    @@ -225,6 +212,7 @@ converge. So, welcome to the promised land of quadratic programming.

  • 28
  • 29
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs028.html b/doc/pub/week46/html/._week46-bs028.html index 5e81fc122..4bab3a0cd 100644 --- a/doc/pub/week46/html/._week46-bs028.html +++ b/doc/pub/week46/html/._week46-bs028.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,53 +174,19 @@ MathJax.Hub.Config({

     

     

     

    -

    A simple example

    +

    How do we solve these problems?

    -

    We remind ourselves about the general problem we want to solve

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

    Let us show how to perform the optmization using a simple case. Assume we want to optimize the following problem

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

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

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

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

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

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

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

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

    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.

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

    +

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

    +
    @@ -223,19 +194,8 @@ The following code solves the equations for us
    -
    # 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’]
    +  
    import numpy
    +import cvxopt
     
    @@ -251,6 +211,7 @@ sol[’primal objective’]
    +

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

    @@ -268,6 +229,7 @@ sol[’primal objective’]

  • 28
  • 29
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/._week46-bs029.html b/doc/pub/week46/html/._week46-bs029.html index f1bde7d95..d96da2baf 100644 --- a/doc/pub/week46/html/._week46-bs029.html +++ b/doc/pub/week46/html/._week46-bs029.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -169,24 +174,88 @@ MathJax.Hub.Config({

     

     

     

    -

    Back to the more realistic cases

    +

    A simple example

    -

    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

    +

    We remind ourselves about the general problem we want to solve

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

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

    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

    -code will be added + +
    +
    +
    +
    +
    +
    # 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’]
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    @@ -203,6 +272,8 @@ With the slack constants this leads to the additional constraint \( 0\leq \lamb

  • 28
  • 29
  • 30
  • +
  • 31
  • +
  • »
  • diff --git a/doc/pub/week46/html/week46-bs.html b/doc/pub/week46/html/week46-bs.html index b621492c7..4a81a76eb 100644 --- a/doc/pub/week46/html/week46-bs.html +++ b/doc/pub/week46/html/week46-bs.html @@ -38,6 +38,10 @@ doconce format html week46.do.txt --html_style=bootstrap --pygments_html_style=d {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -131,33 +135,34 @@ MathJax.Hub.Config({ @@ -187,7 +192,7 @@ MathJax.Hub.Config({
    -

    Nov 18, 2021

    +

    Nov 19, 2021


    @@ -212,7 +217,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 30
  • +
  • 31
  • »
  • diff --git a/doc/pub/week46/html/week46-reveal.html b/doc/pub/week46/html/week46-reveal.html index f820f2d6e..755199425 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 18, 2021

    +

    Nov 19, 2021


    @@ -250,6 +250,19 @@ Feel free to suggest topics.

    The program will be available asap. It depends on input from you!

    +
    +

    Workshop plan Friday November 19 and the rest of the lecture

    + +
      +

    1. 1215-1225pm: Are Frode Helvi Kvanum, Gard Høivang, and David Andreas Bordvik, Next-day forecasts on spot rices 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 will use the second part of the lecture for further discussions of projects 2 and 3 and a summary on boosting methods from last week. Feel free to bring your laptops.

    +
    +

    Support Vector Machines, overarching aims

    diff --git a/doc/pub/week46/html/week46-solarized.html b/doc/pub/week46/html/week46-solarized.html index c4b0b93f1..0c2e8138c 100644 --- a/doc/pub/week46/html/week46-solarized.html +++ b/doc/pub/week46/html/week46-solarized.html @@ -65,6 +65,10 @@ div.toc p,a { {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -159,7 +163,7 @@ MathJax.Hub.Config({
    -

    Nov 18, 2021

    +

    Nov 19, 2021


    @@ -216,6 +220,17 @@ Feel free to suggest topics.

    The program will be available asap. It depends on input from you!

    +









    +

    Workshop plan Friday November 19 and the rest of the lecture

    + +
      +
    1. 1215-1225pm: Are Frode Helvi Kvanum, Gard Høivang, and David Andreas Bordvik, Next-day forecasts on spot rices 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 will use the second part of the lecture for further discussions of projects 2 and 3 and a summary on boosting methods from last week. Feel free to bring your laptops.

    +









    Support Vector Machines, overarching aims

    diff --git a/doc/pub/week46/html/week46.html b/doc/pub/week46/html/week46.html index d7954c871..9593779f1 100644 --- a/doc/pub/week46/html/week46.html +++ b/doc/pub/week46/html/week46.html @@ -142,6 +142,10 @@ div.toc p,a { {'highest level': 2, 'sections': [('Overview of week 46', 2, None, 'overview-of-week-46'), ('Friday', 2, None, 'friday'), + ('Workshop plan Friday November 19 and the rest of the lecture', + 2, + None, + 'workshop-plan-friday-november-19-and-the-rest-of-the-lecture'), ('Support Vector Machines, overarching aims', 2, None, @@ -236,7 +240,7 @@ MathJax.Hub.Config({
    -

    Nov 18, 2021

    +

    Nov 19, 2021


    @@ -293,6 +297,17 @@ Feel free to suggest topics.

    The program will be available asap. It depends on input from you!

    +









    +

    Workshop plan Friday November 19 and the rest of the lecture

    + +
      +
    1. 1215-1225pm: Are Frode Helvi Kvanum, Gard Høivang, and David Andreas Bordvik, Next-day forecasts on spot rices 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 will use the second part of the lecture for further discussions of projects 2 and 3 and a summary on boosting methods from last week. Feel free to bring your laptops.

    +









    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 86c979aca..05bb7be0b 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 9564f9739..874112e34 100644 --- a/doc/pub/week46/ipynb/week46.ipynb +++ b/doc/pub/week46/ipynb/week46.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "5e180fb2", + "id": "ba12855f", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "b8df090e", + "id": "d95034eb", "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 18, 2021**\n", + "Date: **Nov 19, 2021**\n", "\n", "Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license" ] }, { "cell_type": "markdown", - "id": "86bb649f", + "id": "6dd3c46c", "metadata": { "editable": true }, @@ -62,7 +62,7 @@ }, { "cell_type": "markdown", - "id": "63a68151", + "id": "95a9d45f", "metadata": { "editable": true }, @@ -95,7 +95,27 @@ }, { "cell_type": "markdown", - "id": "f82607f5", + "id": "e4c3ef94", + "metadata": { + "editable": true + }, + "source": [ + "## Workshop plan Friday November 19 and the rest of the lecture\n", + "\n", + "1. **1215-1225pm**: Are Frode Helvi Kvanum, Gard Høivang, and David Andreas Bordvik, *Next-day forecasts on spot rices 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 will use the second part of the lecture for further discussions of projects 2 and 3 and a summary on boosting methods from last week. Feel free to bring your laptops." + ] + }, + { + "cell_type": "markdown", + "id": "d0d5601a", "metadata": { "editable": true }, @@ -129,7 +149,7 @@ }, { "cell_type": "markdown", - "id": "50488f70", + "id": "473cc00f", "metadata": { "editable": true }, @@ -151,7 +171,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "22f8d961", + "id": "1456c2a2", "metadata": { "collapsed": false, "editable": true @@ -230,7 +250,7 @@ }, { "cell_type": "markdown", - "id": "3f2ac35e", + "id": "5b1ec14b", "metadata": { "editable": true }, @@ -250,7 +270,7 @@ }, { "cell_type": "markdown", - "id": "0ee21855", + "id": "917314e3", "metadata": { "editable": true }, @@ -262,7 +282,7 @@ }, { "cell_type": "markdown", - "id": "cb87dc6a", + "id": "1f413ec5", "metadata": { "editable": true }, @@ -275,7 +295,7 @@ }, { "cell_type": "markdown", - "id": "42a923f7", + "id": "d30045df", "metadata": { "editable": true }, @@ -287,7 +307,7 @@ }, { "cell_type": "markdown", - "id": "836850e0", + "id": "75b7d85e", "metadata": { "editable": true }, @@ -300,7 +320,7 @@ }, { "cell_type": "markdown", - "id": "39d217fb", + "id": "9eeedc16", "metadata": { "editable": true }, @@ -312,7 +332,7 @@ }, { "cell_type": "markdown", - "id": "e2aa9d98", + "id": "6d12084a", "metadata": { "editable": true }, @@ -324,7 +344,7 @@ }, { "cell_type": "markdown", - "id": "1de14111", + "id": "98f026cd", "metadata": { "editable": true }, @@ -336,7 +356,7 @@ }, { "cell_type": "markdown", - "id": "36226dfb", + "id": "e3c9acd2", "metadata": { "editable": true }, @@ -346,7 +366,7 @@ }, { "cell_type": "markdown", - "id": "433e2307", + "id": "ea60b346", "metadata": { "editable": true }, @@ -358,7 +378,7 @@ }, { "cell_type": "markdown", - "id": "3569dbd5", + "id": "c8691b35", "metadata": { "editable": true }, @@ -369,7 +389,7 @@ }, { "cell_type": "markdown", - "id": "a73c8190", + "id": "2f78e435", "metadata": { "editable": true }, @@ -381,7 +401,7 @@ }, { "cell_type": "markdown", - "id": "6920901b", + "id": "be415f92", "metadata": { "editable": true }, @@ -394,7 +414,7 @@ }, { "cell_type": "markdown", - "id": "25857f65", + "id": "4dc26e10", "metadata": { "editable": true }, @@ -406,7 +426,7 @@ }, { "cell_type": "markdown", - "id": "f53a2dbd", + "id": "721427f8", "metadata": { "editable": true }, @@ -416,7 +436,7 @@ }, { "cell_type": "markdown", - "id": "5d866f95", + "id": "18d4d4bd", "metadata": { "editable": true }, @@ -445,7 +465,7 @@ }, { "cell_type": "markdown", - "id": "5fb24b07", + "id": "d2ec7c2b", "metadata": { "editable": true }, @@ -457,7 +477,7 @@ }, { "cell_type": "markdown", - "id": "99dea25a", + "id": "ea41141d", "metadata": { "editable": true }, @@ -469,7 +489,7 @@ }, { "cell_type": "markdown", - "id": "eb112fd9", + "id": "97539849", "metadata": { "editable": true }, @@ -483,7 +503,7 @@ }, { "cell_type": "markdown", - "id": "07a227df", + "id": "9acfe069", "metadata": { "editable": true }, @@ -495,7 +515,7 @@ }, { "cell_type": "markdown", - "id": "fdf3b149", + "id": "0c4aa5d5", "metadata": { "editable": true }, @@ -509,7 +529,7 @@ }, { "cell_type": "markdown", - "id": "0446dee0", + "id": "da67bb02", "metadata": { "editable": true }, @@ -521,7 +541,7 @@ }, { "cell_type": "markdown", - "id": "82f241ae", + "id": "95be54d3", "metadata": { "editable": true }, @@ -531,7 +551,7 @@ }, { "cell_type": "markdown", - "id": "16c50031", + "id": "be28caa3", "metadata": { "editable": true }, @@ -543,7 +563,7 @@ }, { "cell_type": "markdown", - "id": "e9ba2e51", + "id": "d5232dc5", "metadata": { "editable": true }, @@ -553,7 +573,7 @@ }, { "cell_type": "markdown", - "id": "9512ea20", + "id": "08fe258a", "metadata": { "editable": true }, @@ -565,7 +585,7 @@ }, { "cell_type": "markdown", - "id": "a1bdde86", + "id": "2a29004a", "metadata": { "editable": true }, @@ -577,7 +597,7 @@ }, { "cell_type": "markdown", - "id": "1d0c3722", + "id": "140fc794", "metadata": { "editable": true }, @@ -589,7 +609,7 @@ }, { "cell_type": "markdown", - "id": "eda75f5a", + "id": "5e7a4dcc", "metadata": { "editable": true }, @@ -599,7 +619,7 @@ }, { "cell_type": "markdown", - "id": "4e693536", + "id": "f8dac7b9", "metadata": { "editable": true }, @@ -611,7 +631,7 @@ }, { "cell_type": "markdown", - "id": "0433d31b", + "id": "5eb0e75f", "metadata": { "editable": true }, @@ -621,7 +641,7 @@ }, { "cell_type": "markdown", - "id": "065f7913", + "id": "d451bb41", "metadata": { "editable": true }, @@ -635,7 +655,7 @@ }, { "cell_type": "markdown", - "id": "b2ae3a68", + "id": "91d5c9d8", "metadata": { "editable": true }, @@ -654,7 +674,7 @@ }, { "cell_type": "markdown", - "id": "91652ccb", + "id": "6af90642", "metadata": { "editable": true }, @@ -670,7 +690,7 @@ }, { "cell_type": "markdown", - "id": "332636ca", + "id": "52bf2d58", "metadata": { "editable": true }, @@ -682,7 +702,7 @@ }, { "cell_type": "markdown", - "id": "1a9686ac", + "id": "4b0cc537", "metadata": { "editable": true }, @@ -694,7 +714,7 @@ }, { "cell_type": "markdown", - "id": "0bf1f7f9", + "id": "74f85a66", "metadata": { "editable": true }, @@ -706,7 +726,7 @@ }, { "cell_type": "markdown", - "id": "0ab92ae0", + "id": "561237a3", "metadata": { "editable": true }, @@ -716,7 +736,7 @@ }, { "cell_type": "markdown", - "id": "ee044f72", + "id": "7848773a", "metadata": { "editable": true }, @@ -728,7 +748,7 @@ }, { "cell_type": "markdown", - "id": "97dca9e6", + "id": "1876845d", "metadata": { "editable": true }, @@ -739,7 +759,7 @@ }, { "cell_type": "markdown", - "id": "4cf82fab", + "id": "655f1ca1", "metadata": { "editable": true }, @@ -751,7 +771,7 @@ }, { "cell_type": "markdown", - "id": "5930fcc8", + "id": "2d09412e", "metadata": { "editable": true }, @@ -764,7 +784,7 @@ }, { "cell_type": "markdown", - "id": "150a5681", + "id": "069f3068", "metadata": { "editable": true }, @@ -777,7 +797,7 @@ }, { "cell_type": "markdown", - "id": "b8092387", + "id": "59c4222e", "metadata": { "editable": true }, @@ -789,7 +809,7 @@ }, { "cell_type": "markdown", - "id": "02ef2564", + "id": "b75ddb17", "metadata": { "editable": true }, @@ -799,7 +819,7 @@ }, { "cell_type": "markdown", - "id": "30043986", + "id": "d770dadd", "metadata": { "editable": true }, @@ -811,7 +831,7 @@ }, { "cell_type": "markdown", - "id": "6c1772c6", + "id": "9544cc5e", "metadata": { "editable": true }, @@ -821,7 +841,7 @@ }, { "cell_type": "markdown", - "id": "b28b521a", + "id": "232c4512", "metadata": { "editable": true }, @@ -833,7 +853,7 @@ }, { "cell_type": "markdown", - "id": "cab8716f", + "id": "791aca71", "metadata": { "editable": true }, @@ -850,7 +870,7 @@ }, { "cell_type": "markdown", - "id": "94bc6d2b", + "id": "18953d92", "metadata": { "editable": true }, @@ -862,7 +882,7 @@ }, { "cell_type": "markdown", - "id": "a1b45ad1", + "id": "96e21785", "metadata": { "editable": true }, @@ -872,7 +892,7 @@ }, { "cell_type": "markdown", - "id": "aafd7fce", + "id": "e5446b41", "metadata": { "editable": true }, @@ -884,7 +904,7 @@ }, { "cell_type": "markdown", - "id": "4c397307", + "id": "0cd01fde", "metadata": { "editable": true }, @@ -894,7 +914,7 @@ }, { "cell_type": "markdown", - "id": "dab5b44d", + "id": "c3c48304", "metadata": { "editable": true }, @@ -906,7 +926,7 @@ }, { "cell_type": "markdown", - "id": "8ea9458b", + "id": "79a2bd7d", "metadata": { "editable": true }, @@ -919,7 +939,7 @@ }, { "cell_type": "markdown", - "id": "07eed0d6", + "id": "e8d6cee4", "metadata": { "editable": true }, @@ -931,7 +951,7 @@ }, { "cell_type": "markdown", - "id": "e9846e25", + "id": "e5d5253b", "metadata": { "editable": true }, @@ -943,7 +963,7 @@ }, { "cell_type": "markdown", - "id": "1f8d0762", + "id": "cbe0d4c5", "metadata": { "editable": true }, @@ -953,7 +973,7 @@ }, { "cell_type": "markdown", - "id": "638e1e3b", + "id": "ec403623", "metadata": { "editable": true }, @@ -967,7 +987,7 @@ }, { "cell_type": "markdown", - "id": "de3b57f5", + "id": "5980fff4", "metadata": { "editable": true }, @@ -977,7 +997,7 @@ }, { "cell_type": "markdown", - "id": "04c4d3fb", + "id": "a0c9d0aa", "metadata": { "editable": true }, @@ -989,7 +1009,7 @@ }, { "cell_type": "markdown", - "id": "8026bbf8", + "id": "9aaa1ffb", "metadata": { "editable": true }, @@ -999,7 +1019,7 @@ }, { "cell_type": "markdown", - "id": "1d67c743", + "id": "ec746700", "metadata": { "editable": true }, @@ -1011,7 +1031,7 @@ }, { "cell_type": "markdown", - "id": "2996fa80", + "id": "c87c8e17", "metadata": { "editable": true }, @@ -1021,7 +1041,7 @@ }, { "cell_type": "markdown", - "id": "1bfa7e92", + "id": "9c4c06c3", "metadata": { "editable": true }, @@ -1033,7 +1053,7 @@ }, { "cell_type": "markdown", - "id": "153e0925", + "id": "ba3296ae", "metadata": { "editable": true }, @@ -1047,7 +1067,7 @@ }, { "cell_type": "markdown", - "id": "dcdb4617", + "id": "4acca659", "metadata": { "editable": true }, @@ -1059,7 +1079,7 @@ }, { "cell_type": "markdown", - "id": "ba52a8d8", + "id": "06c2a382", "metadata": { "editable": true }, @@ -1070,7 +1090,7 @@ }, { "cell_type": "markdown", - "id": "f8682584", + "id": "22e3980c", "metadata": { "editable": true }, @@ -1082,7 +1102,7 @@ }, { "cell_type": "markdown", - "id": "ade4c061", + "id": "af2fc1c2", "metadata": { "editable": true }, @@ -1094,7 +1114,7 @@ }, { "cell_type": "markdown", - "id": "64071f7a", + "id": "ecde773e", "metadata": { "editable": true }, @@ -1106,7 +1126,7 @@ }, { "cell_type": "markdown", - "id": "3e84e24a", + "id": "96add88f", "metadata": { "editable": true }, @@ -1116,7 +1136,7 @@ }, { "cell_type": "markdown", - "id": "21a88417", + "id": "2f259eb7", "metadata": { "editable": true }, @@ -1128,7 +1148,7 @@ }, { "cell_type": "markdown", - "id": "843fb235", + "id": "970df203", "metadata": { "editable": true }, @@ -1138,7 +1158,7 @@ }, { "cell_type": "markdown", - "id": "cb37404f", + "id": "57f5674f", "metadata": { "editable": true }, @@ -1150,7 +1170,7 @@ }, { "cell_type": "markdown", - "id": "ef7fc3d3", + "id": "0bb168a7", "metadata": { "editable": true }, @@ -1161,7 +1181,7 @@ }, { "cell_type": "markdown", - "id": "907cc142", + "id": "dcd1084e", "metadata": { "editable": true }, @@ -1173,7 +1193,7 @@ }, { "cell_type": "markdown", - "id": "79de1570", + "id": "343478d8", "metadata": { "editable": true }, @@ -1187,7 +1207,7 @@ }, { "cell_type": "markdown", - "id": "4fd01507", + "id": "1df5ab11", "metadata": { "editable": true }, @@ -1199,7 +1219,7 @@ }, { "cell_type": "markdown", - "id": "0fa4842b", + "id": "10c02649", "metadata": { "editable": true }, @@ -1211,7 +1231,7 @@ }, { "cell_type": "markdown", - "id": "956828c4", + "id": "63af1180", "metadata": { "editable": true }, @@ -1221,7 +1241,7 @@ }, { "cell_type": "markdown", - "id": "45b5f3f4", + "id": "f152a108", "metadata": { "editable": true }, @@ -1238,7 +1258,7 @@ }, { "cell_type": "markdown", - "id": "1aae27d3", + "id": "9e6303f1", "metadata": { "editable": true }, @@ -1249,7 +1269,7 @@ }, { "cell_type": "markdown", - "id": "c35ccbfe", + "id": "9e4de9fc", "metadata": { "editable": true }, @@ -1262,7 +1282,7 @@ }, { "cell_type": "markdown", - "id": "8102926a", + "id": "b5a81bcd", "metadata": { "editable": true }, @@ -1274,7 +1294,7 @@ }, { "cell_type": "markdown", - "id": "9531c58d", + "id": "c6181641", "metadata": { "editable": true }, @@ -1284,7 +1304,7 @@ }, { "cell_type": "markdown", - "id": "149770da", + "id": "c7ff3bd0", "metadata": { "editable": true }, @@ -1296,7 +1316,7 @@ }, { "cell_type": "markdown", - "id": "84d47498", + "id": "8a14310b", "metadata": { "editable": true }, @@ -1306,7 +1326,7 @@ }, { "cell_type": "markdown", - "id": "d53f76f8", + "id": "5287c73f", "metadata": { "editable": true }, @@ -1318,7 +1338,7 @@ }, { "cell_type": "markdown", - "id": "e2ab6efe", + "id": "de0473b5", "metadata": { "editable": true }, @@ -1328,7 +1348,7 @@ }, { "cell_type": "markdown", - "id": "6ad24a67", + "id": "6026b4dc", "metadata": { "editable": true }, @@ -1340,7 +1360,7 @@ }, { "cell_type": "markdown", - "id": "70b45b25", + "id": "eed9cb28", "metadata": { "editable": true }, @@ -1350,7 +1370,7 @@ }, { "cell_type": "markdown", - "id": "7d95e3c0", + "id": "2e676afb", "metadata": { "editable": true }, @@ -1362,7 +1382,7 @@ }, { "cell_type": "markdown", - "id": "d0c46a29", + "id": "1c00a03f", "metadata": { "editable": true }, @@ -1372,7 +1392,7 @@ }, { "cell_type": "markdown", - "id": "6a1aeefa", + "id": "d717b367", "metadata": { "editable": true }, @@ -1392,7 +1412,7 @@ }, { "cell_type": "markdown", - "id": "7b8f796b", + "id": "670ef916", "metadata": { "editable": true }, @@ -1404,7 +1424,7 @@ }, { "cell_type": "markdown", - "id": "01e07da8", + "id": "b318c5eb", "metadata": { "editable": true }, @@ -1414,7 +1434,7 @@ }, { "cell_type": "markdown", - "id": "4c953ca6", + "id": "9e4a7f5d", "metadata": { "editable": true }, @@ -1426,7 +1446,7 @@ }, { "cell_type": "markdown", - "id": "6d44c36a", + "id": "414c44fd", "metadata": { "editable": true }, @@ -1442,7 +1462,7 @@ }, { "cell_type": "markdown", - "id": "807912de", + "id": "d09ddc43", "metadata": { "editable": true }, @@ -1454,7 +1474,7 @@ }, { "cell_type": "markdown", - "id": "44677d9e", + "id": "caed9f37", "metadata": { "editable": true }, @@ -1466,7 +1486,7 @@ }, { "cell_type": "markdown", - "id": "74e3c377", + "id": "c3fa5975", "metadata": { "editable": true }, @@ -1476,7 +1496,7 @@ }, { "cell_type": "markdown", - "id": "10c08bb7", + "id": "a9362dc0", "metadata": { "editable": true }, @@ -1488,7 +1508,7 @@ }, { "cell_type": "markdown", - "id": "642412e8", + "id": "2e2258ab", "metadata": { "editable": true }, @@ -1500,7 +1520,7 @@ }, { "cell_type": "markdown", - "id": "fbe76228", + "id": "dc658b9d", "metadata": { "editable": true }, @@ -1512,7 +1532,7 @@ }, { "cell_type": "markdown", - "id": "28812fec", + "id": "329896d4", "metadata": { "editable": true }, @@ -1522,7 +1542,7 @@ }, { "cell_type": "markdown", - "id": "64adb24c", + "id": "0998d65f", "metadata": { "editable": true }, @@ -1534,7 +1554,7 @@ }, { "cell_type": "markdown", - "id": "7986598c", + "id": "26600566", "metadata": { "editable": true }, @@ -1544,7 +1564,7 @@ }, { "cell_type": "markdown", - "id": "8e9a9b82", + "id": "47d388e2", "metadata": { "editable": true }, @@ -1556,7 +1576,7 @@ }, { "cell_type": "markdown", - "id": "6805aef1", + "id": "f5bf6759", "metadata": { "editable": true }, @@ -1566,7 +1586,7 @@ }, { "cell_type": "markdown", - "id": "68bab981", + "id": "5152e7d3", "metadata": { "editable": true }, @@ -1578,7 +1598,7 @@ }, { "cell_type": "markdown", - "id": "17ca17e2", + "id": "07b4cc68", "metadata": { "editable": true }, @@ -1589,7 +1609,7 @@ }, { "cell_type": "markdown", - "id": "3780e5a0", + "id": "7ec03b1d", "metadata": { "editable": true }, @@ -1601,7 +1621,7 @@ }, { "cell_type": "markdown", - "id": "35dc261b", + "id": "431c8a56", "metadata": { "editable": true }, @@ -1613,7 +1633,7 @@ }, { "cell_type": "markdown", - "id": "f71b5f72", + "id": "2772ef0c", "metadata": { "editable": true }, @@ -1623,7 +1643,7 @@ }, { "cell_type": "markdown", - "id": "e23b9fd0", + "id": "7fbb48a3", "metadata": { "editable": true }, @@ -1635,7 +1655,7 @@ }, { "cell_type": "markdown", - "id": "c609b250", + "id": "3a8c2319", "metadata": { "editable": true }, @@ -1661,7 +1681,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "f8a9b194", + "id": "8999fd9e", "metadata": { "collapsed": false, "editable": true @@ -1718,7 +1738,7 @@ }, { "cell_type": "markdown", - "id": "d31e8847", + "id": "50f4725b", "metadata": { "editable": true }, @@ -1730,7 +1750,7 @@ }, { "cell_type": "markdown", - "id": "762bdffe", + "id": "108dc81e", "metadata": { "editable": true }, @@ -1742,7 +1762,7 @@ }, { "cell_type": "markdown", - "id": "8cb744be", + "id": "60f9f7fa", "metadata": { "editable": true }, @@ -1752,7 +1772,7 @@ }, { "cell_type": "markdown", - "id": "923b8474", + "id": "8f089e4b", "metadata": { "editable": true }, @@ -1764,7 +1784,7 @@ }, { "cell_type": "markdown", - "id": "183f183f", + "id": "534dbe43", "metadata": { "editable": true }, @@ -1774,7 +1794,7 @@ }, { "cell_type": "markdown", - "id": "64a25a6c", + "id": "aa42d9c2", "metadata": { "editable": true }, @@ -1786,7 +1806,7 @@ }, { "cell_type": "markdown", - "id": "efc81707", + "id": "47d26a70", "metadata": { "editable": true }, @@ -1797,7 +1817,7 @@ }, { "cell_type": "markdown", - "id": "88a7caec", + "id": "fd770709", "metadata": { "editable": true }, @@ -1809,7 +1829,7 @@ }, { "cell_type": "markdown", - "id": "7b888dd3", + "id": "e5b70290", "metadata": { "editable": true }, @@ -1819,7 +1839,7 @@ }, { "cell_type": "markdown", - "id": "1484846f", + "id": "aad6e7dc", "metadata": { "editable": true }, @@ -1831,7 +1851,7 @@ }, { "cell_type": "markdown", - "id": "e17bdbca", + "id": "d8d98cc7", "metadata": { "editable": true }, @@ -1849,7 +1869,7 @@ }, { "cell_type": "markdown", - "id": "fe78206c", + "id": "14e3b75a", "metadata": { "editable": true }, @@ -1860,7 +1880,7 @@ }, { "cell_type": "markdown", - "id": "382fc08d", + "id": "4c8e774f", "metadata": { "editable": true }, @@ -1872,7 +1892,7 @@ }, { "cell_type": "markdown", - "id": "107fdb86", + "id": "5eb13f8b", "metadata": { "editable": true }, @@ -1882,7 +1902,7 @@ }, { "cell_type": "markdown", - "id": "44343ee4", + "id": "b613cdad", "metadata": { "editable": true }, @@ -1899,7 +1919,7 @@ }, { "cell_type": "markdown", - "id": "cde93dcb", + "id": "b0a0b186", "metadata": { "editable": true }, @@ -1913,7 +1933,7 @@ }, { "cell_type": "markdown", - "id": "00488361", + "id": "1463ba85", "metadata": { "editable": true }, @@ -1928,7 +1948,7 @@ }, { "cell_type": "markdown", - "id": "861e1a20", + "id": "afe4614f", "metadata": { "editable": true }, @@ -1940,7 +1960,7 @@ }, { "cell_type": "markdown", - "id": "3298a424", + "id": "eed8484a", "metadata": { "editable": true }, @@ -1968,7 +1988,7 @@ }, { "cell_type": "markdown", - "id": "21f044c9", + "id": "60235fbb", "metadata": { "editable": true }, @@ -1980,7 +2000,7 @@ }, { "cell_type": "markdown", - "id": "03a9db26", + "id": "4f7e1c55", "metadata": { "editable": true }, @@ -1995,7 +2015,7 @@ }, { "cell_type": "markdown", - "id": "a50c811d", + "id": "1e94c682", "metadata": { "editable": true }, @@ -2006,7 +2026,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "a9dc9e06", + "id": "1a67d085", "metadata": { "collapsed": false, "editable": true @@ -2205,7 +2225,7 @@ }, { "cell_type": "markdown", - "id": "9811be6e", + "id": "67a258c0", "metadata": { "editable": true }, @@ -2217,7 +2237,7 @@ }, { "cell_type": "markdown", - "id": "1887e66e", + "id": "e82ecb1d", "metadata": { "editable": true }, @@ -2232,7 +2252,7 @@ }, { "cell_type": "markdown", - "id": "3a18e198", + "id": "9d428fd1", "metadata": { "editable": true }, @@ -2249,7 +2269,7 @@ }, { "cell_type": "markdown", - "id": "76033b03", + "id": "5f032a02", "metadata": { "editable": true }, @@ -2270,7 +2290,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "c1082b7d", + "id": "8493ddf9", "metadata": { "collapsed": false, "editable": true @@ -2283,7 +2303,7 @@ }, { "cell_type": "markdown", - "id": "9e9f0e95", + "id": "e145e8bc", "metadata": { "editable": true }, @@ -2293,7 +2313,7 @@ }, { "cell_type": "markdown", - "id": "2113c42e", + "id": "baf5ff44", "metadata": { "editable": true }, @@ -2305,7 +2325,7 @@ }, { "cell_type": "markdown", - "id": "c9d73a70", + "id": "8398d4b3", "metadata": { "editable": true }, @@ -2320,7 +2340,7 @@ }, { "cell_type": "markdown", - "id": "77b65ff4", + "id": "76dc50f5", "metadata": { "editable": true }, @@ -2330,7 +2350,7 @@ }, { "cell_type": "markdown", - "id": "c6897c48", + "id": "c887952a", "metadata": { "editable": true }, @@ -2349,7 +2369,7 @@ }, { "cell_type": "markdown", - "id": "41bec713", + "id": "fcabf4ba", "metadata": { "editable": true }, @@ -2359,7 +2379,7 @@ }, { "cell_type": "markdown", - "id": "12f6feca", + "id": "79cd904c", "metadata": { "editable": true }, @@ -2371,7 +2391,7 @@ }, { "cell_type": "markdown", - "id": "7feb8ac0", + "id": "eccfc34b", "metadata": { "editable": true }, @@ -2381,7 +2401,7 @@ }, { "cell_type": "markdown", - "id": "974ad9b0", + "id": "80154ec4", "metadata": { "editable": true }, @@ -2393,7 +2413,7 @@ }, { "cell_type": "markdown", - "id": "08798f80", + "id": "93cb1764", "metadata": { "editable": true }, @@ -2403,7 +2423,7 @@ }, { "cell_type": "markdown", - "id": "8f1f8420", + "id": "8bd48d72", "metadata": { "editable": true }, @@ -2415,7 +2435,7 @@ }, { "cell_type": "markdown", - "id": "0cf355cc", + "id": "68a9fdbd", "metadata": { "editable": true }, @@ -2426,7 +2446,7 @@ }, { "cell_type": "markdown", - "id": "93b14b87", + "id": "29f9a1ef", "metadata": { "editable": true }, @@ -2438,7 +2458,7 @@ }, { "cell_type": "markdown", - "id": "f7c7cc3f", + "id": "b8a11e5e", "metadata": { "editable": true }, @@ -2450,7 +2470,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "4644f01a", + "id": "8832d28a", "metadata": { "collapsed": false, "editable": true @@ -2474,7 +2494,7 @@ }, { "cell_type": "markdown", - "id": "983ebeff", + "id": "efaffb40", "metadata": { "editable": true }, @@ -2486,7 +2506,7 @@ }, { "cell_type": "markdown", - "id": "84b3fe0a", + "id": "6fbb53cc", "metadata": { "editable": true }, @@ -2503,7 +2523,7 @@ }, { "cell_type": "markdown", - "id": "d78ae146", + "id": "f0c2465c", "metadata": { "editable": true }, diff --git a/doc/src/week46/week46.do.txt b/doc/src/week46/week46.do.txt index fdea8cb9d..229498c63 100644 --- a/doc/src/week46/week46.do.txt +++ b/doc/src/week46/week46.do.txt @@ -44,8 +44,15 @@ Feel free to suggest topics. The program will be available asap. It depends on input from you! +!split +===== Workshop plan Friday November 19 and the rest of the lecture ===== +o _1215-1225pm_: Are Frode Helvi Kvanum, Gard Høivang, and David Andreas Bordvik, *Next-day forecasts on spot rices 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 will use the second part of the lecture for further discussions of projects 2 and 3 and a summary on boosting methods from last week. Feel free to bring your laptops.