Пример #1
0
    def _decode(self, value):
        if self._allow_none and value is None:
            return None
        if isinstance(value, str):
            return locate(value)

        return value
Пример #2
0
def plot(args, experiment=None):
    """
    febo plot
    """

    if experiment is None:
        path = os.path.join(main_config.experiment_dir, args.experiment)
        load_config(os.path.join(path, 'experiment.yaml'))

        experiment = main_config.experiment(main_config.experiment_dir)
        experiment.load(args.experiment)

    if args.plots is None or len(args.plots) == 0:
        logger.warning('No plots specified. Use "--plots path.to.PlottingClass1 path.to.PlottingClass2" to specify plots.')
    for plot_class in args.plots:
        plot_class = plot_class.split(':')
        plot = None
        try:
            plot = locate(plot_class[0])
        except:
            logger.error(f'Could not locate {plot_class}')
        if plot is not None:
            plot = plot(experiment)
            group_id = None
            if len(plot_class) > 1 and plot_class[1]:
                group_id = int(plot_class[1])
            run_id = None
            if len(plot_class) > 2 and plot_class[2]:
                run_id = int(plot_class[2])

            plot.plot(show=True, group_id=group_id, run_id=run_id)
Пример #3
0
    def _init_noise_function(self):
        """"""
        if self.config.noise_function:

            # if self.config.noise_function is a number
            if isinstance(self.config.noise_function, (float, int)):
                noise_var = self.config.noise_function

                # define noise _function
                def noise_function(x):
                    x = np.atleast_2d(x)
                    return noise_var * np.ones(shape=(x.shape[0], 1))
            elif isinstance(self.config.noise_function, str):
                noise_function = locate(self.config.noise_function)
            else:
                raise Exception("Invalid setting for 'noise_function'.")
            # if noise_function is a function, assume it provides std for GaussianNoiseFunction
            if isinstance(noise_function, FunctionType):
                self._noise_function_cls = type(
                    f"__{noise_function.__name__}_Noise",
                    (GaussianNoiseFunction, ), {
                        'std': lambda self, x: noise_function(x)
                    })
            elif issubclass(noise_function, NoiseFunction):
                self._noise_function_cls = noise_function
        else:
            self._noise_function_cls = NoiseFunction

        self._noise_function = self._noise_function_cls(self._domain, self.f)
Пример #4
0
    def _decode(self, value):
        if self._allow_none and value is None:
            return None

        list_decoded = []
        for item in value:
            if isinstance(item, str):
                list_decoded.append(locate(item))
            else:
                list_decoded.append(item)

        return list_decoded
Пример #5
0
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__}".')
Пример #6
0
 def _get_kernel(self):
     kernel = None
     for kernel_module, kernel_params in self.config.kernels:
         input_dim = self.domain.d
         if 'active_dims' in kernel_params:
             input_dim = len(kernel_params['active_dims'])
         kernel_part = locate(kernel_module)(input_dim=input_dim,
                                             **kernel_params)
         if kernel is None:
             kernel = kernel_part
         else:
             kernel += kernel_part
     return kernel
Пример #7
0
    def __init__(self, domain):
        super().__init__(domain)

        self._beta_function = None
        if not self.config.beta is None:
            if isinstance(self.config.beta, str):
                self._beta_function = locate(self.config.beta)
                self.__beta = self.__beta_function
                logger.info(f"Using beta function={self.config.beta} .")
            elif isinstance(self.config.beta, (int, float)):
                def _beta():
                    return self.config.beta
                self.__beta = _beta
                logger.info(f"Using beta={self.config.beta} .")
Пример #8
0
    def finalize(self, *args, **kwargs):
        res = super().finalize(*args, **kwargs)
        for plot_cls in self.config.plots:
            try:
                plot = locate(plot_cls)
                plot = plot(self.experiment)
                plot.plot(show=False,
                          group_id=self.group_id,
                          run_id=self.run_id)
            except Exception as e:
                logger.error(f'Error {str(e)} while plotting {plot_cls}')
                logger.info(
                    f"Here is the stack trace:\n{traceback.format_exc()} ")

        return res
Пример #9
0
def aggregate(args, experiment=None):
    """
    febo aggregate
    """

    if experiment is None:
        path = os.path.join(main_config.experiment_dir, args.experiment)
        load_config(os.path.join(path, 'experiment.yaml'))

        experiment = main_config.experiment(main_config.experiment_dir)
        experiment.load(args.experiment)

    for cls in args.aggregator:
        aggr = locate(cls)
        aggr(experiment)
Пример #10
0
    def initialize(self, **kwargs):
        super(SubDomainBO, self).initialize(**kwargs)

        self._best_x = self.x0.copy()

        self._best_direction = None
        self._phase = 'best'
        self._iteration = 0

        self._parameter_names = kwargs.get('parameter_names')

        self._max_queries_line = dimension_setting_helper(self.config.max_queries_line, self.domain.d)
        self._min_queries_line = dimension_setting_helper(self.config.min_queries_line, self.domain.d)
        self._max_queries_tr = dimension_setting_helper(self.config.max_queries_tr, self.domain.d)
        self._minx_queries_tr = dimension_setting_helper(self.config.min_queries_tr, self.domain.d)
        self._point_type_addition = ''

        self.__acquisition = locate(self.config.acquisition)
Пример #11
0
    def _decode(self, value):
        if isinstance(value, str):
            value = locate(value)()

        decoded_list = []
        for benchmark in value:
            benchmark_settings = {}
            for section, settings in benchmark.items():

                # support for flattend syntax '{section:setting : value }'
                if ':' in section:
                    section, setting = section.rsplit(':')
                    settings = { setting : settings}

                for setting, value in settings.items():
                    if not section in benchmark_settings:
                        benchmark_settings[section] = {}

                    if section in config_manager._fields and setting in config_manager._fields[section]:
                        field = config_manager._fields[section][setting]
                        benchmark_settings[section][setting] = field._encode(value)

            decoded_list.append(benchmark_settings)
        return decoded_list
Пример #12
0
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__}".')