Introduction¶
To use optimatic, first define the function you want to optimise:
def f(x):
return (x - 2.4) ** 2
Some optimisation methods (e.g. gradient descent) optionally allow you to provide the derivative of your function:
def df(x):
return 2 * (x - 2.4)
Then import and initialise the optimiser you want to use, e.g.:
from optimatic.grad_desc import Optimiser
opt = Optimiser(f, df, np.array([6.0]))
All input values must be numpy arrays of the form [x, y, z, ...]
.
Now run either opt.step()
to run one step of the chosen optimisation
algorithm, or opt.optimise()
to run until or opt.precision
is
met. If the algorithm runs opt.steps
steps and still hasn’t converged,
a DidNotConvergeException()
will be raised.
See Optimiser()
for more details.