Exemple #1
0
    def test_read_and_write_pcs(self):
        configuration_space_path = os.path.abspath(HPOlibConfigSpace.__file__)
        configuration_space_path = os.path.dirname(configuration_space_path)
        configuration_space_path = os.path.join(
            configuration_space_path, "..", "test", "test_searchspaces",
            "mini_autosklearn_original.pcs")

        with open(configuration_space_path) as fh:
            cs = pcs_parser.read(fh)

        pcs = pcs_parser.write(cs)

        with open(configuration_space_path) as fh:
            lines = fh.readlines()

        num_asserts = 0
        for line in lines:
            line = line.replace("\n", "")
            line = line.split("#")[0]  # Remove comments
            line = line.strip()

            if line:
                num_asserts += 1
                self.assertIn(line, pcs)

        self.assertEqual(21, num_asserts)

        # Sample a little bit
        rs = RandomSampler(cs, 1)
        print cs
        for i in range(1000):
            c = rs.sample_configuration()
    def test_read_and_write_pcs(self):
        configuration_space_path = os.path.abspath(HPOlibConfigSpace.__file__)
        configuration_space_path = os.path.dirname(configuration_space_path)
        configuration_space_path = os.path.join(configuration_space_path,
                                                "..", "test",
                                                "test_searchspaces",
                                                "mini_autosklearn_original.pcs")

        with open(configuration_space_path) as fh:
            cs = pcs_parser.read(fh)

        pcs = pcs_parser.write(cs)

        with open(configuration_space_path) as fh:
            lines = fh.readlines()

        num_asserts = 0
        for line in lines:
            line = line.replace("\n", "")
            line = line.split("#")[0]       # Remove comments
            line = line.strip()

            if line:
                num_asserts += 1
                self.assertIn(line, pcs)

        self.assertEqual(21, num_asserts)

        # Sample a little bit
        rs = RandomSampler(cs, 1)
        print cs
        for i in range(1000):
            c = rs.sample_configuration()
 def test_read_configuration_space_conditional_with_two_parents(self):
     pcs = list()
     pcs.append("@1:0:restarts {F,L,D,x,+,no}[x]")
     pcs.append("@1:S:Luby:aryrestarts {1,2}[1]")
     pcs.append("@1:2:Luby:restarts [1,65535][1000]il")
     pcs.append("@1:2:Luby:restarts | @1:0:restarts in {L}")
     pcs.append("@1:2:Luby:restarts | @1:S:Luby:aryrestarts in {2}")
     cs = pcs_parser.read(pcs)
     self.assertEqual(len(cs.get_conditions()), 1)
     self.assertIsInstance(cs.get_conditions()[0], AndConjunction)
 def test_read_configuration_space_easy(self):
     expected = six.StringIO()
     expected.write('# This is a \n')
     expected.write('   # This is a comment with a leading whitespace ### ffds \n')
     expected.write('\n')
     expected.write('float_a [-1.23, 6.45] [2.61] # bla\n')
     expected.write('e_float_a [.5E-2, 4.5e+06] [2250000.0025]\n')
     expected.write('int_a [-1, 6] [2]i\n')
     expected.write('log_a [4e-1, 6.45] [1.6062378404]l\n')
     expected.write('int_log_a [1, 6] [2]il\n')
     expected.write('cat_a {a,"b",c,d} [a]\n')
     expected.write('@.:;/\?!$%&_-<>*+1234567890 {"const"} ["const"]\n')
     expected.seek(0)
     cs = pcs_parser.read(expected)
     self.assertEqual(cs, easy_space)
    def test_read_configuration_space_conditional(self):
        # More complex search space as string array
        complex_cs = list()
        complex_cs.append("kernel {rbf, poly, sigmoid} [rbf]")
        complex_cs.append("C [0.03125, 32768] [32]l")
        complex_cs.append("gamma [0.000030518, 8] [0.0156251079996]l")
        complex_cs.append("degree [1, 5] [3]i")
        complex_cs.append("lr [0.0001, 1.0] [0.50005]")
        complex_cs.append("neurons [16, 1024] [520]i # Should be Q16")
        complex_cs.append("preprocessing {None, pca} [None]")

        complex_cs.append("classifier {svm, nn} [svm]")
        complex_cs.append("C | classifier in {svm}")
        complex_cs.append("kernel | classifier in {svm}")
        complex_cs.append("degree | kernel in {poly, sigmoid}")
        complex_cs.append("gamma | kernel in {rbf}")
        complex_cs.append("lr | classifier in {nn}")
        complex_cs.append("neurons | classifier in {nn}")

        cs = pcs_parser.read(complex_cs)
        self.assertEqual(cs, conditional_space)