File: l1svc.py

package info (click to toggle)
cvxopt 1.1.9%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,652 kB
  • sloc: ansic: 22,447; python: 11,344; makefile: 75
file content (17 lines) | stat: -rwxr-xr-x 490 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# The 1-norm support vector classifier of section 10.5 (Examples).

from cvxopt import normal, setseed
from cvxopt.modeling import variable, op, max, sum
from cvxopt.blas import nrm2

m, n = 500, 100
A = normal(m,n) 

x = variable(A.size[1],'x')  
u = variable(A.size[0],'u')  
op(sum(abs(x)) + sum(u), [A*x >= 1-u, u >= 0]).solve()

x2 = variable(A.size[1],'x')  
op(sum(abs(x2)) + sum(max(0, 1 - A*x2))).solve() 

print("\nDifference between two solutions: %e" %nrm2(x.value - x2.value))