示例#1
0
    def test_MTGP(self):
        """Tests MTGP instantiation."""
        # Test Multi-type MTGP
        exp = get_multi_type_experiment(add_trials=True)
        mtgp = get_MTGP(experiment=exp, data=exp.fetch_data())
        self.assertIsInstance(mtgp, TorchModelBridge)

        # Test Single-type MTGP
        exp = get_branin_experiment()
        # Check that factory generates a valid sobol modelbridge.
        sobol = get_sobol(search_space=exp.search_space)
        self.assertIsInstance(sobol, RandomModelBridge)
        for _ in range(5):
            sobol_run = sobol.gen(n=1)
            t = exp.new_batch_trial().add_generator_run(sobol_run)
            t.set_status_quo_with_weight(status_quo=t.arms[0], weight=0.5)
            t.run()
        mtgp = get_MTGP(experiment=exp, data=exp.fetch_data(), trial_index=0)
        self.assertIsInstance(mtgp, TorchModelBridge)

        with self.assertRaises(ValueError):
            get_MTGP(experiment=exp, data=exp.fetch_data(), trial_index=9)

        exp = get_branin_experiment()
        sobol = get_sobol(search_space=exp.search_space)
        self.assertIsInstance(sobol, RandomModelBridge)
        sobol_run = sobol.gen(n=1)
        t = exp.new_batch_trial().add_generator_run(sobol_run)
        t.run()

        with self.assertRaises(ValueError):
            get_MTGP(experiment=exp, data=exp.fetch_data(), trial_index=0)
示例#2
0
 def setUp(self):
     self.experiment = get_multi_type_experiment(add_trials=True)
     self.data = self.experiment.fetch_data()
     self.observations = observations_from_data(self.experiment, self.data)
     self.observation_data = [o.data for o in self.observations]
     self.observation_features = [o.features for o in self.observations]
     self.tconfig = tconfig_from_mt_experiment(self.experiment)
示例#3
0
    def testEq(self):
        exp2 = get_multi_type_experiment()

        # Should be equal to start
        self.assertTrue(self.experiment == exp2)

        self.experiment.add_tracking_metric(BraninMetric("m3", ["x2", "x1"]),
                                            trial_type="type1",
                                            canonical_name="m4")

        # Test different set of metrics
        self.assertFalse(self.experiment == exp2)

        exp2.add_tracking_metric(BraninMetric("m3", ["x2", "x1"]),
                                 trial_type="type1",
                                 canonical_name="m5")

        # Test different metric definitions
        self.assertFalse(self.experiment == exp2)

        exp2.update_tracking_metric(BraninMetric("m3", ["x2", "x1"]),
                                    trial_type="type1",
                                    canonical_name="m4")

        # Should be the same
        self.assertTrue(self.experiment == exp2)

        exp2.remove_tracking_metric("m3")
        self.assertFalse(self.experiment == exp2)
示例#4
0
 def testMTExperimentSaveAndLoad(self):
     experiment = get_multi_type_experiment(add_trials=True)
     save_experiment(experiment)
     loaded_experiment = load_experiment(experiment.name)
     self.assertEqual(loaded_experiment.default_trial_type, "type1")
     self.assertEqual(len(loaded_experiment._trial_type_to_runner), 2)
     self.assertEqual(loaded_experiment.metric_to_trial_type["m1"], "type1")
     self.assertEqual(loaded_experiment.metric_to_trial_type["m2"], "type2")
     self.assertEqual(loaded_experiment._metric_to_canonical_name["m2"], "m1")
     self.assertEqual(len(loaded_experiment.trials), 2)
示例#5
0
文件: test_factory.py 项目: jlin27/Ax
    def test_MTGP(self):
        """Tests MTGP instantiation."""
        # Test Multi-type MTGP
        exp = get_multi_type_experiment(add_trials=True)
        mtgp = get_MTGP(experiment=exp, data=exp.fetch_data())
        self.assertIsInstance(mtgp, TorchModelBridge)

        # Test Single-type MTGP
        exp = get_branin_experiment()
        # Check that factory generates a valid sobol modelbridge.
        sobol = get_sobol(search_space=exp.search_space)
        self.assertIsInstance(sobol, RandomModelBridge)
        for _ in range(5):
            sobol_run = sobol.gen(n=1)
            exp.new_batch_trial().add_generator_run(sobol_run).run()
        mtgp = get_MTGP(experiment=exp, data=exp.fetch_data())
        self.assertIsInstance(mtgp, TorchModelBridge)
示例#6
0
    def test_MTGP(self):
        """Tests MTGP instantiation."""
        # Test Multi-type MTGP
        exp = get_multi_type_experiment(add_trials=True)
        mtgp = get_MTGP(experiment=exp, data=exp.fetch_data())
        self.assertIsInstance(mtgp, TorchModelBridge)

        # Test Single-type MTGP
        exp = get_branin_experiment()
        # Check that factory generates a valid sobol modelbridge.
        sobol = get_sobol(search_space=exp.search_space)
        self.assertIsInstance(sobol, RandomModelBridge)
        for _ in range(5):
            sobol_run = sobol.gen(n=1)
            exp.new_batch_trial().add_generator_run(sobol_run).run()
        mtgp = get_MTGP(experiment=exp,
                        is_multi_type=False,
                        data=exp.fetch_data())
        self.assertIsInstance(mtgp, TorchModelBridge)

        # Test wrong call of Multi-type MTGP. The type of the input experiment
        # should be MultiTypeExperiment.
        with self.assertRaises(ValueError):
            get_MTGP(experiment=exp, is_multi_type=True, data=exp.fetch_data())
示例#7
0
 def setUp(self):
     self.experiment = get_multi_type_experiment()
示例#8
0
 def test_MTGP(self):
     """Tests MTGP instantiation."""
     exp = get_multi_type_experiment(add_trials=True)
     mtgp = get_MTGP(experiment=exp, data=exp.fetch_data())
     self.assertIsInstance(mtgp, TorchModelBridge)