Ejemplo n.º 1
0
    def test_model_type(self):
        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         model_type='GP')
        self.assertTrue(isinstance(method.model, GPModel))

        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         model_type='sparseGP')
        self.assertTrue(isinstance(method.model, GPModel))

        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         model_type='GP_MCMC')
        self.assertTrue(isinstance(method.model, GPModel_MCMC))

        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         model_type='warpedGP')
        self.assertTrue(isinstance(method.model, WarpedGPModel))
Ejemplo n.º 2
0
    def test_initial_value(self):
        x = np.array([[0, 0, 0, 0, 0]])
        y = np.array([[1]])
        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         X=x,
                         Y=y)
        x_opt, y_opt = method.get_best_point()

        self.assertTrue(np.all(x[0] == x_opt))
        self.assertEqual(y[0][0], y_opt)
Ejemplo n.º 3
0
 def test_update_subspace(self):
     x = np.array([[0, 0, 0, 0, 0]])
     y = np.array([[1]])
     method = Dropout(f=self.f,
                      domain=self.domain,
                      subspace_dim_size=self.subspace_dim_size,
                      fill_in_strategy='random',
                      X=x,
                      Y=y)
     method.update_subspace()
     self.assertEqual(len(method.subspace_idx), self.subspace_dim_size)
     for i, idx in enumerate(method.subspace_idx):
         self.assertEqual(str(idx), method.subspace_domain[i]['name'])
Ejemplo n.º 4
0
 def test_update(self):
     x = np.array([[0, 0, 0, 0, 0]])
     y = np.array([[1]])
     method = Dropout(f=self.f,
                      domain=self.domain,
                      subspace_dim_size=self.subspace_dim_size,
                      fill_in_strategy='random',
                      X=x,
                      Y=y,
                      normalize_Y=False)
     method.update()
     self.assertEqual(1, len(method.X_inmodel))
     self.assertTrue(
         np.all(method.X_inmodel[0] == x[0][method.subspace_idx]))
     self.assertEqual(y[0][0], method.Y_inmodel)
Ejemplo n.º 5
0
    def test_acquisition_optimizer_type(self):
        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         acquisition_optimizer_type='lbfgs')
        self.assertEqual(method.acquisition_optimizer_type, 'lbfgs')

        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         acquisition_optimizer_type='DIRECT')
        self.assertEqual(method.acquisition_optimizer_type, 'DIRECT')

        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         acquisition_optimizer_type='CMA')
        self.assertEqual(method.acquisition_optimizer_type, 'CMA')
Ejemplo n.º 6
0
    def test_acquisition_type(self):
        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         acquisition_type='EI')
        self.assertTrue(isinstance(method.acquisition, AcquisitionEI))

        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         acquisition_type='MPI')
        self.assertTrue(isinstance(method.acquisition, AcquisitionMPI))

        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random',
                         acquisition_type='LCB')
        self.assertTrue(isinstance(method.acquisition, AcquisitionLCB))
Ejemplo n.º 7
0
    def test_domain(self):
        method = Dropout(f=self.f,
                         domain=self.domain,
                         subspace_dim_size=self.subspace_dim_size,
                         fill_in_strategy='random')
        self.assertEqual(method.domain[0]['name'], '0')
        self.assertEqual(method.domain[1]['name'], '1')
        self.assertEqual(method.domain[2]['name'], '2')
        self.assertEqual(method.domain[3]['name'], '3')
        self.assertEqual(method.domain[4]['name'], '4')

        self.assertEqual(len(self.domain),
                         method.space.objective_dimensionality)
Ejemplo n.º 8
0
from bayopt.methods.dropout import Dropout
from bayopt.objective_examples.experiments import SchwefelsFunction
import numpy as np

domain = [{'name': 'x0', 'type': 'continuous', 'domain': (-1, 1), 'dimensionality': 1},
          {'name': 'x1', 'type': 'continuous', 'domain': (-1, 1), 'dimensionality': 1},
          {'name': 'x2', 'type': 'continuous', 'domain': (-1, 1), 'dimensionality': 1},
          {'name': 'x3', 'type': 'continuous', 'domain': (-1, 1), 'dimensionality': 1},
          {'name': 'x4', 'type': 'continuous', 'domain': (-1, 1), 'dimensionality': 1},
          ]

dim = len(domain)
fill_in_strategy = 'random'
f = SchwefelsFunction()
X = np.array([np.full(dim, 1)])
method = Dropout(f=f, domain=domain, subspace_dim_size=2, fill_in_strategy=fill_in_strategy, maximize=False,
                 X=X)
method.run_optimization(max_iter=300, eps=-1)
Ejemplo n.º 9
0
    {
        'name': 'x27',
        'type': 'continuous',
        'domain': (1, 4),
        'dimensionality': 1
    },
    {
        'name': 'x28',
        'type': 'continuous',
        'domain': (1, 4),
        'dimensionality': 1
    },
    {
        'name': 'x29',
        'type': 'continuous',
        'domain': (1, 4),
        'dimensionality': 1
    },
]

dim = len(domain)
fill_in_strategy = 'random'
f = GaussianMixtureFunction(dim=dim, mean_1=2, mean_2=3)
X = np.array([np.full(dim, 1)])
method = Dropout(f=f,
                 domain=domain,
                 subspace_dim_size=5,
                 fill_in_strategy=fill_in_strategy,
                 maximize=True)
method.run_optimization(max_iter=200)
Ejemplo n.º 10
0
    },
    {
        'name': 'x29',
        'type': 'continuous',
        'domain': (-1, 1),
        'dimensionality': 1
    },
]

for i in range(5):

    fill_in_strategy = 'random'
    f = SchwefelsFunction()
    method = Dropout(f=f,
                     domain=domain,
                     subspace_dim_size=5,
                     fill_in_strategy=fill_in_strategy,
                     maximize=False)
    method.run_optimization(max_iter=500, eps=0)

    fill_in_strategy = 'copy'
    f = SchwefelsFunction()
    method = Dropout(
        f=f,
        domain=domain,
        subspace_dim_size=1,
        fill_in_strategy=fill_in_strategy,
        maximize=False,
    )
    method.run_optimization(max_iter=500, eps=0)
Ejemplo n.º 11
0
 def test_random_fill_in(self):
     method = Dropout(f=self.f,
                      domain=self.domain,
                      subspace_dim_size=self.subspace_dim_size,
                      fill_in_strategy='random')