0

I am using scipy=1.2.1, python=3.6, numpy=1.16.3, I have an object function defined like so.

def func(arg0,arg1=0,arg2='default'):
  print('Args for objective function:',arg0,arg1,arg2)
  .
  .
  .

Before I call my object function I define my x0 and args like so. Please note that arr is an arbitrary list.

# bounds are between (0,1) for all x
bounds = tuple([(0,1) for _ in range(len(arr))])
temp = [1/len(arr) for _ in range(len(arr))]
x0 = np.asarray(temp)
arg0 = np.array((n,m)) #the actual data is not relevant for this problem
#ensure the return values sum to 1
constraints = {'type' : 'eq', 'fun' : lambda x: 1 == sum(x)}

I then call minimize like so

return_value = minimize(fun=func, args=(arg0,), x0=x0, bounds=bounds,constraints=constraints) 

But when I run the code and look at the print statement in the entry point of func I see that the arguments passed to it are kind of messed up. The print statement gives the following-

Args for objective function: x0,arg0,arg2

Here x0 is the x0 passed to minimize arg0, and arg1 are the parameters in the order as described in the function definition. For simplicity I have only noted their variables names in the print statement to express the order in which they are passed to the objective function. Thoughts?

  • 2
    check the minimize docs, it expects/passes `func(x0, *args)`. It passes by position, not keyword. Review the examples. – hpaulj Sep 11 '22 at 00:57
  • Ok turns out args is unpacked and I need to make sure my function conforms with that singature, after reading the docs thats what I did and it works now. Thanks – the.lotuseater Sep 11 '22 at 03:11

0 Answers0