def test_float(self):
        self.pc["parameter_config"] = [
            {"name": "x1", "type": "float", "range": [0, 1], "interval":0.2},
            {"name": "x2", "type": "float", "range": [0, 1]}
        ]
        rp = get_proposer("sequence")(self.pc)
        self.assertEqual(rp.nSamples, 12)
        param1 = rp.get()
        self.assertDictEqual(param1, {"x1": 0, "x2": 0})
        param1 = rp.get()
        self.assertDictEqual(param1, {"x1": 0.2, "x2": 0})
        for i in range(4):
            param1 = rp.get()
        self.assertDictEqual(param1, {"x1": 1, "x2": 0})
        while not rp.finished:
            param1 = rp.get()
        self.assertTrue(param1 == {"x1": 1, "x2": 1})

        self.pc["parameter_config"] = [
            {"name": "x1", "type": "float", "range": [0, 1], "interval": 0.2},
            {"name": "x2", "type": "float", "range": [0, 1], "n": 2}
        ]
        rp = get_proposer("sequence")(self.pc)
        self.assertEqual(rp.nSamples, 12)
        param1 = rp.get()
        self.assertDictEqual(param1, {"x1": 0, "x2": 0})
        param1 = rp.get()
        self.assertDictEqual(param1, {"x1": 0.2, "x2": 0})
        for i in range(4):
            param1 = rp.get()
        self.assertDictEqual(param1, {"x1": 1, "x2": 0})
        while not rp.finished:
            param1 = rp.get()
        self.assertTrue(param1 == {"x1": 1, "x2": 1})
Example #2
0
 def test_int_interval(self):
     self.pc["parameter_config"] = [
         {
             "name": "x1",
             "type": "int",
             "range": [0, 10],
             "interval": 2
         },  # 0 2 4 6 8 10
         {
             "name": "x2",
             "type": "int",
             "range": [0, 10],
             "n": 3
         }  # 0 5 10
     ]
     rp = get_proposer("sequence")(self.pc)
     self.assertEqual(rp.nSamples, 18)
     param1 = rp.get()
     self.assertTrue(param1 == {"x1": 0, "x2": 0})
     param1 = rp.get()
     self.assertTrue(param1 == {"x1": 2, "x2": 0})
     for i in range(10):
         param1 = rp.get()
     self.assertTrue(param1 == {"x1": 10, "x2": 5})
     while not rp.finished:
         param1 = rp.get()
     self.assertTrue(param1 == {"x1": 10, "x2": 10})
Example #3
0
 def setup_config():  # pragma: no cover
     config = dict()
     config['max_iter'] = int(input("max iteration [81]:") or 81)
     config['eta'] = int(input("ita [3]") or 3)
     config["skip_last"] = int(input("skip last [0]") or '0')
     config["engine"] = get_from_options("Hyperparameter sampling engine", ["random", "sequence"])
     config.update(get_proposer(config['engine']).setup_config())
     return config
 def test_failed(self):
     self.pc["parameter_config"] = [
         {"name": "x1", "type": "choice", "range": [2, 4, 6, 8, 10]},
         {"name": "x2", "type": "choice", "range": ["a", "b", "c"]}
     ]
     p = get_proposer("sequence")(self.pc)
     c = p.get()
     job = Job("none", c)
     p.failed(job)
 def test_choice(self):
     self.pc["parameter_config"] = [
         {"name": "x1", "type": "choice", "range": [2, 4, 6, 8, 10]},
         {"name": "x2", "type": "choice", "range": ["a", "b", "c"]}
     ]
     rp = get_proposer("sequence")(self.pc)
     self.assertEqual(rp.nSamples, 15)
     param1 = rp.get()
     self.assertTrue(param1 == {"x1": 2, "x2": "a"})
     while not rp.finished:
         param1 = rp.get()
     self.assertTrue(param1 == {"x1": 10, "x2": "c"})
 def test_int(self):
     self.pc["parameter_config"] = [
         {"name": "x1", "type": "int", "range": [0, 10]},
         {"name": "x2", "type": "int", "range": [0, 10]}
     ]
     rp = get_proposer("sequence")(self.pc)
     self.assertEqual(rp.nSamples, 121)
     param1 = rp.get()
     self.assertTrue(param1 == {"x1": 0, "x2": 0})
     param1 = rp.get()
     self.assertTrue(param1 == {"x1": 1, "x2": 0})
     while not rp.finished:
         param1 = rp.get()
     self.assertTrue(param1 == {"x1": 10, "x2": 10})
Example #7
0
 def setup(self, s):
     # Follow the hyperband paper, set up internal variables based on s_max
     self.s = s
     self.n = int(ceil(self.B / self.max_iter / (s + 1) * self.eta ** s))
     self.r = self.max_iter * self.eta ** (-s)
     gen_config = self.config.copy()
     gen_config["n_samples"] = self.n
     gen_config["random_seed"] = random.randint(0, 100)
     gen_config["proposer"] = gen_config["engine"]
     proposer = get_proposer(gen_config['proposer'])(gen_config)
     self.test_set = [proposer.get for _ in range(self.n)]
     self.t = 0
     self.i = 0
     self.n_configs = self.n * self.eta ** (-self.i)
     self.n_iterations = self.r * self.eta ** self.i