(self)
Optimizes the hyperparameters of all models that the acquisition function is based on.

        It is called automatically during initialization and each time :meth:`set_data` is called.
        When using the high-level :class:`..BayesianOptimizer` class calling :meth:`set_data` is taken care of.

        For each model the hyperparameters of the model at the time it was passed to __init__() are used as initial
        point and optimized. If optimize_restarts is set to >1, additional randomization
        steps are performed.

        As a special case, if optimize_restarts is set to zero, the hyperparameters of the models are not optimized.
        This is useful when the hyperparameters are sampled using MCMC.
Optimizes the hyperparameters of all models that the acquisition function is based on.
Optimizes the hyperparameters of all models that the acquisition function is based on .
def _optimize_models(self):
        """
        Optimizes the hyperparameters of all models that the acquisition function is based on.

        It is called automatically during initialization and each time :meth:`set_data` is called.
        When using the high-level :class:`..BayesianOptimizer` class calling :meth:`set_data` is taken care of.

        For each model the hyperparameters of the model at the time it was passed to __init__() are used as initial
        point and optimized. If optimize_restarts is set to >1, additional randomization
        steps are performed.

        As a special case, if optimize_restarts is set to zero, the hyperparameters of the models are not optimized.
        This is useful when the hyperparameters are sampled using MCMC.
        """
        if self.optimize_restarts == 0:
            return

        for model in self.models:
            runs = []
            for i in range(self.optimize_restarts):
                if i > 0:
                    model.randomize()
                try:
                    result = model.optimize()
                    runs.append(result)
                except tf.errors.InvalidArgumentError:  # pragma: no cover
                    print("Warning: optimization restart {0}/{1} failed".format(i + 1, self.optimize_restarts))
            if not runs:
                raise RuntimeError("All model hyperparameter optimization restarts failed, exiting.")
            best_idx = np.argmin([r.fun for r in runs])
            model.set_state(runs[best_idx].x)
def _optimize_models ( self ) : if self . optimize_restarts == 0 : return for model in self . models : runs = [ ] for i in range ( self . optimize_restarts ) : if i > 0 : model . randomize ( ) try : result = model . optimize ( ) runs . append ( result ) except tf . errors . InvalidArgumentError : # pragma: no cover print ( "Warning: optimization restart {0}/{1} failed" . format ( i + 1 , self . optimize_restarts ) ) if not runs : raise RuntimeError ( "All model hyperparameter optimization restarts failed, exiting." ) best_idx = np . argmin ( [ r . fun for r in runs ] ) model . set_state ( runs [ best_idx ] . x )