コード例 #1
0
    def test_domain(self):
        ps = ParamSpace()
        ps.add_value("value", True)
        domain = ps.domain("value")
        self.assertIn("domain", domain)
        self.assertIn("dtype", domain)
        self.assertEqual(DTypes.CATEGORICAL.value, domain["dtype"])

        ps.add_list("bool", [True, False, True])
        domain = ps.domain("bool")
        self.assertIn("domain", domain)
        self.assertIn("dtype", domain)
        self.assertEqual(DTypes.CATEGORICAL.value, domain["dtype"])
        self.assertListEqual([True, False], domain["domain"])

        ps.add_range("bounds", 0, 10, dtype=float)
        domain = ps.domain("bounds")
        self.assertIn("domain", domain)
        self.assertIn("dtype", domain)
        self.assertIn("prior", domain)
        self.assertEqual("float", domain["dtype"])
        self.assertEqual("uniform", domain["prior"])

        ps.add_random("random", 0, 10, prior="log-uniform", dtype=float)
        domain = ps.domain("bounds")
        self.assertIn("domain", domain)
        self.assertIn("dtype", domain)
        self.assertIn("prior", domain)
        self.assertEqual("float", domain["dtype"])
        self.assertEqual("uniform", domain["prior"])
コード例 #2
0
    def test_add_range(self):
        filename = "test.cfg"
        ps = ParamSpace()
        ps.add_range("range_param", 0, 10, 1, dtype=int)

        ps.write(filename)

        ps = ParamSpace(filename)
        # print(ps.params["range_param"])
        # print(ps.get_range("range_param"))

        os.remove(filename)