예제 #1
0
    def run_suggestion(self, command=None):
        # get config from optimizer
        #return self.run_config(self.get_suggestion(), command)
        values = self.get_suggestion()
        config = fill_in_values(self.current_search_space.search_space, values, fill_by='uid')

        return self.run_config(config, command)
예제 #2
0
def test_fill_in_values():
    a = UniformFloat(0, 1)
    b = UniformInt(2, 12)
    c = Gaussian(0, 1)
    search_space = json.loads(json.dumps({
        'a': a,
        'foo': {
            'bar': b,
            'nested': {
                'a': a
            }
        },
        'using_list': [a, b, c]
    }))
    values = {
        a['uid']: 11,
        b['uid']: 2.2,
        c['uid']: 'c'
    }
    cfg = fill_in_values(search_space, values)
    assert cfg == {
        'a': 11,
        'foo': {
            'bar': 2.2,
            'nested': {
                'a': 11
            }
        },
        'using_list': [11, 2.2, 'c']
    }
예제 #3
0
    def _search_space_wrapper(self,
                              space,
                              space_name,
                              fixed=None,
                              fallback=None,
                              preset=None):
        # This function pretends to be a ConfigScope for a named_config
        # but under the hood it is getting a suggestion from the optimizer

        self.current_search_space_name = space_name
        sp = build_search_space(space)

        # Establish connection to database
        if self.db is None:
            self._init_db()

        # Check the validity of this search space
        self._verify_and_init_search_space(sp)

        # Create the optimizer
        if self.optimizer_class is not None:
            if not self.db:
                import warnings
                warnings.warn('No database. Falling back to random search')
                self.optimizer = RandomSearch(self.current_search_space)
            self.optimizer = self.optimizer_class(self.current_search_space)
        else:
            self.optimizer = RandomSearch(self.current_search_space)

        fixed = fixed or {}
        final_config = dict(preset or {})
        # the fallback parameter is needed to fit the interface of a
        # ConfigScope, but here it is not supported.
        assert not fallback, "{}".format(fallback)
        # ensure we have a search space definition
        if self.current_search_space is None:
            raise ValueError("LabAssistant search_space_wrapper called but "
                             "there is no search space definition")

        # Get a hyperparameter configuration from the optimizer
        values = self.get_suggestion()

        # Create configuration object
        config = fill_in_values(self.current_search_space.search_space,
                                values,
                                fill_by='uid')
        final_config.update(config)
        final_config.update(fixed)

        return final_config