Esempio n. 1
0
    def convert_study_config_fixed(self):
        hps = hp_module.HyperParameters()
        hps.Fixed("beta", 0.1)
        study_config_float = utils.make_study_config(objective="accuracy",
                                                     hyperparams=hps)
        self.assertEqual(study_config_float, STUDY_CONFIG_FIXED_FLOAT)

        hps = hp_module.HyperParameters()
        hps.Fixed("type", "WIDE_AND_DEEP")
        study_config_categorical = utils.make_study_config(
            objective="accuracy", hyperparams=hps)
        self.assertEqual(study_config_categorical,
                         STUDY_CONFIG_FIXED_CATEGORICAL)
Esempio n. 2
0
 def test_convert_study_config_fixed(self, name, value, expected_config):
     hps = hp_module.HyperParameters()
     hps.Fixed(name, value)
     study_config = utils.make_study_config(
         objective="accuracy", hyperparams=hps
     )
     self._assert_study_config_equal(study_config, expected_config)
Esempio n. 3
0
    def test_convert_study_config_categorical(self):
        hps = hp_module.HyperParameters()
        hps.Choice("model_type", ["LINEAR", "WIDE_AND_DEEP"])
        study_config = utils.make_study_config(
            objective="accuracy", hyperparams=hps)
        self._assert_study_config_equal(study_config, STUDY_CONFIG_CATEGORICAL)

        actual_hps = utils.convert_study_config_to_hps(study_config)
        self._assert_hps_equal(actual_hps, hps)
Esempio n. 4
0
    def convert_study_config_int_step(self):
        hps = hp_module.HyperParameters()
        hps.Int("units", min_value=32, max_value=128, step=32)
        study_config = utils.make_study_config(
            objective="accuracy", hyperparams=hps)
        self.assertEqual(study_config, STUDY_CONFIG_INT_STEP)

        actual_hps = utils.convert_study_config_to_hps(study_config)
        self.assertEqual(actual_hps.space, hps.space)
Esempio n. 5
0
    def test_convert_study_config_multi_float(self):
        hps = hp_module.HyperParameters()
        hps.Float("theta", min_value=0.0, max_value=1.57)
        hps.Float("r", min_value=0.0, max_value=1.0)
        study_config = utils.make_study_config(
            objective="accuracy", hyperparams=hps)
        self._assert_study_config_equal(study_config, STUDY_CONFIG_MULTI_FLOAT)

        actual_hps = utils.convert_study_config_to_hps(study_config)
        self._assert_hps_equal(actual_hps, hps)
Esempio n. 6
0
    def test_convert_study_config_discrete(self):
        hps = hp_module.HyperParameters()
        hps.Choice("learning_rate", [1e-4, 1e-3, 1e-2])
        study_config = utils.make_study_config(
            objective=oracle_module.Objective("val_accuracy", "max"),
            hyperparams=hps)
        self._assert_study_config_equal(study_config, STUDY_CONFIG_DISCRETE)

        actual_hps = utils.convert_study_config_to_hps(study_config)
        self._assert_hps_equal(actual_hps, hps)
Esempio n. 7
0
    def convert_study_config_float_log_scale(self):
        hps = hp_module.HyperParameters()
        hps.Float("learning_rate", min_value=1e-4, max_value=1e-1,
                  sampling="log")
        study_config = utils.make_study_config(
            objective="accuracy", hyperparams=hps)
        self.assertEqual(study_config, STUDY_CONFIG_FLOAT_LOG_SCALE)

        actual_hps = utils.convert_study_config_to_hps(study_config)
        self.assertEqual(actual_hps.space, hps.space)
Esempio n. 8
0
    def convert_study_config_int(self, min_value, max_value, step,
                                 expected_config):
        hps = hp_module.HyperParameters()
        hps.Int("units", min_value=min_value, max_value=max_value, step=step)
        study_config = utils.make_study_config(objective="accuracy",
                                               hyperparams=hps)
        self.assertDictEqual(study_config, expected_config)

        actual_hps = utils.convert_study_config_to_hps(study_config)
        self.assertEqual(actual_hps.space, hps.space)
Esempio n. 9
0
    def test_convert_study_config_float(self, min_value, max_value, step,
                                        sampling, expected_config):
        hps = hp_module.HyperParameters()
        hps.Float("learning_rate", min_value=min_value, max_value=max_value,
                  step=step, sampling=sampling)
        study_config = utils.make_study_config(
            objective="accuracy", hyperparams=hps)
        self._assert_study_config_equal(study_config, expected_config)

        actual_hps = utils.convert_study_config_to_hps(study_config)
        self._assert_hps_equal(actual_hps, hps)
Esempio n. 10
0
    def test_convert_study_config_int(self, min_value, max_value, step,
                                      expected_config):
        hps = hp_module.HyperParameters()
        if step:
            hps.Int(
                "units", min_value=min_value, max_value=max_value, step=step)
        else:
            hps.Int("units", min_value=min_value, max_value=max_value)
        study_config = utils.make_study_config(
            objective="accuracy", hyperparams=hps)
        self._assert_study_config_equal(study_config, expected_config)

        actual_hps = utils.convert_study_config_to_hps(study_config)
        self._assert_hps_equal(actual_hps, hps)
Esempio n. 11
0
 def test_convert_study_config_bool(self):
     hps = hp_module.HyperParameters()
     hps.Boolean("has_beta")
     study_config = utils.make_study_config(
         objective="accuracy", hyperparams=hps)
     self._assert_study_config_equal(study_config, STUDY_CONFIG_BOOL)