Lightweight, versatile, and platform agnostic architecture

Optuna is entirely written in Python and has few dependencies. This means that we can quickly move to the real example once you get interested in Optuna.

Quadratic Function Example

Usually, Optuna is used to optimize hyperparameters, but as an example, let’s optimize a simple quadratic function: \((x - 2)^2\).

First of all, import optuna.

import optuna

In optuna, conventionally functions to be optimized are named objective.

def objective(trial):
    x = trial.suggest_float("x", -10, 10)
    return (x - 2) ** 2

This function returns the value of \((x - 2)^2\). Our goal is to find the value of x that minimizes the output of the objective function. This is the “optimization.” During the optimization, Optuna repeatedly calls and evaluates the objective function with different values of x.

A Trial object corresponds to a single execution of the objective function and is internally instantiated upon each invocation of the function.

The suggest APIs (for example, suggest_float()) are called inside the objective function to obtain parameters for a trial. suggest_float() selects parameters uniformly within the range provided. In our example, from \(-10\) to \(10\).

To start the optimization, we create a study object and pass the objective function to method optimize() as follows.

study = optuna.create_study()
study.optimize(objective, n_trials=100)

You can get the best parameter as follows.

best_params = study.best_params
found_x = best_params["x"]
print("Found x: {}, (x - 2)^2: {}".format(found_x, (found_x - 2) ** 2))

Out:

Found x: 2.021485302532984, (x - 2)^2: 0.00046161822493385714

We can see that the x value found by Optuna is close to the optimal value of 2.

Note

When used to search for hyperparameters in machine learning, usually the objective function would return the loss or accuracy of the model.

Study Object

Let us clarify the terminology in Optuna as follows:

  • Trial: A single call of the objective function

  • Study: An optimization session, which is a set of trials

  • Parameter: A variable whose value is to be optimized, such as x in the above example

In Optuna, we use the study object to manage optimization. Method create_study() returns a study object. A study object has useful properties for analyzing the optimization outcome.

To get the dictionary of parameter name and parameter values:

Out:

{'x': 2.021485302532984}

To get the best observed value of the objective function:

study.best_value

Out:

0.00046161822493385714

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=55, values=[0.00046161822493385714], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 502591), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 505197), params={'x': 2.021485302532984}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=55, state=TrialState.COMPLETE, value=None)

To get all trials:

study.trials

Out:

