Note
Go to the end to download the full example code.
How to Implement Your Sampler with OptunaHub
OptunaHub is an Optuna package registry, which is a platform to share algorithms developed by contributors. This recipe shows how to implement your own algorithm with OptunaHub.
Here, we show how to implement your own sampler, i.e., optimizaiton algorithm. If you want to implement algorithms other than a sampler, please refer to the other recipes.
Usually, Optuna provides BaseSampler
class to implement your own sampler.
However, it is a bit complicated to implement a sampler from scratch.
Instead, in OptunaHub, you can use optunahub.samplers.SimpleBaseSampler class, which is a sampler template that can be easily extended.
You need to install optuna
to implement your own sampler, and optunahub
to use the template SimpleBaseSampler
.
$ pip install optuna optunahub
First of all, import optuna
, optunahub
, and other required modules.
from __future__ import annotations
from typing import Any
import numpy as np
import optuna
import optunahub
Next, define your own sampler class by inheriting SimpleBaseSampler
class.
In this example, we implement a sampler that returns a random value.
class MySampler(optunahub.samplers.SimpleBaseSampler):
# By default, search space will be estimated automatically like Optuna's built-in samplers.
# You can fix the search spacd by `search_space` argument of `SimpleSampler` class.
def __init__(
self, search_space: dict[str, optuna.distributions.BaseDistribution] | None = None
) -> None:
super().__init__(search_space)
self._rng = np.random.RandomState()
# You need to implement sample_relative method.
# This method returns a dictionary of hyperparameters.
# The keys of the dictionary are the names of the hyperparameters, which must be the same as the keys of the search_space argument.
# The values of the dictionary are the values of the hyperparameters.
# In this example, sample_relative method returns a dictionary of randomly sampled hyperparameters.
def sample_relative(
self,
study: optuna.study.Study,
trial: optuna.trial.FrozenTrial,
search_space: dict[str, optuna.distributions.BaseDistribution],
) -> dict[str, Any]:
# search_space argument must be identical to search_space argument input to __init__ method.
# This method is automatically invoked by Optuna and SimpleBaseSampler.
# If search space is empty, all parameter values are sampled randomly by SimpleBaseSampler.
if search_space == {}:
return {}
params = {} # type: dict[str, Any]
for n, d in search_space.items():
if isinstance(d, optuna.distributions.FloatDistribution):
params[n] = self._rng.uniform(d.low, d.high)
elif isinstance(d, optuna.distributions.IntDistribution):
params[n] = self._rng.randint(d.low, d.high)
elif isinstance(d, optuna.distributions.CategoricalDistribution):
params[n] = d.choices[self._rng.randint(len(d.choices))]
else:
raise NotImplementedError
return params
Here, as an example, the objective function is defined as follows.
def objective(trial: optuna.trial.Trial) -> float:
x = trial.suggest_float("x", -10, 10)
y = trial.suggest_int("y", -10, 10)
z = trial.suggest_categorical("z", ["a", "b", "c"])
return x**2 + y**2 + {"a": -10, "b": 0, "c": 10}[z] ** 2
This sampler can be used in the same way as other Optuna samplers.
In the following example, we create a study and optimize it using MySampler
class.
sampler = MySampler()
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=100)
[I 2025-03-28 10:20:52,414] A new study created in memory with name: no-name-4191141f-53b0-4e5e-afd8-50e0c0faa7e9
[I 2025-03-28 10:20:52,415] Trial 0 finished with value: 274.82100975736364 and parameters: {'x': -8.649913858378222, 'y': -10, 'z': 'a'}. Best is trial 0 with value: 274.82100975736364.
[I 2025-03-28 10:20:52,415] Trial 1 finished with value: 0.10024618790298799 and parameters: {'x': 0.31661678398813287, 'y': 0, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,416] Trial 2 finished with value: 164.0144121023427 and parameters: {'x': 0.12005041583730858, 'y': 8, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,416] Trial 3 finished with value: 73.0650589813516 and parameters: {'x': 6.0881079968535055, 'y': -6, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,417] Trial 4 finished with value: 184.56353651932662 and parameters: {'x': -1.887733169525454, 'y': 9, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,417] Trial 5 finished with value: 115.2266212121662 and parameters: {'x': 9.498769457785897, 'y': -5, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,417] Trial 6 finished with value: 136.011709866603 and parameters: {'x': 0.10821213704110555, 'y': -6, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,418] Trial 7 finished with value: 190.06080722380995 and parameters: {'x': -9.490037261455296, 'y': -10, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,418] Trial 8 finished with value: 128.41660652219397 and parameters: {'x': -4.4064278641768295, 'y': -3, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,419] Trial 9 finished with value: 124.41308674312356 and parameters: {'x': -3.9259504254541415, 'y': -3, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,419] Trial 10 finished with value: 131.59814940546028 and parameters: {'x': 5.253394084347782, 'y': 2, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,419] Trial 11 finished with value: 84.07647520831704 and parameters: {'x': 1.753988371773609, 'y': 9, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,420] Trial 12 finished with value: 111.81760134605834 and parameters: {'x': 3.2890122143370544, 'y': -1, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,420] Trial 13 finished with value: 200.05019716655463 and parameters: {'x': 4.364653155355489, 'y': 9, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,421] Trial 14 finished with value: 60.42912839087118 and parameters: {'x': -5.952237259289248, 'y': 5, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,421] Trial 15 finished with value: 201.4704657960206 and parameters: {'x': 1.2126276411250885, 'y': -10, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,421] Trial 16 finished with value: 90.65213227349754 and parameters: {'x': 9.036156941615033, 'y': 3, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,422] Trial 17 finished with value: 156.8758526915849 and parameters: {'x': -6.919237869273241, 'y': -3, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,422] Trial 18 finished with value: 193.60163851983458 and parameters: {'x': -8.80917921941849, 'y': 4, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,422] Trial 19 finished with value: 101.62887016543343 and parameters: {'x': 0.7930133450538079, 'y': -1, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,423] Trial 20 finished with value: 135.11994679396696 and parameters: {'x': 3.1811863815197867, 'y': 5, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,423] Trial 21 finished with value: 187.36385407405643 and parameters: {'x': 2.5226680467426625, 'y': 9, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,423] Trial 22 finished with value: 183.47931410005566 and parameters: {'x': 1.5745837862926422, 'y': -9, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,424] Trial 23 finished with value: 55.38104476388685 and parameters: {'x': -2.526072992588862, 'y': 7, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,424] Trial 24 finished with value: 122.0350481411546 and parameters: {'x': 4.694150417397658, 'y': -10, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,425] Trial 25 finished with value: 200.01879352647774 and parameters: {'x': 0.13708948346876682, 'y': -10, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,425] Trial 26 finished with value: 116.06584328601593 and parameters: {'x': -0.25659946612556794, 'y': -4, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,425] Trial 27 finished with value: 75.18627069004383 and parameters: {'x': -8.613145226341178, 'y': 1, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,426] Trial 28 finished with value: 115.43282258215649 and parameters: {'x': -2.536300964427623, 'y': -3, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,426] Trial 29 finished with value: 68.95243192038853 and parameters: {'x': -4.4668145160045025, 'y': -7, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,426] Trial 30 finished with value: 134.44135108238953 and parameters: {'x': -4.294339423286138, 'y': 4, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,427] Trial 31 finished with value: 236.57798358386077 and parameters: {'x': -7.455064291061531, 'y': 9, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,427] Trial 32 finished with value: 144.07890348738283 and parameters: {'x': 9.75084116819584, 'y': 7, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,427] Trial 33 finished with value: 108.11465668702856 and parameters: {'x': 2.0284616553015145, 'y': -2, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,428] Trial 34 finished with value: 234.56321728989252 and parameters: {'x': -9.250038772345363, 'y': -7, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,428] Trial 35 finished with value: 298.2716500844439 and parameters: {'x': 9.913205842937181, 'y': -10, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,429] Trial 36 finished with value: 123.82404140295212 and parameters: {'x': 4.452419724481523, 'y': 2, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,429] Trial 37 finished with value: 81.0027160493243 and parameters: {'x': 0.05211573010425674, 'y': 9, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,429] Trial 38 finished with value: 17.692522647425847 and parameters: {'x': 1.3009698872094795, 'y': -4, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,430] Trial 39 finished with value: 94.66044185843579 and parameters: {'x': 8.346283116359988, 'y': 5, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,430] Trial 40 finished with value: 10.71505971909712 and parameters: {'x': -2.5913432268028718, 'y': -2, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,430] Trial 41 finished with value: 172.72806016886597 and parameters: {'x': -8.469242006748063, 'y': -1, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,431] Trial 42 finished with value: 149.02683645964314 and parameters: {'x': -0.16381837394852816, 'y': -7, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,432] Trial 43 finished with value: 105.65481431108691 and parameters: {'x': 9.46862261953062, 'y': -4, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,432] Trial 44 finished with value: 161.82103184117668 and parameters: {'x': -7.267807911686761, 'y': 3, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,433] Trial 45 finished with value: 84.13749423932185 and parameters: {'x': 1.7712973322742442, 'y': -9, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,433] Trial 46 finished with value: 118.46687742768195 and parameters: {'x': -4.179339353017646, 'y': 1, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,433] Trial 47 finished with value: 126.07610984702681 and parameters: {'x': 1.0373571453587278, 'y': 5, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,434] Trial 48 finished with value: 149.00014551530757 and parameters: {'x': 0.012062972583477105, 'y': -7, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,434] Trial 49 finished with value: 168.6065900096691 and parameters: {'x': 8.282909513550724, 'y': -10, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,434] Trial 50 finished with value: 36.027803287739864 and parameters: {'x': 0.16674317899051871, 'y': -6, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,435] Trial 51 finished with value: 150.36905776598456 and parameters: {'x': 6.809482929414287, 'y': -2, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,435] Trial 52 finished with value: 107.3771746420105 and parameters: {'x': -1.8377090743669129, 'y': 2, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,435] Trial 53 finished with value: 150.084569799818 and parameters: {'x': 3.7529414863301582, 'y': 6, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,436] Trial 54 finished with value: 116.29916169636357 and parameters: {'x': 0.5469567591351048, 'y': 4, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,436] Trial 55 finished with value: 181.14002261694935 and parameters: {'x': -0.37419596062669136, 'y': 9, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,437] Trial 56 finished with value: 190.6871393050669 and parameters: {'x': -6.456557852684888, 'y': 7, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,437] Trial 57 finished with value: 169.03422801533242 and parameters: {'x': -9.382655701630132, 'y': 9, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,437] Trial 58 finished with value: 171.7923946618431 and parameters: {'x': 2.79148610274941, 'y': -8, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,438] Trial 59 finished with value: 143.5917241247652 and parameters: {'x': -6.526233532809349, 'y': 1, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,438] Trial 60 finished with value: 158.68104179363985 and parameters: {'x': 3.111437255295346, 'y': 7, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,438] Trial 61 finished with value: 227.0711086287094 and parameters: {'x': 6.787570156448432, 'y': -9, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,439] Trial 62 finished with value: 172.00725956599118 and parameters: {'x': 8.24665141533163, 'y': -2, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,439] Trial 63 finished with value: 63.01662229090621 and parameters: {'x': 3.7438779748953106, 'y': -7, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,440] Trial 64 finished with value: 110.43940861040191 and parameters: {'x': -3.2310073677418183, 'y': 0, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,440] Trial 65 finished with value: 43.09437072266461 and parameters: {'x': -4.253747844273872, 'y': -5, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,440] Trial 66 finished with value: 156.27089350769106 and parameters: {'x': -2.6964594392816394, 'y': -7, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,441] Trial 67 finished with value: 218.08272503704262 and parameters: {'x': -9.647938900979971, 'y': -5, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,441] Trial 68 finished with value: 109.20930643618851 and parameters: {'x': 0.4575002034846616, 'y': -3, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,441] Trial 69 finished with value: 159.43475129398067 and parameters: {'x': -7.101742834965279, 'y': -3, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,442] Trial 70 finished with value: 139.09541566498777 and parameters: {'x': 3.7543861901764686, 'y': -5, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,442] Trial 71 finished with value: 151.48105161775342 and parameters: {'x': -3.934596754148183, 'y': 6, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,442] Trial 72 finished with value: 73.87541971530997 and parameters: {'x': -8.536710122483367, 'y': -1, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,443] Trial 73 finished with value: 16.00297997355705 and parameters: {'x': -0.05458913405660937, 'y': 4, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,443] Trial 74 finished with value: 181.0004935633675 and parameters: {'x': -0.022216286087060055, 'y': 9, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,444] Trial 75 finished with value: 187.53961847271898 and parameters: {'x': 4.851764470037576, 'y': 8, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,444] Trial 76 finished with value: 45.315971636133995 and parameters: {'x': -3.052207665958198, 'y': 6, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,444] Trial 77 finished with value: 194.03710034699102 and parameters: {'x': -9.221556286603201, 'y': 3, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,445] Trial 78 finished with value: 164.03402746007052 and parameters: {'x': 0.1844653356880972, 'y': -8, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,445] Trial 79 finished with value: 118.03987198617276 and parameters: {'x': -6.086039104883632, 'y': 9, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,446] Trial 80 finished with value: 159.45367623034707 and parameters: {'x': -4.842899568476213, 'y': -6, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,446] Trial 81 finished with value: 108.17027383834018 and parameters: {'x': -2.0421248341715508, 'y': 2, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,447] Trial 82 finished with value: 243.78162818284235 and parameters: {'x': -8.93205621247663, 'y': 8, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,447] Trial 83 finished with value: 55.06668847353713 and parameters: {'x': 5.483309992471439, 'y': -5, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,447] Trial 84 finished with value: 66.03084826930473 and parameters: {'x': -1.4250783379536465, 'y': 8, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,448] Trial 85 finished with value: 82.80077998794096 and parameters: {'x': -8.59073803511322, 'y': -3, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,448] Trial 86 finished with value: 22.214915490875335 and parameters: {'x': -2.4929732230562234, 'y': -4, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,448] Trial 87 finished with value: 54.02583497953955 and parameters: {'x': -5.387562990772317, 'y': -5, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,449] Trial 88 finished with value: 123.2232973257326 and parameters: {'x': 9.910766737530079, 'y': 5, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,449] Trial 89 finished with value: 192.82148789953794 and parameters: {'x': -9.155407576920753, 'y': -3, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,450] Trial 90 finished with value: 170.05280745102993 and parameters: {'x': -2.4602454046354687, 'y': 8, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,450] Trial 91 finished with value: 11.959919325358042 and parameters: {'x': 3.3105768870935535, 'y': -1, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,450] Trial 92 finished with value: 130.81845012539696 and parameters: {'x': -3.849474006328264, 'y': -4, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,451] Trial 93 finished with value: 134.0210397497954 and parameters: {'x': 5.832755759484138, 'y': 0, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,451] Trial 94 finished with value: 26.65173447509138 and parameters: {'x': -4.201396729076103, 'y': -3, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,451] Trial 95 finished with value: 141.85294736220908 and parameters: {'x': -4.105234142190803, 'y': 5, 'z': 'a'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,452] Trial 96 finished with value: 19.964065254341847 and parameters: {'x': -3.995505631874625, 'y': -2, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,452] Trial 97 finished with value: 196.35316401710395 and parameters: {'x': 9.815964752234187, 'y': -10, 'z': 'b'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,452] Trial 98 finished with value: 125.06730301941862 and parameters: {'x': 0.25942825485790877, 'y': -5, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
[I 2025-03-28 10:20:52,453] Trial 99 finished with value: 227.55160377294237 and parameters: {'x': -6.822873571519727, 'y': -9, 'z': 'c'}. Best is trial 1 with value: 0.10024618790298799.
The best parameters can be fetched as follows.
best_params = study.best_params
best_value = study.best_value
print(f"Best params: {best_params}, Best value: {best_value}")
Best params: {'x': 0.31661678398813287, 'y': 0, 'z': 'b'}, Best value: 0.10024618790298799
We can see that best_params
value found by Optuna is close to the optimal value {"x":0, "y": 0, "z": "b"}
.
In the above examples, search space is estimated at the first trial and updated dynamically through optimization.
If your sampler requires the search space to be fixed before optimization, you can pass the search space to the sampler at initialization.
Passing the search space also allows the sampler to avoid the overhead of estimating the search space.
See the documentation for more information about the optuna.distributions
to define search space.
sampler = MySampler(
search_space={
"x": optuna.distributions.FloatDistribution(-10, 10),
"y": optuna.distributions.IntDistribution(-10, 10),
"z": optuna.distributions.CategoricalDistribution(["a", "b", "c"]),
}
)
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=100)
[I 2025-03-28 10:20:52,454] A new study created in memory with name: no-name-70cd5203-a400-422f-9340-fd339d50336f
[I 2025-03-28 10:20:52,454] Trial 0 finished with value: 81.07815403218574 and parameters: {'x': -0.2795604267161984, 'y': -9, 'z': 'b'}. Best is trial 0 with value: 81.07815403218574.
[I 2025-03-28 10:20:52,455] Trial 1 finished with value: 219.74717233558837 and parameters: {'x': -6.224722671379695, 'y': 9, 'z': 'a'}. Best is trial 0 with value: 81.07815403218574.
[I 2025-03-28 10:20:52,455] Trial 2 finished with value: 205.80591382119493 and parameters: {'x': 6.465749285364762, 'y': 8, 'z': 'a'}. Best is trial 0 with value: 81.07815403218574.
[I 2025-03-28 10:20:52,455] Trial 3 finished with value: 242.29936055691206 and parameters: {'x': -8.848692590259425, 'y': 8, 'z': 'c'}. Best is trial 0 with value: 81.07815403218574.
[I 2025-03-28 10:20:52,456] Trial 4 finished with value: 158.45692920836288 and parameters: {'x': 7.580034908122975, 'y': 1, 'z': 'c'}. Best is trial 0 with value: 81.07815403218574.
[I 2025-03-28 10:20:52,456] Trial 5 finished with value: 89.31812391023877 and parameters: {'x': 6.349655416653629, 'y': 7, 'z': 'b'}. Best is trial 0 with value: 81.07815403218574.
[I 2025-03-28 10:20:52,456] Trial 6 finished with value: 58.54680252037526 and parameters: {'x': -7.385580716529693, 'y': 2, 'z': 'b'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,457] Trial 7 finished with value: 100.63843937286987 and parameters: {'x': -4.431527882443014, 'y': 9, 'z': 'b'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,457] Trial 8 finished with value: 116.00220461898353 and parameters: {'x': 0.04695337031062863, 'y': -4, 'z': 'c'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,457] Trial 9 finished with value: 203.86956381868413 and parameters: {'x': -7.407399261460403, 'y': 7, 'z': 'c'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,458] Trial 10 finished with value: 168.93662518095786 and parameters: {'x': 7.2757559869032065, 'y': -4, 'z': 'c'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,458] Trial 11 finished with value: 185.01740531311867 and parameters: {'x': 2.0043466050358383, 'y': 9, 'z': 'c'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,458] Trial 12 finished with value: 120.5907095399271 and parameters: {'x': -2.1425941146019962, 'y': 4, 'z': 'c'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,458] Trial 13 finished with value: 116.18009719966625 and parameters: {'x': -3.89616442153899, 'y': 1, 'z': 'a'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,459] Trial 14 finished with value: 181.07724989482688 and parameters: {'x': 8.06704716081584, 'y': 4, 'z': 'c'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,459] Trial 15 finished with value: 141.65691762432417 and parameters: {'x': 2.378427552885343, 'y': -6, 'z': 'c'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,459] Trial 16 finished with value: 189.5355261148479 and parameters: {'x': -2.921562272971072, 'y': -9, 'z': 'c'}. Best is trial 6 with value: 58.54680252037526.
[I 2025-03-28 10:20:52,460] Trial 17 finished with value: 33.7448122915099 and parameters: {'x': 5.453880480126962, 'y': 2, 'z': 'b'}. Best is trial 17 with value: 33.7448122915099.
[I 2025-03-28 10:20:52,460] Trial 18 finished with value: 122.23940937532328 and parameters: {'x': 3.638599919656361, 'y': 3, 'z': 'a'}. Best is trial 17 with value: 33.7448122915099.
[I 2025-03-28 10:20:52,460] Trial 19 finished with value: 88.90691547821652 and parameters: {'x': 6.317192056461202, 'y': 7, 'z': 'b'}. Best is trial 17 with value: 33.7448122915099.
[I 2025-03-28 10:20:52,461] Trial 20 finished with value: 103.8343308395475 and parameters: {'x': 1.9581447442790072, 'y': 0, 'z': 'a'}. Best is trial 17 with value: 33.7448122915099.
[I 2025-03-28 10:20:52,461] Trial 21 finished with value: 4.292818302362598 and parameters: {'x': 0.5411268819441499, 'y': 2, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,461] Trial 22 finished with value: 179.20723547919584 and parameters: {'x': -3.899645558149592, 'y': -8, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,462] Trial 23 finished with value: 137.66559605116862 and parameters: {'x': 1.2905797345257817, 'y': 6, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,462] Trial 24 finished with value: 109.04135892428978 and parameters: {'x': -0.2033689363934048, 'y': -3, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,462] Trial 25 finished with value: 149.0969740091042 and parameters: {'x': 6.332217147974649, 'y': 3, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,462] Trial 26 finished with value: 128.55163748574228 and parameters: {'x': -1.8845788616405237, 'y': 5, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,463] Trial 27 finished with value: 122.3326777792211 and parameters: {'x': -2.5164812296580124, 'y': -4, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,463] Trial 28 finished with value: 138.66127896298312 and parameters: {'x': -3.6961167409841273, 'y': -5, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,463] Trial 29 finished with value: 198.6968830487241 and parameters: {'x': -9.470843840372625, 'y': 3, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,464] Trial 30 finished with value: 88.46387454664419 and parameters: {'x': 2.732009250834299, 'y': -9, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,464] Trial 31 finished with value: 158.70531062332296 and parameters: {'x': -7.050199332169478, 'y': -3, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,464] Trial 32 finished with value: 135.14675544016183 and parameters: {'x': -5.113389818912872, 'y': 3, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,465] Trial 33 finished with value: 11.61768777512366 and parameters: {'x': -2.760015901244712, 'y': 2, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,465] Trial 34 finished with value: 156.57255895428287 and parameters: {'x': 7.521473190425056, 'y': 0, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,465] Trial 35 finished with value: 247.74971030419016 and parameters: {'x': -9.937288880987115, 'y': -7, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,466] Trial 36 finished with value: 55.16878434723232 and parameters: {'x': 2.4837037559323214, 'y': 7, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,466] Trial 37 finished with value: 122.89769921742159 and parameters: {'x': 4.67949775268902, 'y': -1, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,466] Trial 38 finished with value: 146.50860247293065 and parameters: {'x': 6.519862151374877, 'y': -2, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,466] Trial 39 finished with value: 29.201174522390858 and parameters: {'x': -2.0496766872828642, 'y': -5, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,467] Trial 40 finished with value: 90.18210427934315 and parameters: {'x': -9.010111224582255, 'y': -3, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,467] Trial 41 finished with value: 57.278106894628394 and parameters: {'x': 2.8771699453852904, 'y': 7, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,467] Trial 42 finished with value: 196.84001278007074 and parameters: {'x': 5.730620627826513, 'y': 8, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,468] Trial 43 finished with value: 133.22228071603695 and parameters: {'x': 2.867451955314502, 'y': 5, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,468] Trial 44 finished with value: 129.55937433933724 and parameters: {'x': -5.055627986643918, 'y': -2, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,468] Trial 45 finished with value: 27.641142236254346 and parameters: {'x': 4.317538909639882, 'y': 3, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,469] Trial 46 finished with value: 138.56735097308336 and parameters: {'x': -1.6022955323795163, 'y': 6, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,469] Trial 47 finished with value: 217.65421365048422 and parameters: {'x': 4.201691760527444, 'y': -10, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,469] Trial 48 finished with value: 166.49440388548413 and parameters: {'x': 1.579368191867923, 'y': -8, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,470] Trial 49 finished with value: 215.12022719414242 and parameters: {'x': 9.955914181738532, 'y': 4, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,470] Trial 50 finished with value: 126.96254687034539 and parameters: {'x': -7.934894257036158, 'y': 8, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,470] Trial 51 finished with value: 10.9304256630158 and parameters: {'x': 2.6325701629806186, 'y': 2, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,470] Trial 52 finished with value: 133.1196364253878 and parameters: {'x': 2.849497574202829, 'y': -5, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,471] Trial 53 finished with value: 142.53176872240965 and parameters: {'x': -6.444514622716722, 'y': 1, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,471] Trial 54 finished with value: 116.48750201851612 and parameters: {'x': -3.9354163716837043, 'y': 1, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,471] Trial 55 finished with value: 116.01244800031048 and parameters: {'x': 0.11157060683925835, 'y': -4, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,472] Trial 56 finished with value: 16.0759750494593 and parameters: {'x': -0.2756357187653613, 'y': 4, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,472] Trial 57 finished with value: 149.99368731498424 and parameters: {'x': -0.9968386604582662, 'y': 7, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,472] Trial 58 finished with value: 102.68417615251943 and parameters: {'x': -4.656627121911248, 'y': -9, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,473] Trial 59 finished with value: 175.26640033078488 and parameters: {'x': 7.089880135149315, 'y': -5, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,473] Trial 60 finished with value: 127.96723061218302 and parameters: {'x': -6.853264230436691, 'y': -9, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,473] Trial 61 finished with value: 236.02702128188082 and parameters: {'x': -6.002251351108249, 'y': -10, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,474] Trial 62 finished with value: 247.5061580776674 and parameters: {'x': 9.138170390054423, 'y': -8, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,474] Trial 63 finished with value: 142.98892642615306 and parameters: {'x': 5.830002266393475, 'y': 3, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,474] Trial 64 finished with value: 154.41251982076503 and parameters: {'x': 2.326482284644573, 'y': 7, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,475] Trial 65 finished with value: 120.75183361756785 and parameters: {'x': -3.428094750377804, 'y': 3, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,475] Trial 66 finished with value: 227.19464365572867 and parameters: {'x': -9.54958866421631, 'y': -6, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,475] Trial 67 finished with value: 141.07411201678033 and parameters: {'x': 6.08885145300658, 'y': 2, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,475] Trial 68 finished with value: 154.10304150133265 and parameters: {'x': -2.2589912574714965, 'y': -7, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,476] Trial 69 finished with value: 165.0433923868049 and parameters: {'x': 5.389192183138851, 'y': -6, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,476] Trial 70 finished with value: 104.84953721597105 and parameters: {'x': 0.9217034316801964, 'y': -2, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,476] Trial 71 finished with value: 193.34846122399483 and parameters: {'x': 9.452431497979493, 'y': -2, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,477] Trial 72 finished with value: 157.88047208045862 and parameters: {'x': 4.677656686895546, 'y': 6, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,477] Trial 73 finished with value: 238.02486271103857 and parameters: {'x': -8.603770261405089, 'y': 8, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,477] Trial 74 finished with value: 248.6970016290544 and parameters: {'x': -8.227818764961611, 'y': -9, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,478] Trial 75 finished with value: 147.4839086001144 and parameters: {'x': 6.890856884315216, 'y': 0, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,478] Trial 76 finished with value: 176.46328679585017 and parameters: {'x': -8.686960734103163, 'y': 1, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,478] Trial 77 finished with value: 166.96156263143956 and parameters: {'x': 7.138736767204655, 'y': -4, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,479] Trial 78 finished with value: 208.82741044794034 and parameters: {'x': -2.9710958328435533, 'y': -10, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,479] Trial 79 finished with value: 107.86474133734644 and parameters: {'x': 1.9658945387142328, 'y': -2, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,479] Trial 80 finished with value: 193.27525077894956 and parameters: {'x': 8.262883926266273, 'y': -5, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,479] Trial 81 finished with value: 110.28840962822241 and parameters: {'x': -1.135081331104697, 'y': -3, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,480] Trial 82 finished with value: 84.369528984416 and parameters: {'x': -1.8356276813166659, 'y': 9, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,480] Trial 83 finished with value: 139.1113394098512 and parameters: {'x': -1.7638989227989228, 'y': 6, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,480] Trial 84 finished with value: 174.67792588178963 and parameters: {'x': 8.407016467319998, 'y': -2, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,481] Trial 85 finished with value: 67.56099246068945 and parameters: {'x': 1.8870592096406096, 'y': 8, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,481] Trial 86 finished with value: 106.35076006907757 and parameters: {'x': 8.387535995098773, 'y': 6, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,481] Trial 87 finished with value: 41.600264259187234 and parameters: {'x': -6.1319054346252955, 'y': 2, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,482] Trial 88 finished with value: 169.59367215351094 and parameters: {'x': -8.34228219095416, 'y': 0, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,482] Trial 89 finished with value: 67.94388355715651 and parameters: {'x': 5.651892033395233, 'y': -6, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,482] Trial 90 finished with value: 101.01532132481546 and parameters: {'x': -0.12377933921081663, 'y': 1, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,483] Trial 91 finished with value: 191.7355952960363 and parameters: {'x': -3.2765218290187414, 'y': 9, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,483] Trial 92 finished with value: 34.50915785444021 and parameters: {'x': -3.0836922437948004, 'y': -5, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,483] Trial 93 finished with value: 7.1574707457393965 and parameters: {'x': -2.48142514409349, 'y': 1, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,483] Trial 94 finished with value: 48.7078010617493 and parameters: {'x': 4.869065727811579, 'y': 5, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,484] Trial 95 finished with value: 86.59664188423538 and parameters: {'x': 9.251845323190146, 'y': 1, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,484] Trial 96 finished with value: 172.8236224328578 and parameters: {'x': 2.9704582866719083, 'y': 8, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,484] Trial 97 finished with value: 35.11326806748776 and parameters: {'x': -3.1801364856697205, 'y': 5, 'z': 'b'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,485] Trial 98 finished with value: 202.53993527212094 and parameters: {'x': 1.5937174379798194, 'y': -10, 'z': 'a'}. Best is trial 21 with value: 4.292818302362598.
[I 2025-03-28 10:20:52,485] Trial 99 finished with value: 106.01168183027953 and parameters: {'x': -1.4183376996609525, 'y': 2, 'z': 'c'}. Best is trial 21 with value: 4.292818302362598.
In the next recipe, we will show how to register your sampler to OptunaHub. Let’s move on to How to Register Your Package with OptunaHub. See the User-Defined Sampler documentation for more information to implement a sampler.
Total running time of the script: (0 minutes 0.240 seconds)