def test_write_categorical_with_weights(self): cat = CategoricalHyperparameter('a', ['a', 'b'], weights=[0.3, 0.7]) cs = ConfigurationSpace() cs.add_hyperparameter(cat) with self.assertRaisesRegex(ValueError, 'The pcs format does not support'): pcs.write(cs) with self.assertRaisesRegex(ValueError, 'The pcs format does not support'): pcs.write(cs)
def _create_search_space(self, tmp_dir, backend, datamanager, include_estimators=None, exclude_estimators=None, include_preprocessors=None, exclude_preprocessors=None): task_name = 'CreateConfigSpace' self._stopwatch.start_task(task_name) configspace_path = os.path.join(tmp_dir, 'space.pcs') configuration_space = pipeline.get_configuration_space( datamanager.info, include_estimators=include_estimators, exclude_estimators=exclude_estimators, include_preprocessors=include_preprocessors, exclude_preprocessors=exclude_preprocessors) configuration_space = self.configuration_space_created_hook( datamanager, configuration_space) sp_string = pcs.write(configuration_space) backend.write_txt_file(configspace_path, sp_string, 'Configuration space') self._stopwatch.stop_task(task_name) return configuration_space, configspace_path
def test_write_log10(self): expected = "a [10.0, 1000.0] [100.0]l" cs = ConfigurationSpace() cs.add_hyperparameter( UniformFloatHyperparameter("a", 10, 1000, log=True)) value = pcs.write(cs) self.assertEqual(expected, value)
def test_write_q_float(self): expected = "Q16_float_a [16.0, 1024.0] [520.0]" cs = ConfigurationSpace() cs.add_hyperparameter( UniformFloatHyperparameter("float_a", 16, 1024, q=16)) value = pcs.write(cs) self.assertEqual(expected, value)
def test_write_q_int(self): expected = "Q16_int_a [16, 1024] [520]i" cs = ConfigurationSpace() cs.add_hyperparameter( UniformIntegerHyperparameter("int_a", 16, 1024, q=16)) value = pcs.write(cs) self.assertEqual(expected, value)
def test_write_log10(self): expected = "a [10.0, 1000.0] [100.0]l" cs = ConfigurationSpace() cs.add_hyperparameter( UniformFloatHyperparameter("a", 10, 1000, log=True)) value = pcs.write(cs) self.assertEqual(expected, value)
def test_write_q_float(self): expected = "Q16_float_a [16.0, 1024.0] [520.0]" cs = ConfigurationSpace() cs.add_hyperparameter( UniformFloatHyperparameter("float_a", 16, 1024, q=16)) value = pcs.write(cs) self.assertEqual(expected, value)
def test_write_q_int(self): expected = "Q16_int_a [16, 1024] [520]i" cs = ConfigurationSpace() cs.add_hyperparameter( UniformIntegerHyperparameter("int_a", 16, 1024, q=16)) value = pcs.write(cs) self.assertEqual(expected, value)
def test_build_forbidden(self): expected = "a {a, b, c} [a]\nb {a, b, c} [c]\n\n" \ "{a=a, b=a}\n{a=a, b=b}\n{a=b, b=a}\n{a=b, b=b}" cs = ConfigurationSpace() a = CategoricalHyperparameter("a", ["a", "b", "c"], "a") b = CategoricalHyperparameter("b", ["a", "b", "c"], "c") cs.add_hyperparameter(a) cs.add_hyperparameter(b) fb = ForbiddenAndConjunction(ForbiddenInClause(a, ["a", "b"]), ForbiddenInClause(b, ["a", "b"])) cs.add_forbidden_clause(fb) value = pcs.write(cs) self.assertIn(expected, value)
def test_build_forbidden(self): expected = "a {a, b, c} [a]\nb {a, b, c} [c]\n\n" \ "{a=a, b=a}\n{a=a, b=b}\n{a=b, b=a}\n{a=b, b=b}" cs = ConfigurationSpace() a = CategoricalHyperparameter("a", ["a", "b", "c"], "a") b = CategoricalHyperparameter("b", ["a", "b", "c"], "c") cs.add_hyperparameter(a) cs.add_hyperparameter(b) fb = ForbiddenAndConjunction(ForbiddenInClause(a, ["a", "b"]), ForbiddenInClause(b, ["a", "b"])) cs.add_forbidden_clause(fb) value = pcs.write(cs) self.assertIn(expected, value)
def test_read_write(self): # Some smoke tests whether reading, writing, reading alters makes the # configspace incomparable this_file = os.path.abspath(__file__) this_directory = os.path.dirname(this_file) configuration_space_path = os.path.join(this_directory, "..", "test_searchspaces") configuration_space_path = os.path.abspath(configuration_space_path) configuration_space_path = os.path.join(configuration_space_path, "spear-params-mixed.pcs") with open(configuration_space_path) as fh: cs = pcs.read(fh) tf = tempfile.NamedTemporaryFile() name = tf.name tf.close() with open(name, 'w') as fh: pcs_string = pcs.write(cs) fh.write(pcs_string) with open(name, 'r') as fh: pcs_new = pcs.read(fh) self.assertEqual(pcs_new, cs, msg=(pcs_new, cs))
def test_read_write(self): # Some smoke tests whether reading, writing, reading alters makes the # configspace incomparable this_file = os.path.abspath(__file__) this_directory = os.path.dirname(this_file) configuration_space_path = os.path.join(this_directory, "..", "test_searchspaces") configuration_space_path = os.path.abspath(configuration_space_path) configuration_space_path = os.path.join(configuration_space_path, "spear-params-mixed.pcs") with open(configuration_space_path) as fh: cs = pcs.read(fh) tf = tempfile.NamedTemporaryFile() name = tf.name tf.close() with open(name, 'w') as fh: pcs_string = pcs.write(cs) fh.write(pcs_string) with open(name, 'r') as fh: pcs_new = pcs.read(fh) self.assertEqual(pcs_new, cs, msg=(pcs_new, cs))
def _create_search_space(self, tmp_dir, backend, datamanager, include_estimators=None, exclude_estimators=None, include_preprocessors=None, exclude_preprocessors=None): task_name = 'CreateConfigSpace' self._stopwatch.start_task(task_name) configspace_path = os.path.join(tmp_dir, 'space.pcs') configuration_space = pipeline.get_configuration_space( datamanager.info, include_estimators=include_estimators, exclude_estimators=exclude_estimators, include_preprocessors=include_preprocessors, exclude_preprocessors=exclude_preprocessors) configuration_space = self.configuration_space_created_hook( datamanager, configuration_space) sp_string = pcs.write(configuration_space) backend.write_txt_file(configspace_path, sp_string, 'Configuration space') self._stopwatch.stop_task(task_name) return configuration_space, configspace_path
def test_write_log_int(self): expected = "int_log_a [1, 6] [2]il" cs = ConfigurationSpace() cs.add_hyperparameter(int_log_a) value = pcs.write(cs) self.assertEqual(expected, value)
# Create folder for CAVE configuration files if not os.path.exists(output_path + alg): os.makedirs(output_path + alg) # Save them as csv config_csv.to_csv(output_path + alg + '/configurations.csv', index=False) runhistory_csv.to_csv(output_path + alg + '/runhistory.csv', index=False) trajectory_csv.to_csv(output_path + alg + '/trajectory.csv', index=False) # Create Configuration Space cs = _classifiers.get(alg).get_hyperparameter_search_space() # Write pcs with open(output_path + alg + '/configspace.pcs_new', 'w') as fh: fh.write(pcs.write(cs)) # Create scenario with open(output_path + alg + '/scenario.txt', 'w') as sc: sc.write('initial_incumbent = DEFAULT\n') sc.write('runcount_limit = inf\n') sc.write('execdir .\n') sc.write('paramfile = configspace.pcs_new\n') sc.write('run_obj = quality\n') # Encode data categorical = X.select_dtypes(include=['category', 'object', 'bool']) labelEncoder = LabelEncoder() for colname in categorical: X[colname] = labelEncoder.fit_transform(X[colname])
def test_write_log_int(self): expected = "int_log_a [1, 6] [2]il" cs = ConfigurationSpace() cs.add_hyperparameter(int_log_a) value = pcs.write(cs) self.assertEqual(expected, value)