Esempio n. 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"])
Esempio n. 2
0
    def test_sample_params(self):
        ps = ParamSpace()
        ps.add_value("p1", True)
        ps.add_list("p2", ["A", "B"])
        ps.add_random("p3", n=1, prior="uniform", low=1, high=3)

        x = ps.sample_space()
        self.assertIsInstance(x, dict)
Esempio n. 3
0
    def test_param_grid_with_id(self):
        ps = ParamSpace()
        ps.add_value("p1", True)
        ps.add_list("p2", ["A", "B"])

        params1 = ps.param_grid(runs=5)

        self.assertEqual(len(list(params1)), 1 * 2 * 5)
Esempio n. 4
0
    def test_write_grid_files(self):
        ps = ParamSpace()
        ps.add_value("p1", True)
        ps.add_list("p2", ["A", "B"])
        ps.add_random("p3", n=2, prior="uniform", low=1, high=3)
        # print("param space size ", ps.grid_size)

        out_path = "/tmp/test_params/"
        if not os.path.exists(out_path) or not os.path.isdir(out_path):
            os.makedirs(out_path)
        ps.write_config_files(out_path)
Esempio n. 5
0
    def test_write_recover(self):
        """ There is one issue with writing the param assets which is the fact that these do not preserve the
        value types, this is expected, the only issue was that we need to ensure that we can use np.random.uniform
        so regardless of the add_random and add_range arg types, they will be converted to float parameters
        """
        ps = ParamSpace()
        ps.add_value("p1", True)
        ps.add_list("p2", ["A", "B"])
        ps.add_random("p3", low=0, high=4, prior="uniform", n=3)

        param_filename = "test.conf"
        ps.write(param_filename)
        self.assertTrue(os.path.exists(param_filename))
        ParamSpace(param_filename)
        os.remove(param_filename)
Esempio n. 6
0
    def test_param_grid(self):
        ps = ParamSpace()
        ps.add_value("p1", True)
        ps.add_list("p2", ["A", "B"])
        ps.add_random("p3", low=0, high=4, prior="uniform", n=3)
        # print("param space size ", ps.grid_size)

        grid = ps.param_grid()

        # for params in grid:
        #    print(params)

        grid = ps.param_grid()
        grid = list(grid)
        self.assertEqual(len(grid), 1 * 2 * 3)
        self.assertEqual(len(grid), ps.size)
Esempio n. 7
0
    def test_write_summary(self):
        summary_file = "params.csv"

        ps = ParamSpace()
        ps.add_value("p1", True)
        ps.add_list("p2", ["A", "B"])
        ps.add_random("p3", low=0, high=4, prior="uniform", n=3)
        # print("param space size ", ps.grid_size)

        ps.write_configs(summary_file)

        written_summary = open(summary_file)
        reader = csv.DictReader(written_summary)

        params = [dict(config) for config in reader]
        # print("read parameters")
        # for config in params:
        #    print(config)

        written_summary.close()
        os.remove(summary_file)

        self.assertEqual(len(params), ps.size)
Esempio n. 8
0
from exp.params import ParamSpace
import os

ps = ParamSpace()
# prefix used to identify result assets

# data
default_corpus = os.path.join(os.getenv("HOME"), "data/datasets/ptb/")
ps.add_value("corpus", default_corpus)
ps.add_value("ngram_size", 5)
ps.add_value("save_model", False)

# nrp params
ps.add_list("k_dim", [1000, 4000, 8000, 10000])
ps.add_list("s_active", [2, 16, 64, 128])

# architecture
ps.add_list("embed_dim", [128, 256])
ps.add_value("embed_init", "uniform")
ps.add_value("embed_init_val", 0.01)
ps.add_value("embed_share", False)

ps.add_list("h_dim", [256, 512])
ps.add_value("h_act", "relu")
ps.add_value("num_h", 1)

ps.add_value("logit_init", "uniform")
ps.add_value("logit_init_val", 0.01)

# ps.add_value("use_f_predict", True)
ps.add_value("f_init", "uniform")
Esempio n. 9
0
from exp.params import ParamSpace
import os

ps = ParamSpace()
# prefix used to identify result assets

# data
default_corpus = os.path.join(os.getenv("HOME"), "data/datasets/ptb/")
ps.add_value("corpus", default_corpus)
ps.add_value("ngram_size", 5)
ps.add_value("save_model", False)

# nrp params

# architecture
ps.add_list("embed_dim", [128, 256])
ps.add_value("embed_init", "uniform")
ps.add_value("embed_init_val", 0.01)
ps.add_value("embed_share", False)

ps.add_list("h_dim", [256, 512])
ps.add_value("h_act", "relu")
ps.add_value("num_h", 1)

ps.add_value("logit_init", "uniform")
ps.add_value("logit_init_val", 0.01)

ps.add_value("use_f_predict", True)
ps.add_value("f_init", "uniform")
ps.add_value("f_init_val", 0.01)