Source code for naginterfaces.library.examples.opt.uncon_simplex_ex

#!/usr/bin/env python3
"``naginterfaces.library.opt.uncon_simplex`` Python Example."

# NAG Copyright 2017-2019.

# pylint: disable=invalid-name

from math import exp, sqrt

from naginterfaces.library import machine, opt

[docs]def main(): """ Example for :func:`naginterfaces.library.opt.uncon_simplex`. Unconstrained minimum, Nelder--Mead simplex algorithm. >>> main() naginterfaces.library.opt.uncon_simplex Python Example Results. Nelder--Mead simplex algorithm. The final function value is 0.0000 at the point x = (0.5000, -0.9999) """ print( 'naginterfaces.library.opt.uncon_simplex Python Example Results.' ) print('Nelder--Mead simplex algorithm.') # The initial guess: x = [-1.0, 1.] # The objective function: funct = lambda x: ( exp(x[0])*(4.*x[0]*(x[0] + x[1]) + 2.*x[1]*(x[1]+1.)+1.) ) # Other parameters for the optimizer: maxcal = 100 tolf = sqrt(machine.precision()) tolx = sqrt(tolf) soln = opt.uncon_simplex( x, tolf, tolx, funct, maxcal, ) print('The final function value is {:1.4f}'.format(soln.f)) print('at the point x = ({:1.4f}, {:1.4f})'.format(*soln.x))
if __name__ == '__main__': import doctest import sys sys.exit( doctest.testmod( None, verbose=True, report=False, optionflags=doctest.REPORT_NDIFF, ).failed )