It is necessary to minimize the function depending on two variables using the Nelder-Mead algorithm. The documentation says ( link ) that you can specify xtol in the options of this function, but it is accepted as a float .
How to specify xtol for each of two variable variables, besides, that they have a different order? I tried to write the form 'xtol':[1,0.01] - swears. Code:

 import Residual_calc as res_c from scipy.optimize import minimize var_ar0=[25,1.0]; var_ar_min=minimize(res_c.x_extr_res,var_ar0,(),'Nelder-Mead',options={'disp':True,'maxiter':10}); 
  • The code for the 'Nelder-Mead' function does not allow using multiple values ​​for 'xtol'. As an option, write your function to minimize. Take the code from the scipy.optimize.optimize._minimize_neldermead function and add a check for several xtol values. - Avernial

1 answer 1

If the variables have a different order, it is necessary to make a linear change of variables so that the order is the same. Then one value of xtol is enough, and at the same time, the performance of the method is likely to improve.

I give an example of such a replacement. The function f has variables of different order; and this defect function scaledf corrects.

 from scipy.optimize import minimize def f(x): return 3**(x[0]**2) + 3**(1e-8*x[1]**2) def scaledf(x): return f([x[0], 1e4*x[1]]) res = minimize(f, [1,1], method='Nelder-Mead', options={'xtol': 1e-6}) print(res) res2 = minimize(scaledf, [1,1], method='Nelder-Mead', options={'xtol': 1e-6}) print(res2) 

Comparison of results (the real minimum in (0,0)):

 [ 8.64722640e-09, 1.65971984e-04] для f [-3.37014990e-07, -8.87487948e-08] для scaledf 

At the same time I will note what happens if you do not set the options:

 res = minimize(f, [1,1]) print(res) res2 = minimize(scaledf, [1,1]) print(res2) 

The result for f is no good; for scaledf is quite acceptable.

 [-1.10723146e-07, 9.99999971e-01] для f [-1.13095095e-07, -1.13095095e-07] для scaledf