Exemple #1
0
# BBopt setup:
from bbopt import BlackBoxOptimizer
bb = BlackBoxOptimizer(file=__file__)
if __name__ == "__main__":
    bb.run_backend(
        "mixture",
        distribution=[
            ("gaussian_process", float("inf")),
            ("tree_structured_parzen_estimator", 1),
        ],
        remove_erroring_algs=True,
    )

# Set some parameters that skopt supports.
x0 = bb.randint("x0", 1, 10, guess=5)
x1 = bb.choice("x1", [-10, -1, 0, 1, 10])

# Set a parameter that only hyperopt supports.
x2 = bb.normalvariate("x2", mu=0, sigma=1)

if not bb.is_serving:
    assert bb.backend.selected_alg == "tree_structured_parzen_estimator", bb.backend.selected_alg

# Set the goal.
y = x0 + x1 * x2
bb.minimize(y)

# Print out the value we used for debugging purposes.
if __name__ == "__main__":
    print(repr(y))
Exemple #2
0
To run this example, just run:
    > bbopt ./any_fast_example.py
"""

# BBopt setup:
from bbopt import BlackBoxOptimizer
bb = BlackBoxOptimizer(file=__file__)
if __name__ == "__main__":
    bb.run()  # alg="any_fast" should be the default

# We set u ~ dist(0, 1) * sin(dist(0, 1)) where dist is uniform or normal.
from math import sin
dist = bb.choice("dist", ["uniform", "normal"])
if dist == "normal":
    u = bb.normalvariate("x0_n", 0, 1) * sin(bb.normalvariate("x1_n", 0, 1))
else:
    u = bb.random("x0_u") * sin(bb.random("x1_u"))

# If we used hyperopt-only parameters, we shouldn't have skopt.
if hasattr(bb.backend, "selected_backend"):
    bb.remember({"backend": bb.backend.selected_backend})
    if dist == "normal":
        assert bb.backend.selected_backend != "scikit-optimize", bb.backend.selected_backend
else:
    bb.remember({"backend": bb.backend.backend_name})

# Set u as the thing to minimize.
bb.minimize(u)

# Print out the value we used for debugging purposes.
"""
Example of using the hyperopt backend with BBopt.

To run this example, just run:
    > bbopt ./hyperopt_example.py
"""

# BBopt setup:
from bbopt import BlackBoxOptimizer
bb = BlackBoxOptimizer(file=__file__)
if __name__ == "__main__":
    bb.run(alg="tree_structured_parzen_estimator")

# Let's use some parameters!
x0 = bb.randint("x0", 1, 10, guess=5)
x1 = bb.normalvariate("x1", mu=0, sigma=1)
x2 = bb.choice("x2", [-10, -1, 0, 1, 10])

# And let's set our goal!
y = x0 + x1 * x2
bb.minimize(y)

# Finally, we'll print out the value we used for debugging purposes.
if __name__ == "__main__":
    print(repr(y))
"""
Example of using the default "tpe_or_gp" algorithm.

To run this example, just run:
    > bbopt ./tpe_or_gp_example.py
"""

# BBopt setup:
from bbopt import BlackBoxOptimizer
bb = BlackBoxOptimizer(file=__file__)
if __name__ == "__main__":
    bb.run()  # alg="tpe_or_gp" should be the default

# We set u ~ normal(0, 1) * sin(normal(0, 1)).
from math import sin
u = bb.normalvariate("x0", 0, 1) * sin(bb.normalvariate("x1", 0, 1))

# Since we used hyperopt-only parameters, we shouldn't have skopt.
if hasattr(bb.backend, "selected_backend"):
    bb.remember({"backend": bb.backend.selected_backend})
    assert bb.backend.selected_backend != "scikit-optimize", bb.backend.selected_backend
else:
    bb.remember({"backend": bb.backend.backend_name})

# Set u as the thing to minimize.
bb.minimize(u)

# Print out the value we used for debugging purposes.
if __name__ == "__main__":
    print(repr(u))