Skip to main content

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)

Uploaded Source

Built Distribution

hydra_smac-0.1.11-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page