:mod:`simplex` --- Simplex Search Algorithms ============================================ .. automodule:: dfoalgos.simplex .. autoclass:: dfoalgos.simplex.SimplexSearch :special-members: __init__ :private-members: :members: .. autoclass:: dfoalgos.simplex.SpendleySimplexSearch :special-members: __init__ :private-members: :members: .. autoclass:: dfoalgos.simplex.NelderMeadSimplexSearch :special-members: __init__ :members: .. autoclass:: dfoalgos.simplex.NMKSimplexSearch :special-members: __init__ :members: Usage Example ------------- The easiest way to use the optimization algorithms is via the :func:`minimize` classmethod that mimics the interface of SciPy optimizers. .. code:: python from dfoalgos.simplex import NelderMeadSimplexSearch def sphere(phenome): return sum(x * x for x in phenome) result = NelderMeadSimplexSearch.minimize(sphere, [1.333, 1.999]) Additional keyword arguments will be passed to the constructor of the algorithm. If bounds are provided (recommended), the search space is normalized internally and violations of the bound constraints are repaired automatically by reflection. .. code:: python result = NelderMeadSimplexSearch.minimize(sphere, [1.333, 1.999], xtol=1e-4, bounds=[(-1.5, 1.5), (-1.5, 1.5)]) Full control over the setup can be obtained by using the internal API: .. code:: python from optproblems import Problem, ScalingPreprocessor, BoundConstraintsRepair from dfoalgos.base import create_tilted_regular_simplex from dfoalgos.simplex import NelderMeadSimplexSearch def sphere(phenome): return sum(x * x for x in phenome) x0 = [1.333, 1.999] dim = 2 min_bounds = [-1.5, -1.5] max_bounds = [1.5, 1.5] unit_cube = ([0.0] * dim, [1.0] * dim) scale_to_orig = ScalingPreprocessor(from_cuboid=unit_cube, to_cuboid=(min_bounds, max_bounds)) scale_to_unit = ScalingPreprocessor(from_cuboid=(min_bounds, max_bounds), to_cuboid=unit_cube) repair = BoundConstraintsRepair((min_bounds, max_bounds), ["reflection"] * dim, previous_preprocessor=scale_to_orig) problem = Problem(sphere, phenome_preprocessor=repair) initial_simplex = create_tilted_regular_simplex(scale_to_unit(x0), size_param=1.0) algo = NelderMeadSimplexSearch(problem, initial_simplex) best_individual = algo.run() best_individual = min(algo.simplex, key=algo.sort_key) # alternatively print(algo.last_termination) print(best_individual.objective_values) print(problem.consumed_evaluations) print(algo.iteration)