def test_bool(): api_config = { "x": { "type": "bool" }, } transformer = HyperTransformer(api_config) gs = GeneticSearch(transformer) proposal = gs.suggest(fit_function_bool) assert 1 == proposal["x"]
def test_categorical(): api_config = { "x": { "type": "cat", "values": ["exp", "log", "abs"] }, } transformer = HyperTransformer(api_config) gs = GeneticSearch(transformer) proposal = gs.suggest(fit_function_cat) assert "exp" == proposal["x"]
def test_log_space(): api_config = { "x": { "type": "real", "space": "log", "range": (0.1, 100) }, } transformer = HyperTransformer(api_config) gs = GeneticSearch(transformer) proposal = gs.suggest(basic_fit_function_10) assert pytest.approx(10, 0.1) == proposal["x"]
def test_happy_path(): api_config = { "x": { "type": "real", "space": "linear", "range": (-10, 10) }, } transformer = HyperTransformer(api_config) gs = GeneticSearch(transformer) proposal = gs.suggest(basic_fit_function) assert pytest.approx(-1, 0.1) == proposal["x"]
def test_int_values(): api_config = { "x": { "type": "int", "space": "linear", "values": (-10, -2, -1, 0, 10) }, } transformer = HyperTransformer(api_config) gs = GeneticSearch(transformer) proposal = gs.suggest(basic_fit_function) assert pytest.approx(-1, 0.1) == proposal["x"]
def test_timeout_callback(): api_config = { "x": { "type": "real", "space": "linear", "range": (-10, 10) }, } transformer = HyperTransformer(api_config) gs = GeneticSearch(transformer) start_time = time() proposal = gs.suggest(basic_fit_function, timeout=0.001) end_time = time() assert pytest.approx(-1, 1) == proposal["x"] assert end_time - start_time < 0.1
def test_bounds_log(): min_max_iter = 10 max_max_iter = 5000 api_config = { "max_iter": { "type": "int", "space": "log", "range": (min_max_iter, max_max_iter) }, } transformer = HyperTransformer(api_config) gs = GeneticSearch(transformer) for i in range(10): proposal = gs.suggest(more_better_fit_function, seed=i) print(proposal) assert min_max_iter <= proposal["max_iter"] <= max_max_iter
def test_mixed_types(): api_config = { "x": { "type": "real", "space": "linear", "range": (-10, 10) }, "b": { "type": "bool" }, "c": { "type": "cat", "values": ["exp", "log", "abs"] }, } transformer = HyperTransformer(api_config) gs = GeneticSearch(transformer) proposal = gs.suggest(fit_function_mixed_type) assert (pytest.approx(-1, 0.1) == proposal["x"] and 1 == proposal["b"] and "exp" == proposal["c"])