View Single Post
  #5  
Old 08-25-2012, 07:47 AM
tadworthington tadworthington is offline
Member
 
Join Date: Jun 2012
Location: Chicago, IL
Posts: 32
Default Re: Question about the constraints in Quadratic Programming

Quote:
Originally Posted by jiunjiunma@gmail.com View Post
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
You want to be careful what you give away in these forums...there is no *ANSWER* in the title of this post, so people who don't want too much information would not be happy seeing code posted here.
Reply With Quote