0

I am having an issue with a section of code I am running. It's purpose is to find the vector that minimizes a function via scipy.opimize's minimize function with a constraint.

However, I keep getting thrown the following error

line 495, in minimize
constraints, callback=callback, **options) line 378, in _minimize_slsqp
fx = func(x), line 292, in function_wrapper
return function(*(wrapper_args + args), TypeError: 'numpy.ndarray' object is not callable

I am a little confused as to what I am doing wrong. The following code contains the function to be minimised and the constrain function.

def constraint1(w):
goal = 1
for i in range(w.shape[0]):
    goal - w[i]
return goal 
def lasso_var(w, *args):
var = w.T.dot(args[0]).dot(w)+args[1]*sum(abs(w))
return var

con1 = {'type': 'eq', 'fun': constraint1}

from scipy.optimize import minimize

sol = minimize(lasso_var(w, *(train_sig, 5)),\
            x0=w_equal,\
           constraints=con1) 

where w is a vector and train_sig is a matrix.

Many Thanks for any aid you can give.

1 Answer 1

1

You should pass the function itself to minimize, instead of a evaluated value.

Your code is not a minimal, complete and verifiable example. So I don't know exactly your intention. But just use like this:

sol = minimize(lambda w: lasso_var(w, *(train_sig, 5)),
        x0=w_equal,
       constraints=con1) 
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent. That worked exactly as I'd hoped. Thank you very much. Shame on me for trying to follow online examples so religiously I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.