Exemplo n.º 1
0
    def one_step_assesment(self, attribute=0, context=None):
        """
        """
        if self.objective is None:
            raise InvalidConfigError("Cannot run the optimization loop without the objective function")
        #self.model_parameters_iterations = None
        self.context = context
        # --- Initial function evaluation
        if self.X is not None and self.Y is None:
            self.Y, cost_values = self.objective.evaluate(self.X)
            if self.cost.cost_type == 'evaluation_time':
                self.cost.update_cost_model(self.X, cost_values)
            self._update_model()

        self.suggested_sample = self.compute_next_evaluations()

        model_to_plot = deepcopy(self.model)

        integrated_plot(self.acquisition.space.get_bounds(),
                                self.X.shape[1],
                                model_to_plot,
                                self.X,
                                self.Y,
                                self.acquisition.acquisition_function,
                                self.suggested_sample,
                                attribute,
                                None)

        self.X = np.vstack((self.X,self.suggested_sample))
        self.evaluate_objective()
        self._update_model()
        self.historical_optimal_values.append(self._current_max_value())
Exemplo n.º 2
0
    def one_step_assesment(self, attribute=0, context=None):
        """
        Runs the optimization process for one iteration and, for 1d and 2d input spaces, outputs plots of
        the acquisition function, highliting the selected point to evaluate, and of the posterior mean for each output.
        """
        if self.objective is None:
            raise InvalidConfigError(
                "Cannot run the optimization loop without the objective function"
            )
        #self.model_parameters_iterations = None
        self.context = context
        # --- Initial function evaluation
        if self.X is not None and self.Y is None:
            self.Y, cost_values = self.objective.evaluate(self.X)
            if self.cost.cost_type == 'evaluation_time':
                self.cost.update_cost_model(self.X, cost_values)
            self._update_model()

        self.suggested_sample = self._compute_next_evaluations()

        from copy import deepcopy
        model_to_plot = deepcopy(self.model)

        integrated_plot(self.acquisition.space.get_bounds(), self.X.shape[1],
                        model_to_plot, self.X, self.Y,
                        self.acquisition.acquisition_function,
                        self.suggested_sample, attribute, None)

        self.X = np.vstack((self.X, self.suggested_sample))
        self.evaluate_objective()
        self._update_model()
        self.optimal_values.append(self._current_max_value())
Exemplo n.º 3
0
    def convergence_assesment(self, n_iter=10, attribute=0, context=None):
        if self.objective is None:
            raise InvalidConfigError(
                "Cannot run the optimization loop without the objective function"
            )
        #self.model_parameters_iterations = None
        self.context = context
        # --- Initial function evaluation
        if self.X is not None and self.Y is None:
            self.Y, cost_values = self.objective.evaluate(self.X)
            if self.cost.cost_type == 'evaluation_time':
                self.cost.update_cost_model(self.X, cost_values)
            self._update_model()
        for i in range(n_iter):
            self.suggested_sample = self.compute_next_evaluations()
            filename = './experiments/1d' + str(i) + '.eps'
            model_to_plot = deepcopy(self.model)
            integrated_plot(self.acquisition.space.get_bounds(),
                            self.X.shape[1], model_to_plot, self.X, self.Y,
                            self.acquisition.acquisition_function,
                            self.suggested_sample, attribute, filename)

            self.X = np.vstack((self.X, self.suggested_sample))
            self.evaluate_objective()
            self._update_model()
            #self.model.get_model_parameters_names()
            #self.model.get_model_parameters()
            #print('Acquisition value at previously evaluated points:')
            #print(self.acquisition.acquisition_function(self.X))
            #print('Posterior mean and variance')
            #print(self.model.predict(self.X))
            #print(self.Y)
            self.historical_optimal_values.append(self._current_max_value())
Exemplo n.º 4
0
    def integrated_plot(self, attribute=0, filename=None):
        """
        Plots the model and the acquisition function.
            if self.input_dim = 1: Plots data, mean and variance in one plot and the acquisition function in another plot
            if self.input_dim = 2: as before but it separates the mean and variance of the model in two different plots
        :param filename: name of the file where the plot is saved
        """
        from copy import deepcopy
        model_to_plot = deepcopy(self.model)

        integrated_plot(self.acquisition.space.get_bounds(), self.X.shape[1],
                        model_to_plot, self.X, self.Y,
                        self.acquisition.acquisition_function,
                        self.suggest_next_locations(), attribute, filename)