def initialize_framework(default_config='default.yaml', config_manager=config_manager, **kwargs): """ Reads default config if exists Args: config_data: Returns: """ config_manager.register(MainConfig) if os.path.exists(default_config): config_manager.load_yaml(default_config, section=MainConfig._section) config_manager.update_config(main_config) register_modules(config_manager=config_manager) # set logging levels get_logger.set_level(main_config.log_level_console) get_logger.set_filehandler_level(main_config.log_level_file) if main_config.plotting_backend != None: import matplotlib.pyplot as plt plt.switch_backend(main_config.plotting_backend) # reload config, now that we have registered the modules. config_manager.load_yaml(default_config) else: logger.warning(f'Did not find default config ("{default_config}").')
def register_modules(config_manager): """ Registers modules as given by MainConfig with the config_manager. Args: config_manager: """ for m in main_config.modules: if isinstance(m, str): m = locate(m) config_manager.register(m) logger.info(f'Registered module "{m.__name__}".')
def main(): """ Main program entry point. """ config_manager.register(MainConfig) parser = argparse.ArgumentParser(description='Bandit and Bayesian Optimization Experimental Framework.') parser.add_argument("task", type=parse_task) parser.add_argument("experiment", nargs='?') parser.add_argument("--save", help='Path where to save to.') parser.add_argument("--config", required=False, default=None) parser.add_argument("--include", required=False, default=None, type=str, nargs='+') parser.add_argument("--overwrite", required=False, action='store_true') parser.add_argument("--plots", required=False, help='Immediately plot after run.', nargs='*') parser.add_argument("--aggregator", required=False, help='Immediately plot after run.', nargs='*') parser.add_argument("--remote", required=False, action='store_true', help='Run remotely using ceramo.') parser.add_argument("-m", "--message", required=False, help='Message.') args = parser.parse_args() initialize_framework() args.task(args)
class TripathyGPConfig(ModelConfig): """ * kernels: List of kernels * noise_var: noise variance """ # kernels = ConfigField([('GPy.kern.RBF', {'variance': 2., 'lengthscale': 0.2 , 'ARD': True})]) noise_var = ConfigField(0.01) calculate_gradients = ConfigField(False, comment='Enable/Disable computation of gradient on each update.') optimize_bias = ConfigField(False) optimize_var = ConfigField(False) bias = ConfigField(0) _section = 'src.tripathy__' config_manager.register(TripathyGPConfig) from bacode.tripathy.src.bilionis_refactor.t_kernel import TripathyMaternKernel from bacode.tripathy.src.bilionis_refactor.t_optimizer import TripathyOptimizer @assign_config(TripathyGPConfig) class TripathyGP(ConfidenceBoundModel): """ Base class for GP optimization. Handles common functionality. """ def set_new_kernel(self, d, W=None, variance=None, lengthscale=None): self.kernel = TripathyMaternKernel( real_dim=self.domain.d,
* kernels: List of kernels * noise_var: noise variance """ # kernels = ConfigField([('GPy.kern.Matern32', {'variance': 1., 'lengthscale': 1.5, 'ARD': True})]) noise_var = ConfigField(0.01) calculate_gradients = ConfigField( False, comment='Enable/Disable computation of gradient on each update.') optimize_bias = ConfigField(False) optimize_var = ConfigField(False) bias = ConfigField(0) _section = 'src.tripathy__' config_manager.register(BoringGPConfig) from bacode.tripathy.src.bilionis_refactor.t_kernel import TripathyMaternKernel from GPy.kern import Matern32, RBF from bacode.tripathy.src.bilionis_refactor.t_optimizer import TripathyOptimizer @assign_config(BoringGPConfig) class BoringGP(ConfidenceBoundModel): """ Base class for GP optimization. Handles common functionality. """ def create_new_kernel(self, active_d,
""" * kernels: List of kernels * noise_var: noise variance """ # kernels = ConfigField([('GPy.kern.RBF', {'variance': 2., 'lengthscale': 0.2 , 'ARD': True})]) noise_var = ConfigField(0.1) calculate_gradients = ConfigField( True, comment='Enable/Disable computation of gradient on each update.') optimize_bias = ConfigField(False) optimize_var = ConfigField(False) bias = ConfigField(0) _section = 'src.tripathy__' config_manager.register(ClassicalActiveSubspaceGPConfig) # def optimize_gp(experiment): # experiment.algorithm.f.gp.kern.variance.fix() # experiment.algorithm.f.gp.optimize() # print(experiment.algorithm.f.gp) from .t_kernel import TripathyMaternKernel from .t_optimizer import TripathyOptimizer @assign_config(ClassicalActiveSubspaceGPConfig) class ClassicalActiveSubspaceGP(ConfidenceBoundModel): """ Base class for GP optimization. Handles common functionality.
def register_modules(modules): for m in modules: if isinstance(m, str): m = locate(m) config_manager.register(m) logger.info(f'Registered module "{m.__name__}".')
from bacode.tripathy.src.rembo.utils import sample_orthogonal_matrix import numpy as np from febo.algorithms import Algorithm, AlgorithmConfig from febo.environment import ContinuousDomain from febo.models import GP from febo.optimizers import ScipyOptimizer from febo.utils.config import ConfigField, config_manager, assign_config class RemboConfig(AlgorithmConfig): dim = ConfigField(2, comment='subspace dimension') config_manager.register(RemboConfig) def normalize(x, domain): """ Normalize value of x from the range of the domain, to [-1, 1]^d :param x: :param center: :param range: :return: """ # assert x.shape == center.shape, ("Center and x don't have the same shape ", x.shape, center.shape) # assert domainrange.shape == center.shape, ("Center and range don't have the same shape ", center.shape, domainrange.shape) return (domain.normalize(x) - 0.5) * 2. # return np.divide(x - center, domainrange)
* kernels: List of kernels * noise_var: noise variance """ # kernels = ConfigField([('GPy.kern.RBF', {'variance': 2., 'lengthscale': 0.2 , 'ARD': True})]) noise_var = ConfigField(0.01) calculate_gradients = ConfigField( False, comment='Enable/Disable computation of gradient on each update.') optimize_bias = ConfigField(False) optimize_var = ConfigField(False) bias = ConfigField(0) _section = 'src.boring.boring_model' config_manager.register(BoringModelConfig) # def optimize_gp(experiment): # experiment.algorithm.f.gp.kern.variance.fix() # experiment.algorithm.f.gp.optimize() # print(experiment.algorithm.f.gp) from bacode.tripathy.src.bilionis_refactor.t_kernel import TripathyMaternKernel from bacode.tripathy.src.bilionis_refactor.t_optimizer import TripathyOptimizer from bacode.tripathy.src.boring.generate_orthogonal_basis import generate_orthogonal_matrix_to_A @assign_config(BoringModelConfig) class BoringGP(ConfidenceBoundModel): """ Base class for GP optimization.