Hydra + SMAC
Project description
Hydra-SMAC 0.1.11
A minimal Python re-implementation of Hydra.
Getting started
pip install hydra-smac
Example
For more information on how to use Scenario objects, please refer to the SMAC documentation.
from ConfigSpace import Configuration, ConfigurationSpace, Float
from hydrasmac import Hydra
from smac import Scenario
instances = ["a", "b", "c"]
features = {"a": [0.0], "b": [1.0], "c": [2.0]}
cs = ConfigurationSpace()
cs.add_hyperparameters(
[
Float("x", (1.0, 5.0)),
Float("y", (1.0, 5.0)),
Float("z", (1.0, 5.0)),
]
)
def target_function(config: Configuration, instance: str, seed: int = 0) -> float:
config_dict = config.get_dictionary()
x, y, z = config_dict["x"], config_dict["y"], config_dict["z"]
if instance == "a" and x < 2.5 and y > 2.5 and z > 2.5:
return 0.001
if instance == "b" and y < 2.5 and x > 2.5 and z > 2.5:
return 0.01
if instance == "c" and z < 2.5 and y > 2.5 and x > 2.5:
return 0.1
return 1
scenario = Scenario(
configspace=cs,
instances=instances,
instance_features=features,
n_trials=500,
)
hydra = Hydra(
scenario,
target_function,
hydra_iterations=3,
smac_runs_per_iter=1,
incumbents_added_per_iter=1,
stop_early=True,
)
portfolio = hydra.optimize()
print("====== Resulting portfolio ======")
print(portfolio)
print("=================================")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hydra-smac-0.1.11.tar.gz
(8.9 kB
view hashes)
Built Distribution
Close
Hashes for hydra_smac-0.1.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ba7653a8e0988ccf98256f46b8496a9c4c9a6ee86eca24718c84710a461964b |
|
MD5 | d42c0a93a2764420163ecffe855f862e |
|
BLAKE2b-256 | 3df624a617f8fdedd3fa6b5e5c8748cac94a199cf6d24cab2988a6d6f814f587 |