Example #1
0
XX = concatenate([c1,-c2])
nx = XX.shape[0]

# quadratic and linear terms of QP
Q = KernelMatrix(XX)
b = -1 * ones(nx)

H = Q
f = b
Aeq = concatenate([ones(c1.shape[0]), -ones(c2.shape[0])]).reshape(1,nx)
Beq = array([0])
lb = zeros(nx)
ub = zeros(nx) + 100000

#alpha = qld.quadprog2(H, f, None, None, Aeq, Beq, lb, ub)
alpha,xxx = quapro.quadprog(H, f, None, None, Aeq, Beq, lb, ub)
#t1 = time.time()
#for i in range(1000):
#   alpha,xxx = quapro.quadprog(H, f, None, None, Aeq, Beq, lb, ub)
#   #alpha = qld.quadprog2(H, f, None, None, Aeq, Beq, lb, ub)
#t2 = time.time()
#print "1000 calls to QP took %0.3f s" % (t2-t1)
print alpha

# the labels and the points
X = concatenate([c1,c2])
y = concatenate([ones(c1.shape[0]), -ones(c2.shape[0])]).reshape(1,nx)

wv = WeightVector(alpha, X, y)
sv1, sv2 = SupportVectors(alpha,y, eps=1e-6)
bias = Bias(alpha, X, y)
Example #2
0
XX = concatenate([c1,-c2])
nx = XX.shape[0]

# quadratic and linear terms of QP
Q = KernelMatrix(XX)
b = -1 * ones(nx)

H = Q
f = b
Aeq = concatenate([ones(c1.shape[0]), -ones(c2.shape[0])]).reshape(1,nx)
Beq = array([0])
lb = zeros(nx)
ub = zeros(nx) + 99999

#alpha = qld.quadprog2(H, f, None, None, Aeq, Beq, lb, ub)
alpha, xxx= quapro.quadprog(H, f, None, None, Aeq=Aeq, beq=Beq, LB=lb, UB=ub)
print alpha
#alpha = array([fil(x) for x in alpha])
print "cons:", inner(Aeq,alpha)
print "obj min: 0.5 * x'Hx + <x,f>",  0.5*inner(alpha,inner(H,alpha))+inner(f,alpha)


# the labels and the points
X = concatenate([c1,c2])
y = concatenate([ones(c1.shape[0]), -ones(c2.shape[0])]).reshape(1,nx)

wv = WeightVector(alpha, X, y)
sv1, sv2 = SupportVectors(alpha,y,eps=1e-6)
bias = Bias(alpha, X, y)

ym = (y.flatten()<0).nonzero()[0]
Example #3
0
XX = concatenate([c1, -c2])
nx = XX.shape[0]

# quadratic and linear terms of QP
Q = KernelMatrix(XX)
b = -1 * ones(nx)

H = Q
f = b
Aeq = concatenate([ones(c1.shape[0]), -ones(c2.shape[0])]).reshape(1, nx)
Beq = array([0])
lb = zeros(nx)
ub = zeros(nx) + 100000

#alpha = qld.quadprog2(H, f, None, None, Aeq, Beq, lb, ub)
alpha, xxx = quapro.quadprog(H, f, None, None, Aeq, Beq, lb, ub)
#t1 = time.time()
#for i in range(1000):
#   alpha,xxx = quapro.quadprog(H, f, None, None, Aeq, Beq, lb, ub)
#   #alpha = qld.quadprog2(H, f, None, None, Aeq, Beq, lb, ub)
#t2 = time.time()
#print("1000 calls to QP took %0.3f s" % (t2-t1))
print(alpha)

# the labels and the points
X = concatenate([c1, c2])
y = concatenate([ones(c1.shape[0]), -ones(c2.shape[0])]).reshape(1, nx)

wv = WeightVector(alpha, X, y)
sv1, sv2 = SupportVectors(alpha, y, eps=1e-6)
bias = Bias(alpha, X, y)
Example #4
0
XX = concatenate([c1,-c2])
nx = XX.shape[0]

# quadratic and linear terms of QP
Q = KernelMatrix(XX)
b = -1 * ones(nx)

H = Q
f = b
Aeq = concatenate([ones(c1.shape[0]), -ones(c2.shape[0])]).reshape(1,nx)
Beq = array([0])
lb = zeros(nx)
ub = zeros(nx) + 99999

#alpha = qld.quadprog2(H, f, None, None, Aeq, Beq, lb, ub)
alpha, xxx= quapro.quadprog(H, f, None, None, Aeq=Aeq, beq=Beq, LB=lb, UB=ub)
print(alpha)
#alpha = array([fil(x) for x in alpha])
print("cons:%s" % inner(Aeq,alpha))
print("obj min: 0.5 * x'Hx + <x,f> %s" % 0.5*inner(alpha,inner(H,alpha))+inner(f,alpha))


# the labels and the points
X = concatenate([c1,c2])
y = concatenate([ones(c1.shape[0]), -ones(c2.shape[0])]).reshape(1,nx)

wv = WeightVector(alpha, X, y)
sv1, sv2 = SupportVectors(alpha,y,eps=1e-6)
bias = Bias(alpha, X, y)

ym = (y.flatten()<0).nonzero()[0]