Skip to main content

Standard algorithms

Usage instructions

In order to use the standard algorithms with any of the problems written using the Problem() class, you should first import your problem from the corresponding file and also import the optimizer of your choice from the library. After that, set tolerances and other parameters for the chosen optimizer. Solve the problem and then print results.

An example is shown below for the SteepestDescent optimizer.


from my_problem import MyProblem

from modopt import SteepestDescent, Newton, QuasiNewton

tol = 1E-8
maxiter = 500

prob = MyProblem()

optimizer = SteepestDescent(prob,opt_tol=tol,maxiter=maxiter)
# optimizer = Newton(prob,opt_tol=tol,maxiter=maxiter)
# optimizer = QuasiNewton(prob,opt_tol=tol,maxiter=maxiter)

optimizer.check_first_derivatives(prob.x0)
optimizer.solve()
optimizer.print_results(summary_table=True)