Esempio n. 1
0
    def test_minmax(self):
        # Zero-std case
        y = np.array([1])
        y_norm = normalize(y, 'maxmin')
        assert_allclose(y_norm, y - 1)

        y = np.array([0, 0, 0])
        y_norm = normalize(y + 1, 'maxmin')
        assert_allclose(y_norm, y)

        y = np.array([1, 3])[:, None]
        y_norm = normalize(y, 'maxmin')
        assert_allclose(y_norm, np.array([[0], [1]]))

        y = np.arange(5)
        y_norm = normalize(y - 1, 'maxmin')
        assert_allclose(y_norm, y / 4)
Esempio n. 2
0
    def test_minmax(self):
        # Zero-std case
        y = np.array([1])
        y_norm = normalize(y, 'maxmin')
        assert_allclose(y_norm, y - 1)

        y = np.array([0, 0, 0])
        y_norm = normalize(y + 1, 'maxmin')
        assert_allclose(y_norm, y)

        y = np.array([1, 3])[:, None]
        y_norm = normalize(y, 'maxmin')
        assert_allclose(y_norm, np.array([[-1], [1]]))

        y = np.arange(5)
        y_norm = normalize(y - 1, 'maxmin')
        assert_allclose(y_norm, (y - 2) / 2)
Esempio n. 3
0
    def test_std(self):
        """Test the std normalization."""
        # Zero-std case
        y = np.array([1])
        y_norm = normalize(y, 'stats')
        assert_allclose(y_norm, y - 1)

        y = np.array([0, 0, 0])
        y_norm = normalize(y + 1, 'stats')
        assert_allclose(y_norm, y)

        y = np.array([1, 3])[:, None]
        y_norm = normalize(y, 'stats')
        assert_allclose(y_norm, np.array([[-1], [1]]))

        y = np.arange(5)
        y_norm = normalize(y, 'stats')
        assert_allclose(y_norm, (y - y.mean()) / y.std())
Esempio n. 4
0
    def test_std(self):
        """Test the std normalization."""
        # Zero-std case
        y = np.array([1])
        y_norm = normalize(y, 'stats')
        assert_allclose(y_norm, y - 1)

        y = np.array([0, 0, 0])
        y_norm = normalize(y + 1, 'stats')
        assert_allclose(y_norm, y)

        y = np.array([1, 3])[:, None]
        y_norm = normalize(y, 'stats')
        assert_allclose(y_norm, np.array([[-1], [1]]))

        y = np.arange(5)
        y_norm = normalize(y, 'stats')
        assert_allclose(y_norm, (y - y.mean()) / y.std())
Esempio n. 5
0
    def _input_data(self, normalization_type):
        # input that goes into the model (is unziped in case there are categorical variables)
        X_inmodel = self.subspace.unzip_inputs(self.X)

        # Y_inmodel is the output that goes into the model
        if self.normalize_Y:
            Y_inmodel = normalize(self.Y, normalization_type)
        else:
            Y_inmodel = self.Y

        return X_inmodel, Y_inmodel
Esempio n. 6
0
def plot_acquisition(obj, d_opt, filename=None):

    # GPyOpt part: Interpolation
    bounds = obj.space.get_bounds()
    x_grid = np.linspace(bounds[0][0], bounds[0][1], 1000)
    x_grid = x_grid.reshape(len(x_grid), 1)
    AEI = AcquisitionEI(obj.model, obj.space)
    acqu = AEI._compute_acq(x_grid)
    acqu_normalized = (-acqu - min(-acqu)) / (max(-acqu - min(-acqu)))
    m, s = obj.model.predict(x_grid)

    fig = plt.figure(figsize=(10, 6))
    ax = fig.add_subplot(111)

    # Plot Model
    # Note that we have to flip the GPyOpt utility
    ax.plot(x_grid, -m, 'k-', lw=1, alpha=0.6)
    ax.plot(x_grid, -(m + np.sqrt(s)), 'k-', alpha=0.2)
    ax.plot(x_grid, -(m - np.sqrt(s)), 'k-', alpha=0.2)
    ax.fill_between(x_grid.reshape(-1),
                    -(m + np.sqrt(s)).reshape(-1),
                    -(m - np.sqrt(s)).reshape(-1),
                    color='steelblue',
                    alpha=0.5,
                    label=r'68\% C.L.')

    # Plot Evals
    X = obj.X
    Y = normalize(obj.Y)
    ax.plot(X, -1 * Y, 'r.', markersize=10, label='Bayes. Opt. Evaluations')

    # Plot optimum
    ax.axvline(d_opt, ls='--', c='g', label='Optimal Design')

    ax.set_xlabel(r'Design variable d')
    ax.set_ylabel(r'$U(d)$')
    ax.legend(loc='bottom right', prop={'size': 14})
    ax.grid(True, ls='--')
    # ax.set_title('Utility Function')
    # ax.tick_params(labelsize=25)

    plt.tight_layout()

    if filename:
        plt.savefig('{}.pdf'.format(filename))
        plt.savefig('{}.png'.format(filename))
    else:
        plt.savefig('./utility.pdf')
        plt.savefig('./utility.png')
Esempio n. 7
0
    def _update_model(self, normalization_type='stats'):
        """
        Updates the model (when more than one observation is available) and saves the parameters (if available).
        """
        if self.num_acquisitions % self.model_update_interval == 0:

            # input that goes into the model (is unziped in case there are categorical variables)
            X_inmodel = self.space.unzip_inputs(self.X)

            # Y_inmodel is the output that goes into the model
            if self.normalize_Y:
                Y_inmodel = normalize(self.Y, normalization_type)
            else:
                Y_inmodel = self.Y

            self.model.updateModel(X_inmodel, Y_inmodel, None, None)