optim_maximize

optim_maximize(
    objective,
    lower=None,
    upper=None,
    initial=None,
    method='de',
    seed=None,
    control=None,
    gradient=None,
    constraints=None,
    inner=None,
)

Maximize a user-written objective. See :func:optim_minimize for the arguments.

Every method is accepted except "augmented_lagrange", which can only minimize: the upstream C# class always drives its inner optimizer through Minimize() over an augmented Lagrangian built from the raw objective, so a maximize request would flip the reported sign without flipping the search direction and hand back the constrained minimum. Negate the objective and call :func:optim_minimize instead – minimizing -f subject to the same constraints is exactly maximizing f.

Examples

>>> from corehydropy import optim_maximize
>>> def peak(p):
...     return -((p[0] - 2) ** 2 + (p[1] + 1) ** 2)
>>> fit = optim_maximize(peak, lower=[-10, -10], upper=[10, 10], seed=7)
>>> import numpy as np
>>> np.round(fit.parameters, 3)
array([ 2., -1.])