[FrozenTrial(number=0, values=[38.851324598632196], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 365713), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 366070), params={'x': 8.233083073297852}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=0, state=TrialState.COMPLETE, value=None), FrozenTrial(number=1, values=[38.82443117017796], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 366354), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 366602), params={'x': -4.230925386343345}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=1, state=TrialState.COMPLETE, value=None), FrozenTrial(number=2, values=[62.99814940906395], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 366834), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 367051), params={'x': -5.937137356066351}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=2, state=TrialState.COMPLETE, value=None), FrozenTrial(number=3, values=[51.37844115335894], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 367272), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 367490), params={'x': -5.167875637408823}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=3, state=TrialState.COMPLETE, value=None), FrozenTrial(number=4, values=[8.681363274606419], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 367722), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 367937), params={'x': -0.9464153262237858}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=4, state=TrialState.COMPLETE, value=None), FrozenTrial(number=5, values=[33.18657641176134], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 368161), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 368380), params={'x': -3.760779149712419}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=5, state=TrialState.COMPLETE, value=None), FrozenTrial(number=6, values=[47.519902573285485], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 368603), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 368825), params={'x': 8.893468109252808}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=6, state=TrialState.COMPLETE, value=None), FrozenTrial(number=7, values=[73.05753181552939], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 369046), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 369270), params={'x': -6.547369877075018}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=7, state=TrialState.COMPLETE, value=None), FrozenTrial(number=8, values=[20.102114570797514], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 369489), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 369713), params={'x': 6.483538175458921}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=8, state=TrialState.COMPLETE, value=None), FrozenTrial(number=9, values=[33.5087987403766], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 369928), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 370154), params={'x': -3.7886784968917215}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=9, state=TrialState.COMPLETE, value=None), FrozenTrial(number=10, values=[0.5512392567432159], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 370384), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 375659), params={'x': 2.742454885325173}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=10, state=TrialState.COMPLETE, value=None), FrozenTrial(number=11, values=[1.0738533828484749], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 375949), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 378538), params={'x': 3.0362689722501948}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=11, state=TrialState.COMPLETE, value=None), FrozenTrial(number=12, values=[3.482332259182962], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 378804), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 381444), params={'x': 3.8661008169932733}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=12, state=TrialState.COMPLETE, value=None), FrozenTrial(number=13, values=[0.7177061333676288], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 381715), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 384230), params={'x': 2.847175385246543}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=13, state=TrialState.COMPLETE, value=None), FrozenTrial(number=14, values=[0.9942190427322382], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 384485), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 387000), params={'x': 1.002894668185834}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=14, state=TrialState.COMPLETE, value=None), FrozenTrial(number=15, values=[8.68948183897085], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 387257), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 389771), params={'x': 4.947792706241545}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=15, state=TrialState.COMPLETE, value=None), FrozenTrial(number=16, values=[134.6215320790876], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 390024), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 392612), params={'x': -9.602651941650564}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=16, state=TrialState.COMPLETE, value=None), FrozenTrial(number=17, values=[3.1464042771261034], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 392866), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 395374), params={'x': 0.22618933447616696}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=17, state=TrialState.COMPLETE, value=None), FrozenTrial(number=18, values=[11.467981647507544], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 395627), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 398134), params={'x': -1.38644085250393}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=18, state=TrialState.COMPLETE, value=None), FrozenTrial(number=19, values=[0.008653404823162389], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 398383), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 400959), params={'x': 2.0930236788305128}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=19, state=TrialState.COMPLETE, value=None), FrozenTrial(number=20, values=[18.01125390211232], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 401222), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 403768), params={'x': 6.243966764963213}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=20, state=TrialState.COMPLETE, value=None), FrozenTrial(number=21, values=[0.038611993955441244], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 404029), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 406644), params={'x': 2.1964993484860478}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=21, state=TrialState.COMPLETE, value=None), FrozenTrial(number=22, values=[0.25541210187471963], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 406903), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 409433), params={'x': 1.4946168761476897}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=22, state=TrialState.COMPLETE, value=None), FrozenTrial(number=23, values=[1.5890756168364915], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 409688), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 412277), params={'x': 0.7394145737648354}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=23, state=TrialState.COMPLETE, value=None), FrozenTrial(number=24, values=[12.552257821664192], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 412535), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 415042), params={'x': -1.5429165699553513}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=24, state=TrialState.COMPLETE, value=None), FrozenTrial(number=25, values=[0.1579852936720299], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 415300), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 417857), params={'x': 1.602526361035062}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=25, state=TrialState.COMPLETE, value=None), FrozenTrial(number=26, values=[9.370591269679403], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 418119), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 420719), params={'x': 5.061142151171586}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=26, state=TrialState.COMPLETE, value=None), FrozenTrial(number=27, values=[19.994518550289847], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 420993), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 423591), params={'x': -2.471523068294499}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=27, state=TrialState.COMPLETE, value=None), FrozenTrial(number=28, values=[0.0062531898795010685], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 423868), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 426467), params={'x': 2.079077113500058}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=28, state=TrialState.COMPLETE, value=None), FrozenTrial(number=29, values=[62.14046197293451], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 426724), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 429333), params={'x': 9.882922172198233}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=29, state=TrialState.COMPLETE, value=None), FrozenTrial(number=30, values=[28.43398134000475], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 429590), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 432259), params={'x': 7.332352327069616}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=30, state=TrialState.COMPLETE, value=None), FrozenTrial(number=31, values=[0.06785348464377161], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 432514), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 435120), params={'x': 1.739512985652314}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=31, state=TrialState.COMPLETE, value=None), FrozenTrial(number=32, values=[5.9543060175826374], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 435378), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 438004), params={'x': 4.440144671445248}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=32, state=TrialState.COMPLETE, value=None), FrozenTrial(number=33, values=[0.03483728806711248], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 438262), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 440920), params={'x': 2.186647496814483}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=33, state=TrialState.COMPLETE, value=None), FrozenTrial(number=34, values=[0.432672221388222], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 441191), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 443802), params={'x': 2.657778246362877}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=34, state=TrialState.COMPLETE, value=None), FrozenTrial(number=35, values=[5.930525036094112], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 444062), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 446688), params={'x': -0.43526693323218923}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=35, state=TrialState.COMPLETE, value=None), FrozenTrial(number=36, values=[3.1737397400379996], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 446960), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 449555), params={'x': 3.7814992955479942}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=36, state=TrialState.COMPLETE, value=None), FrozenTrial(number=37, values=[18.46551404135899], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 449814), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 452495), params={'x': -2.297151852257375}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=37, state=TrialState.COMPLETE, value=None), FrozenTrial(number=38, values=[14.145031580470805], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 452755), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 455390), params={'x': 5.760988112248004}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=38, state=TrialState.COMPLETE, value=None), FrozenTrial(number=39, values=[4.596097357004901], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 455672), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 458290), params={'x': -0.14385105756087935}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=39, state=TrialState.COMPLETE, value=None), FrozenTrial(number=40, values=[27.32794507919156], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 458560), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 461197), params={'x': 7.227613707916028}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=40, state=TrialState.COMPLETE, value=None), FrozenTrial(number=41, values=[0.2374279988085128], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 461473), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 464096), params={'x': 1.512734160022978}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=41, state=TrialState.COMPLETE, value=None), FrozenTrial(number=42, values=[0.04345913637409893], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 464368), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 467118), params={'x': 2.208468550083937}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=42, state=TrialState.COMPLETE, value=None), FrozenTrial(number=43, values=[0.015271454653946682], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 467393), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 470124), params={'x': 2.1235777271758414}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=43, state=TrialState.COMPLETE, value=None), FrozenTrial(number=44, values=[3.0218870202308787], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 470441), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 473193), params={'x': 3.7383575639755127}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=44, state=TrialState.COMPLETE, value=None), FrozenTrial(number=45, values=[1.5066890160665105], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 473470), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 476166), params={'x': 0.7725273868364677}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=45, state=TrialState.COMPLETE, value=None), FrozenTrial(number=46, values=[1.7212579659042535], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 476440), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 479027), params={'x': 3.3119672122062553}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=46, state=TrialState.COMPLETE, value=None), FrozenTrial(number=47, values=[7.116821353825757], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 479292), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 481901), params={'x': -0.6677371223240415}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=47, state=TrialState.COMPLETE, value=None), FrozenTrial(number=48, values=[7.023895010273338], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 482164), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 484818), params={'x': 4.65026319641528}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=48, state=TrialState.COMPLETE, value=None), FrozenTrial(number=49, values=[0.036486747799833505], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 485081), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 487653), params={'x': 2.191015046003799}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=49, state=TrialState.COMPLETE, value=None), FrozenTrial(number=50, values=[2.3272004859951836], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 487930), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 490657), params={'x': 0.47448353466926374}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=50, state=TrialState.COMPLETE, value=None), FrozenTrial(number=51, values=[0.02735159040837783], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 490929), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 493647), params={'x': 2.165383162408928}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=51, state=TrialState.COMPLETE, value=None), FrozenTrial(number=52, values=[0.5174751409284829], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 493909), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 496516), params={'x': 2.7193574500403}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=52, state=TrialState.COMPLETE, value=None), FrozenTrial(number=53, values=[1.8393199220397134], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 496779), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 499355), params={'x': 3.3562152933954525}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=53, state=TrialState.COMPLETE, value=None), FrozenTrial(number=54, values=[5.115835268677033], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 499618), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 502329), params={'x': 4.2618212282753545}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=54, state=TrialState.COMPLETE, value=None), FrozenTrial(number=55, values=[0.00046161822493385714], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 502591), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 505197), params={'x': 2.021485302532984}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=55, state=TrialState.COMPLETE, value=None), FrozenTrial(number=56, values=[0.7178958760208708], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 505466), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 508144), params={'x': 1.1527126366923257}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=56, state=TrialState.COMPLETE, value=None), FrozenTrial(number=57, values=[13.294049124109284], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 508409), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 511122), params={'x': 5.646100536752831}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=57, state=TrialState.COMPLETE, value=None), FrozenTrial(number=58, values=[4.063443566060526], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 511402), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 514089), params={'x': -0.015798493416573134}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=58, state=TrialState.COMPLETE, value=None), FrozenTrial(number=59, values=[0.08372949808817172], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 514354), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 517028), params={'x': 2.2893604984930938}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=59, state=TrialState.COMPLETE, value=None), FrozenTrial(number=60, values=[8.776631149206835], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 517293), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 519981), params={'x': -0.9625379574288724}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=60, state=TrialState.COMPLETE, value=None), FrozenTrial(number=61, values=[0.002457059040861093], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 520247), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 522981), params={'x': 2.0495687304745753}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=61, state=TrialState.COMPLETE, value=None), FrozenTrial(number=62, values=[1.145005648520743], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 523248), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 526004), params={'x': 0.9299506326712104}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=62, state=TrialState.COMPLETE, value=None), FrozenTrial(number=63, values=[1.4700582469169305], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 526272), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 529009), params={'x': 3.2124595856839644}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=63, state=TrialState.COMPLETE, value=None), FrozenTrial(number=64, values=[0.035618347316050264], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 529281), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 532681), params={'x': 1.8112717633313704}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=64, state=TrialState.COMPLETE, value=None), FrozenTrial(number=65, values=[2.4814148491453376], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 532960), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 536600), params={'x': 0.42474927419621933}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=65, state=TrialState.COMPLETE, value=None), FrozenTrial(number=66, values=[0.9035702097515774], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 536894), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 540019), params={'x': 2.9505631014044136}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=66, state=TrialState.COMPLETE, value=None), FrozenTrial(number=67, values=[3.9983421961745886], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 540323), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 543456), params={'x': 3.9995855060923473}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=67, state=TrialState.COMPLETE, value=None), FrozenTrial(number=68, values=[8.770404195964439], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 543764), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 546462), params={'x': 4.9614868218454795}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=68, state=TrialState.COMPLETE, value=None), FrozenTrial(number=69, values=[0.8592954438439627], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 546745), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 549466), params={'x': 1.0730180995057332}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=69, state=TrialState.COMPLETE, value=None), FrozenTrial(number=70, values=[0.0007177472284796768], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 549744), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 552528), params={'x': 2.026790804924072}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=70, state=TrialState.COMPLETE, value=None), FrozenTrial(number=71, values=[0.0006013265436464351], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 552808), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 555520), params={'x': 1.9754780395635578}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=71, state=TrialState.COMPLETE, value=None), FrozenTrial(number=72, values=[0.169947534819215], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 555812), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 558525), params={'x': 1.5877530657249044}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=72, state=TrialState.COMPLETE, value=None), FrozenTrial(number=73, values=[0.3495649570813133], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 558805), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 561589), params={'x': 2.591240185610986}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=73, state=TrialState.COMPLETE, value=None), FrozenTrial(number=74, values=[2.302435219243239], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 561871), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 564600), params={'x': 3.5173777444141057}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=74, state=TrialState.COMPLETE, value=None), FrozenTrial(number=75, values=[2.9709656350603124], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 564883), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 567599), params={'x': 0.2763510696605551}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=75, state=TrialState.COMPLETE, value=None), FrozenTrial(number=76, values=[0.04822532589891869], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 567903), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 570669), params={'x': 1.7803973454192352}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=76, state=TrialState.COMPLETE, value=None), FrozenTrial(number=77, values=[10.219312307730856], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 570965), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 573740), params={'x': -1.1967659138152196}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=77, state=TrialState.COMPLETE, value=None), FrozenTrial(number=78, values=[0.7496380954242511], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 574022), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 576768), params={'x': 1.1341835671320097}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=78, state=TrialState.COMPLETE, value=None), FrozenTrial(number=79, values=[5.350040586248624], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 577045), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 579783), params={'x': -0.3130154747101508}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=79, state=TrialState.COMPLETE, value=None), FrozenTrial(number=80, values=[16.10037453936069], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 580054), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 582830), params={'x': -2.012527201074242}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=80, state=TrialState.COMPLETE, value=None), FrozenTrial(number=81, values=[0.037986919617900426], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 583102), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 585851), params={'x': 2.1949023335363136}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=81, state=TrialState.COMPLETE, value=None), FrozenTrial(number=82, values=[0.7206331680266291], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 586121), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 589143), params={'x': 2.8489011532720574}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=82, state=TrialState.COMPLETE, value=None), FrozenTrial(number=83, values=[0.0004768637862007422], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 589415), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 592216), params={'x': 2.0218372110444705}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=83, state=TrialState.COMPLETE, value=None), FrozenTrial(number=84, values=[0.028765916976826827], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 592487), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 595228), params={'x': 1.8303948203125069}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=84, state=TrialState.COMPLETE, value=None), FrozenTrial(number=85, values=[0.5282442315655717], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 595497), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 598237), params={'x': 1.2731958781311352}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=85, state=TrialState.COMPLETE, value=None), FrozenTrial(number=86, values=[0.26179646847722643], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 598509), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 601299), params={'x': 2.511660501189242}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=86, state=TrialState.COMPLETE, value=None), FrozenTrial(number=87, values=[105.82420072681134], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 601593), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 604371), params={'x': -8.287089030761392}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=87, state=TrialState.COMPLETE, value=None), FrozenTrial(number=88, values=[3.8603595724812734], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 604644), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 607395), params={'x': 3.964779777094948}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=88, state=TrialState.COMPLETE, value=None), FrozenTrial(number=89, values=[1.3622750081620856], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 607670), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 610458), params={'x': 3.1671653730993246}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=89, state=TrialState.COMPLETE, value=None), FrozenTrial(number=90, values=[1.856473696076613], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 610752), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 613564), params={'x': 0.6374752493710021}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=90, state=TrialState.COMPLETE, value=None), FrozenTrial(number=91, values=[0.036953032497647254], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 613839), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 616602), params={'x': 1.8077682843606517}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=91, state=TrialState.COMPLETE, value=None), FrozenTrial(number=92, values=[0.025470865748322354], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 616879), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 619678), params={'x': 1.8404040547246818}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=92, state=TrialState.COMPLETE, value=None), FrozenTrial(number=93, values=[0.20708712142133112], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 619971), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 622764), params={'x': 2.4550682601778893}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=93, state=TrialState.COMPLETE, value=None), FrozenTrial(number=94, values=[3.789794577702231], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 623040), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 625818), params={'x': 0.0532605264950754}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=94, state=TrialState.COMPLETE, value=None), FrozenTrial(number=95, values=[2.3519427704414775], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 626101), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 628885), params={'x': 3.5336045026151552}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=95, state=TrialState.COMPLETE, value=None), FrozenTrial(number=96, values=[0.31827198235614035], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 629169), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 631976), params={'x': 1.435844008844947}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=96, state=TrialState.COMPLETE, value=None), FrozenTrial(number=97, values=[1.6277738655825256], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 632262), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 635027), params={'x': 0.7241575859133207}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=97, state=TrialState.COMPLETE, value=None), FrozenTrial(number=98, values=[0.9876437738607409], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 635309), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 638088), params={'x': 2.993802683564872}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=98, state=TrialState.COMPLETE, value=None), FrozenTrial(number=99, values=[6.442316206094351], datetime_start=datetime.datetime(2021, 6, 7, 7, 8, 14, 638373), datetime_complete=datetime.datetime(2021, 6, 7, 7, 8, 14, 641212), params={'x': 4.538171823595548}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=99, state=TrialState.COMPLETE, value=None)]

To get the number of trials:

len(study.trials)

Out:

100

By executing optimize() again, we can continue the optimization.

study.optimize(objective, n_trials=100)

To get the updated number of trials:

len(study.trials)

Out:

200

As the objective function is so easy that the last 100 trials don’t improve the result. However, we can check the result again:

best_params = study.best_params
found_x = best_params["x"]
print("Found x: {}, (x - 2)^2: {}".format(found_x, (found_x - 2) ** 2))

Out:

Found x: 1.996960097124372, (x - 2)^2: 9.241009493251708e-06

Total running time of the script: ( 0 minutes 0.623 seconds)

Gallery generated by Sphinx-Gallery