def optimize(self, optimizer=None, start=None, messages=False, max_iters=<NUM_LIT:1000>, ipython_notebook=True, clear_after_finish=False, **kwargs):
self.inference_method.on_optimization_start()<EOL>try:<EOL><INDENT>ret = super(GP, self).optimize(optimizer, start, messages, max_iters, ipython_notebook, clear_after_finish, **kwargs)<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>print("<STR_LIT>")<EOL>self.inference_method.on_optimization_end()<EOL>raise<EOL><DEDENT>return ret<EOL>
Optimize the model using self.log_likelihood and self.log_likelihood_gradient, as well as self.priors.
kwargs are passed to the optimizer. They can be:

:param max_iters: maximum number of function evaluations
:type max_iters: int
:param messages: whether to display during optimisation
:type messages: bool
:param optimizer: which optimizer to use (defaults to self.preferred optimizer), a range of optimisers can be found in :module:`~GPy.inference.optimization`, they include 'scg', 'lbfgs', 'tnc'.
:type optimizer: string
:param bool ipython_notebook: whether to use ipython notebook widgets or not.
:param bool clear_after_finish: if in ipython notebook, we can clear the widgets after optimization.