Exemplo n.º 1
0
def evaluate(name, x_next):
    '''
    Evaluate performance of x_next
    '''
    # build problem
    problem = build_problem(name)

    # evaluate x_next with real problem
    y_next = np.array(problem.evaluate_objective(x_next))

    return y_next
Exemplo n.º 2
0
    def _initialize(self):
        '''
        '''
        if not self.agent.check_table_exist() and not self.initializing: # check if initializing
            self.initializing = True

            problem = build_problem(self.config['problem']['name'])
            n_random_sample, init_sample_path = self.config['experiment']['n_random_sample'], self.config['experiment']['init_sample_path']
            X_init_evaluated, X_init_unevaluated, Y_init_evaluated = get_initial_samples(problem, n_random_sample, init_sample_path)
            rowids_unevaluated = self.agent.initialize(X_init_evaluated, X_init_unevaluated, Y_init_evaluated)
            if rowids_unevaluated is not None:
                self.evaluate_manual(rowids_unevaluated)
Exemplo n.º 3
0
def build_optimizer(config):
    '''
    Build optimizer based on problem and configurations
    Input:
        config: experiment configuration
    '''
    prob_cfg, algo_cfg = config['problem'], config['algorithm']

    problem = build_problem(prob_cfg['name'])
    algo = get_algorithm(algo_cfg['name'])
    optimizer = algo(problem, algo_cfg)

    return optimizer
Exemplo n.º 4
0
    def set_config(self, config, window=None):
        '''
        Setting configurations
        '''
        # set parent window for displaying potential error messagebox
        if window is None: window = self.root

        try:
            config = complete_config(config, check=True)
        except Exception as e:
            tk.messagebox.showinfo('Error',
                                   'Invalid configurations: ' + str(e),
                                   parent=window)
            return False

        old_config = None if self.config is None else self.config.copy()

        if self.config is None:  # first time setting config
            # initialize problem
            try:
                problem, self.true_pfront = build_problem(
                    config['problem']['name'], get_pfront=True)
            except Exception as e:
                tk.messagebox.showinfo('Error',
                                       'Invalid values in configuration: ' +
                                       str(e),
                                       parent=window)
                return False

            # check if config is compatible with history data (problem dimension)
            table_exist = self.agent.check_table_exist()
            if table_exist:
                column_names = self.agent.get_column_names()
                data_n_var = len(
                    [name for name in column_names if name.startswith('x')])
                data_n_obj = len([
                    name for name in column_names
                    if name.startswith('f') and '_' not in name
                ])
                problem_cfg = problem.get_config()
                if problem_cfg['n_var'] != data_n_var or problem_cfg[
                        'n_obj'] != data_n_obj:
                    tk.messagebox.showinfo(
                        'Error',
                        'Problem dimension mismatch between configuration and history data',
                        parent=window)
                    return False

            # update config
            self.config = config
            self.problem_cfg = problem.get_config()
            self.problem_cfg.update(self.config['problem'])

            # remove tutorial image
            self.view.image_tutorial.destroy()

            # configure
            self.controller['panel_info'].set_info(self.problem_cfg)
            self.scheduler.set_config(self.config)

            # initialize visualization widgets
            self._init_visualization()

            # load existing data
            if table_exist:
                self._load_existing_data()

            # change menu button status
            self.view.menu_config.entryconfig(0, state=tk.DISABLED)
            self.view.menu_config.entryconfig(1, state=tk.DISABLED)
            self.view.menu_config.entryconfig(2, state=tk.NORMAL)
            for i in range(3):
                self.view.menu_export.entryconfig(i, state=tk.NORMAL)
            for i in range(2):
                self.view.menu_eval.entryconfig(i, state=tk.NORMAL)

            # activate widgets
            entry_mode = self.controller['panel_control'].view.widget['mode']
            entry_mode.enable()
            if not self.agent.can_eval:
                entry_mode.widget['Auto'].disable()

            entry_batch_size = self.controller['panel_control'].view.widget[
                'batch_size']
            entry_batch_size.enable()
            try:
                entry_batch_size.set(self.config['experiment']['batch_size'])
            except:
                entry_batch_size.set(5)

            self.controller['panel_log'].view.widget['clear'].enable()

            # trigger periodic refresh
            self.root.after(self.refresh_rate, self.refresh)

        else:  # user changed config in the middle
            try:
                assert self.config['problem']['name'] == config['problem'][
                    'name']
            except:
                tk.messagebox.showinfo('Error',
                                       'Cannot change problem',
                                       parent=window)
                return False

            self.config = config
            self.scheduler.set_config(self.config)

        if self.config != old_config:
            self.controller['viz_space'].set_config(self.config)

        return True
Exemplo n.º 5
0
    def refresh(self):

        config = self.get_config()
        if config is None: return

        if self.problem_cfg is None:  # first time

            problem_cfg = config['problem']
            problem = build_problem(problem_cfg['name'])
            self.problem_cfg = problem.get_config()
            self.problem_cfg.update(problem_cfg)

            self.can_eval = hasattr(
                problem, 'evaluate_objective'
            ) or self.problem_cfg['obj_func'] is not None

            # mapping from keys to database columns (e.g., X -> [x1, x2, ...])
            self.key_map = {
                'status':
                'status',
                'X': [f'x{i + 1}' for i in range(self.problem_cfg['n_var'])],
                'Y': [f'f{i + 1}' for i in range(self.problem_cfg['n_obj'])],
                'Y_expected': [
                    f'f{i + 1}_expected'
                    for i in range(self.problem_cfg['n_obj'])
                ],
                'Y_uncertainty': [
                    f'f{i + 1}_uncertainty'
                    for i in range(self.problem_cfg['n_obj'])
                ],
                'pareto':
                'pareto',
                'batch':
                'batch',
                '_order':
                '_order',
                '_hypervolume':
                '_hypervolume',
            }

            var_type_map = {
                'continuous': float,
                'integer': int,
                'binary': int,
                'categorical': str,
                'mixed': object,
            }

            # mapping from keys to data types
            self.type_map = {
                'status': str,
                'X': var_type_map[self.problem_cfg['type']],
                'Y': float,
                'Y_expected': float,
                'Y_uncertainty': float,
                'pareto': bool,
                'batch': int,
                '_order': int,
                '_hypervolume': float,
            }

        elif config != self.problem_cfg:  # update in the middle
            self.problem_cfg.update(config['problem'])