Exemplo n.º 1
0
 def generate_random_hyperparameters(self):
     hyperparameters = {}
     for hp in self._hyperparameters:
         hyperparameters[hp.name] = hp.generate()
     hyperparameters = ppp.dot_map_dict_to_nested_dict(hyperparameters)
     return ppp.merge_recursive_dicts(
         hyperparameters,
         copy.deepcopy(self._default_kwargs),
         ignore_duplicate_keys_in_second_dict=True,
     )
Exemplo n.º 2
0
 def test_merge_recursive_dicts(self):
     a = {'foo': 1, 'bar': {'baz': 3}}
     b = {'foo2': 2, 'bar': {'baz2': 4}}
     result = ppp.merge_recursive_dicts(a, b)
     expected = {
         'foo': 1,
         'foo2': 2,
         'bar': {
             'baz': 3,
             'baz2': 4,
         }
     }
     self.assertDictEqual(result, expected)
Exemplo n.º 3
0
    def iterate_hyperparameters(self):
        """
        Iterate over the hyperparameters in a grid-manner.

        :return: List of dictionaries. Each dictionary is a map from name to
        hyperpameter.
        """
        return [
            ppp.merge_recursive_dicts(
                hyperparameters,
                copy.deepcopy(self._default_kwargs),
                ignore_duplicate_keys_in_second_dict=True,
            ) for hyperparameters in self._hyperparameters_dicts
        ]
Exemplo n.º 4
0
 def wrapped_function(params):
     start_time = time.time()
     if flatten_choice_dictionary:
         params = flatten_hyperopt_choice_dict(params)
     if dotmap_to_nested_dictionary:
         params = dot_map_dict_to_nested_dict(params)
     loss = function(
         merge_recursive_dicts(
             params,
             extra_function_kwargs,
             ignore_duplicate_keys_in_second_dict=True,
         ))
     if maximize:
         loss = -loss
     if np.isnan(loss):
         loss = max_magnitude
     return {
         'loss': loss,
         'status': STATUS_OK,
         'params': params,
         # -- store other results like this
         'eval_time': time.time() - start_time,
     }