Ejemplo n.º 1
0
 def bbopt_actor(env):
     _coconut_match_to_0 = env
     _coconut_match_check_0 = False
     if _coconut.isinstance(_coconut_match_to_0, _coconut.abc.Mapping):
         _coconut_match_temp_0 = _coconut_match_to_0.get(bb_name, _coconut_sentinel)
         if _coconut_match_temp_0 is not _coconut_sentinel:
             bb = _coconut_match_temp_0
             _coconut_match_check_0 = True
     if _coconut_match_check_0 and not (bb is not None):
         _coconut_match_check_0 = False
     if _coconut_match_check_0:
         if isinstance(util_func, Str):
             util = env[util_func]
         else:
             util = util_func(env)
         bb.maximize(util)
     else:
         bb = BlackBoxOptimizer(file=file, tag=env["game"].name + "_" + name)
         env[bb_name] = bb
     bb.run(alg=alg if not env["game"].final_step else None)
     if print_chosen_alg:
         chosen_alg = bb.get_current_run()["values"].get(meta_opt_alg_var)
         if chosen_alg is not None:
             print("\nusing BBopt alg =", chosen_alg)
     return tunable_actor(bb, env)
Ejemplo n.º 2
0
    def __init__(self):
        super().__init__(create_parser(usage))
        self.bb = BlackBoxOptimizer(file=self.args.trials_name)
        if not self.test:
            data = TrainData.from_both(self.args.tags_file,
                                       self.args.tags_folder, self.args.folder)
            _, self.test = data.load(False, True)

        from keras.callbacks import ModelCheckpoint
        for i in list(self.callbacks):
            if isinstance(i, ModelCheckpoint):
                self.callbacks.remove(i)
Ejemplo n.º 3
0
"""
Example of using BBopt with conditional parameters and randomness
while leveraging the bayes-skopt backend.

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

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

# We set the x parameter conditional on the use_high parameter and add randomness.
import random
use_high = bb.randbool("use high", guess=False)
assert isinstance(use_high, bool), type(use_high)
if use_high:
    x = bb.randrange("x high", 10, 20) * random.random()
else:
    x = bb.randrange("x low", 10) * random.random()

# We set x as the thing we want to optimize.
bb.maximize(x)

# Finally, we'll print out the value we used for debugging purposes.
if __name__ == "__main__":
    print(repr(x))
Ejemplo n.º 4
0
"""
Simple example using json instead of pickle for enhanced cross-platform compatibility.

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

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


# Set up log uniform and log normal parameters.
x0 = bb.loguniform("x0", 1, 10, guess=5)
x1 = bb.lognormvariate("x1", 0, 1, guess=1)


# Set the goal to be the sum.
y = x0 + x1
bb.minimize(y)


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