def read_quniform(self, expr, label, condition=None): # Or # 0 quniform # 1 Literal{2.50001} # 2 Literal{8.5} # 3 Literal{1} assert len(expr.inputs()) == 3 assert all([input.name == "literal" for input in expr.inputs()]), \ expr.inputs() lower = expr.inputs()[0]._obj upper = expr.inputs()[1]._obj q = expr.inputs()[2]._obj if abs(q - 1.0) < 0.0001: # Special case (see top of function) # + avoid numerical issues when rounding param.upper if abs(lower + 0.49999 - np.round(lower, 0)) < 0.0001 and\ abs(upper - 0.5 - np.round(upper - 0.0001, 0)) < 0.0001 and \ abs(q - 1.0) < 0.0001: lower = np.round(lower, 0) upper = np.round(upper - 0.0001, 0) else: print "WARNING: %s has a q-value which suggests the parameter is an Integer," \ "but the ranges could not be properly inferred." return configuration_space_module.UniformIntegerHyperparameter( label, lower, upper) else: return configuration_space_module.UniformFloatHyperparameter(label, lower, upper, q=q)
def read_uniform(self, expr, label, condition=None): assert len(expr.inputs()) == 2 assert all([input.name == "literal" for input in expr.inputs()]), \ expr.inputs() lower = expr.inputs()[0]._obj upper = expr.inputs()[1]._obj return configuration_space_module.UniformFloatHyperparameter( label, lower, upper)
def test_write_log10(self): expected = "a [10.0, 1000.0] [100.0]l" sp = { "a": configuration_space.UniformFloatHyperparameter("a", 10, 1000, base=10) } value = pcs_parser.write(sp) self.assertEqual(expected, value)
def test_write_log23(self): expected = "LOG23_a [1.0, 5.0] [3.0]" sp = { "a": configuration_space.UniformFloatHyperparameter("a", 23**1, 23**5, base=23) } value = pcs_parser.write(sp) self.assertEqual(expected, value)
def test_write_q_float(self): expected = "Q16_float_a [16.1, 1024.1] [520.1]" sp = { "a": configuration_space.UniformFloatHyperparameter("float_a", 16.10, 1024.10, q=16) } value = pcs_parser.write(sp) self.assertEqual(expected, value)
def test_read_configuration_space_basic(self): float_a_copy = configuration_space.UniformFloatHyperparameter( "float_a", -1.23, 6.45) a_copy = {"a": float_a_copy, "b": int_a} a_real = {"b": int_a, "a": float_a} self.assertDictEqual(a_real, a_copy)
import HPOlib.format_converter.configuration_space as configuration_space import HPOlib.format_converter.pcs_parser as pcs_parser # More complex search space classifier = configuration_space.CategoricalHyperparameter( "classifier", ["svm", "nn"]) kernel = configuration_space.CategoricalHyperparameter("kernel", ["rbf", "linear"], conditions=[[ "classifier == svm", ]]) C = configuration_space.UniformFloatHyperparameter( "C", 0.03125, 32768, # base=2, conditions=[[ "classifier == svm", ]]) gamma = configuration_space.UniformFloatHyperparameter( "gamma", 0.000030518, 8, # base=2, conditions=[["kernel == rbf", "classifier == svm"]]) neurons = configuration_space.UniformIntegerHyperparameter( "neurons", 16, 1024, # q=16, conditions=[[ "classifier == nn", ]])
def test_uniform_float_to_int(self): # For some reason, the upper bound converts to an int param = configuration_space.UniformFloatHyperparameter( "@1:max-feature-time", 1.0, 600.0, q=1.0, base=10.0) param = param.to_integer() print param
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. __authors__ = ["Katharina Eggensperger", "Matthias Feurer"] __contact__ = "automl.org" import StringIO import unittest import HPOlib.format_converter.configuration_space as configuration_space import HPOlib.format_converter.pb_parser as pb_parser float_a = configuration_space.UniformFloatHyperparameter("float_a", -5.3, 10.5) int_a = configuration_space.UniformIntegerHyperparameter("int_a", -5, 10) cat_a = configuration_space.CategoricalHyperparameter("enum_a", ["5", "a", "b", "@/&%%"]) crazy = configuration_space.CategoricalHyperparameter("@.:;/\?!$%&_-<>*+1234567890", ["const"]) easy_space = {"float_a": float_a, "int_a": int_a, "enum_a": cat_a, "@.:;/\?!$%&_-<>*+1234567890": crazy, } class TestPbConverter(unittest.TestCase): def test_read_configuration_space_easy(self): expected = StringIO.StringIO() expected.write("""