TypeError in solver.cp

388 views
Skip to first unread message

Anil Raj

unread,
Apr 1, 2010, 11:09:44 AM4/1/10
to cvxopt
Hi all,
I'm implementing a general nonlinear convex optimization problem
(with a user-defined script that gives the function value, derivative
and Hessian). The problem has a highly nonlinear objective, but simple
inequality constraints. (I've attached the code at the end; however,
there are other functions/dependencies that I haven't included.)

I get the following error:

Traceback (most recent call last):
File "svm_dal.py", line 115, in <module>
l1svm_dal(fold,10.,cas,outdir)
File "svm_dal.py", line 54, in l1svm_dal
soln = solvers.cp(F,G,H)
File "/share/apps/python26/lib/python2.6/site-packages/cvxopt/cvxprog.py",
line 1964, in cp
xdot_e, xaxpy_e, xscal_e)
File "/share/apps/python26/lib/python2.6/site-packages/cvxopt/cvxprog.py",
line 676, in cpl
fDf(z[:mnl], rx, beta = 1.0, trans = 'T')
File "/share/apps/python26/lib/python2.6/site-packages/cvxopt/cvxprog.py",
line 1798, in Df_e
trans = 'T')
TypeError: length of x is too small

After briefly going through the code in cvxprog.py, I was unable to
find a plausible cause for this. Any thoughts on what I should be
looking for or how I could resolve this would be much appreciated!!

Thanks!
Cheers,
Anil


#####

import numpy as np
import cvxopt as C

# constraints
G = C.matrix([C.spdiag(C.matrix(1., (N,1))),
C.spdiag(C.matrix(-1., (N,1)))])
H = C.matrix([C.matrix(1., (N,1)), C.matrix(0., (N,1))])

# Defining nonlinear function
def F(x = None, z = None):
if x is None and z is None: return 0, C.matrix(beto)

# find 'active' variables
u = wo+eta*np.dot(Xy,x)
v = shrink(u,mu) # User-defined function
I = v.nonzero()[0]
vI = v[I]
XyI = Xy[I,:]
Yx = np.dot(Y.T,x)

f = C.matrix(-1.*np.sum(x)+bo*Yx +
0.5*eta*Yx**2 + 0.5/eta*np.dot(v.T,v))
Df = C.matrix(-1. + bo*Y + eta*Yx*Y + np.dot(vI.T,XyI))
if z is None: return f, Df.T

K = np.dot(XyI.T,XyI)
H = z[0]*eta*C.matrix(Y*Y.T+K)
return f,Df.T,H

# use cvxopt
soln = solvers.cp(F,G,H)

Anil Raj

unread,
Apr 1, 2010, 11:45:11 AM4/1/10
to cvxopt
Please ignore this query. I found the problem to be a bug in my function.

Thanks and sorry for the spam.
Best,
Anil

Laachir Ismail

unread,
Oct 1, 2013, 11:05:56 AM10/1/13
to cvx...@googlegroups.com
Hi,

I am facing the same problem as you.

Can you please explain the bug you found in your function.

Thank you for your help.

ymous

unread,
Mar 21, 2014, 2:36:51 PM3/21/14
to cvx...@googlegroups.com
I just experienced the same problem.  In my case, it was because I was returning the gradient, when I was supposed to return the transpose of the gradient.  Hope this helps.

Matthew Molloy

unread,
Aug 18, 2014, 5:23:49 AM8/18/14
to cvx...@googlegroups.com
I also overlooked this one, thanks for the pointer!
Reply all
Reply to author
Forward
0 new messages