View Single Post
  #3  
Old 08-24-2012, 01:39 PM
jiunjiunma@gmail.com jiunjiunma@gmail.com is offline
Junior Member
 
Join Date: Jul 2012
Posts: 8
Default Re: Question about the constraints in Quadratic Programming

I am also using CVXOPT and python and didn't encounter this problem. However, the result I got from the solver was totally wrong. It even gave me some negative alphas. I suspect I might have set some parameter wrong but couldn't find it after hours of debugging. Frustrated, I am posting my small routine to create the qp parameters here to see if extra pairs of eyes help:

Code:
def getDualQuardraticParameters(trainingData, trainingResults):
    n = len(trainingResults)
    quadraticCoefficients = []
    for i in range(n):
        for j in range(n):
            kernel = np.dot(trainingData[j], trainingData[i])
            yjyi = trainingResults[j]*trainingResults[i]
            quadraticCoefficients.append(yjyi * kernel)
    P = matrix(quadraticCoefficients, (n, n), tc='d')
    q = -1.0 * matrix(np.ones((n, 1)), tc='d')
    G = -1.0 * matrix(np.identity(n), tc='d')
    h = matrix(np.zeros((n, 1)), tc='d')
    A = matrix(trainingResults, (1,n), tc='d')
    b = matrix([0.0])

    return P, q, G, h, A, b
Reply With Quote