简体   繁体   中英

scipy.optimize.least_squares - limit number of jacobian evaluations

I am trying to use scipy.optimize.least_squares(fun= my_fun, jac=my_jac, max_nfev= 1000) with two callable functions: my_fun and my_jac

both fuctions: my_fun and my_jac, use an external software to evaluate their value, this task is much time consuming, therefore I prefer to control the number of evaluations for both

the trf method uses the my_fun function for evaluating if trust region is adequate and the my_jac function for determine both the cost function and the jacobian matrix

There is an input parameter max_nfev. does this parameter count only for the fun evaluations? does it consider also the jac evaluations?

moreover, in matlab there are two parameters for the lsqnonlin function, MaxIterations and MaxFunctionEvaluations. does it exist in scipy.optimize.least_squares?

Thanks Alon

According to the help of scipy.optimize.least_squares , max_nfev is the number of function evaluations before the program exits :

max_nfev : None or int, optional Maximum number of function evaluations before the termination. If None (default), the value is chosen automatically:

Again, according to the help, there is no MaxIterations argument but you can define the tolerance in f ( ftol ) that is the function you want to minimize or x ( xtol ) the solution, before exiting the code.

You can also use scipy.optimize.minimize() . In it, you can define a maxiter argument which will be in the options dictionary. If you do so, beware that the function you want to minimize must be your cost function, meaning that you will have to code your least square function.

I hope it will be clear and useful to you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM