From 9570bc4cbe8f40156283edb11665f1ffdea53d88 Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Tue, 6 Nov 2018 18:46:38 +0100 Subject: [PATCH] updating svm code --- doc/src/SupportVMachines/svm.do.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/doc/src/SupportVMachines/svm.do.txt b/doc/src/SupportVMachines/svm.do.txt index 17b9a8b0b..6619b4238 100644 --- a/doc/src/SupportVMachines/svm.do.txt +++ b/doc/src/SupportVMachines/svm.do.txt @@ -743,18 +743,12 @@ Finally, the vector $\bm{h}$ is defined as Since we don't have any equalities the matrix $\bm{A}$ is set to zero -The following code does this for us +The following code solves the equations for us !bc pycod # Import the necessary packages import numpy from cvxopt import matrix from cvxopt import solvers -# Define QP parameters (directly) -P = matrix([[1.0,0.0],[0.0,0.0]]) -q = matrix([3.0,4.0]) -G = matrix([[-1.0,0.0,-1.0,2.0,3.0],[0.0,-1.0,-3.0,5.0,4.0]]) -h = matrix([0.0,0.0,-15.0,100.0,80.0]) -# Define QP parameters (with NumPy) P = matrix(numpy.diag([1,0]), tc=’d’) q = matrix(numpy.array([3,4]), tc=’d’) G = matrix(numpy.array([[-1,0],[0,-1],[-1,-3],[2,5],[3,4]]), tc=’d’) @@ -773,7 +767,7 @@ We are now ready to return to our setup of the optmization problem for a more re !bt \[ \frac{1}{2} \bm{\lambda}^T\begin{bmatrix} y_1y_1K(\bm{x}_1,\bm{x}_1) & y_1y_2K(\bm{x}_1,\bm{x}_2) & \dots & \dots & y_1y_nK(\bm{x}_1,\bm{x}_n) \\ -y_2y_1\bm{x}_2^T\bm{x}_1 & y_2y_2\bm{x}_2^T\bm{x}_2 & \dots & \dots & y_1y_n\bm{x}_2^T\bm{x}_n \\ +y_2y_1K(\bm{x}_2,\bm{x}_1) & y_2y_2K(\bm{x}_2,\bm{x}_2) & \dots & \dots & y_1y_nK(\bm{x}_2,\bm{x}_n) \\ \dots & \dots & \dots & \dots & \dots \\ \dots & \dots & \dots & \dots & \dots \\ y_ny_1K(\bm{x}_n,\bm{x}_1) & y_ny_2K(\bm{x}_n\bm{x}_2) & \dots & \dots & y_ny_nK(\bm{x}_n,\bm{x}_n) \\