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: 1.9999249955783402, (x - 2)^2: 5.62566326851392e-09

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': 1.9999249955783402}

To get the best observed value of the objective function:

study.best_value

Out:

5.62566326851392e-09

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=81, values=[5.62566326851392e-09], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 149426), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 152522), params={'x': 1.9999249955783402}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=81, state=TrialState.COMPLETE, value=None)

To get all trials:

study.trials

Out:

[FrozenTrial(number=0, values=[22.789366239527546], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 908377), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 908606), params={'x': 6.773820926629689}, 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=[1.139114451784366], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 908911), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 909106), params={'x': 3.067293048691111}, 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=[10.89294661164252], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 909367), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 909536), params={'x': 5.3004464261130675}, 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=[32.43135250733547], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 909782), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 909955), params={'x': 7.6948531594182015}, 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=[13.18872874525837], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 910197), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 910370), params={'x': 5.63162893826701}, 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=[22.78610966198533], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 910709), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 910892), params={'x': 6.773479827336168}, 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=[0.037638140192686784], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 911220), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 911395), params={'x': 2.194005515882118}, 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=[8.315961210487513], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 911636), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 911812), params={'x': 4.883740836220813}, 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=[45.32026272665002], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 912054), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 912232), params={'x': 8.732032585085282}, 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=[51.59354478579098], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 912468), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 912650), params={'x': -5.182864664309845}, 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=[35.6868749822708], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 912944), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 916170), params={'x': -3.973849260089411}, 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.5507457840583618], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 916460), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 919380), params={'x': 0.7547105621349058}, 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=[1.6242484627281315], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 919664), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 922601), params={'x': 0.7255399328624959}, 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=[12.855299407950653], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 922886), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 925778), params={'x': -1.5854287620800185}, 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=[123.74719078370926], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 926064), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 928923), params={'x': -9.124171465044453}, 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=[1.4673105219977418], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 929229), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 932039), params={'x': 3.211325935492897}, 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=[0.48401971954420725], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 932324), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 935129), params={'x': 2.6957152575186254}, 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=[12.518603500086703], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 935413), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 938224), params={'x': -1.538163859982562}, 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=[0.4014247896431251], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 938519), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 941359), params={'x': 2.6335809258832885}, 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=[36.00501270557298], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 941676), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 944582), params={'x': -4.000417710924213}, 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=[12.877208198403322], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 944879), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 947797), params={'x': -1.5884827153552408}, 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.9516436547297527], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 948084), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 950915), params={'x': 2.97552224717315}, 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.020634879361557987], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 951203), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 954029), params={'x': 2.143648457567626}, 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=[0.362569451475297], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 954316), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 957160), params={'x': 1.3978625975117498}, 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=[2.044845254184978], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 957448), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 960389), params={'x': 0.5700191420214822}, 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=[7.608927693137495], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 960717), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 963669), params={'x': -0.7584284825127323}, 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=[0.22046047220440032], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 963989), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 966997), params={'x': 1.5304678155819345}, 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=[63.9996032349228], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 967322), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 970304), params={'x': 9.999975202144242}, 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=[4.155373329853723], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 970594), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 973609), params={'x': 4.038473284066711}, 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=[0.06587636556724998], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 973900), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 976858), params={'x': 1.7433360844075467}, 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=[20.258287361116267], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 977162), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 980154), params={'x': -2.5009207237093465}, 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=[3.9361683221927812], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 980446), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 983452), params={'x': 0.016022096344623815}, 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=[0.03008248773987888], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 983742), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 986777), params={'x': 1.8265569611086139}, 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=[5.088084942442473], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 987104), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 990159), params={'x': 4.255678377438254}, 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=[18.467246965108025], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 990482), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 993483), params={'x': 6.2973534838442164}, 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=[0.06397264362268787], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 993781), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 23, 996782), params={'x': 2.252928139246482}, 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=[2.9289316435932893], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 23, 997126), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 157), params={'x': 3.7114121781713747}, 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=[9.567229945440163], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 480), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 3526), params={'x': 5.093093911513222}, 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=[0.0561218545463699], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 3859), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 6886), params={'x': 2.2369005161378293}, 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=[40.764741410091105], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 7180), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 10225), params={'x': 8.384727199347761}, 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=[14.858896027550058], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 10524), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 13544), params={'x': 5.8547238587932675}, 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.0017436130387719526], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 13838), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 16872), params={'x': 2.0417565927581736}, 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=[5.843507431752518], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 17182), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 20243), params={'x': 4.4173347785841575}, 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=[3.183658920042809], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 20540), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 23727), params={'x': 0.21571893468466996}, 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=[0.01616205382460316], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 24022), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 27071), params={'x': 1.872869933435858}, 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=[7.869729475047031], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 27369), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 30435), params={'x': -0.8053038115411015}, 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=[0.8954015565906843], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 30734), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 33815), params={'x': 1.053743398125707}, 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=[27.143142665803396], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 34145), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 37201), params={'x': 7.209908124506938}, 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=[2.122506918313303], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 37501), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 40556), params={'x': 3.4568826027903907}, 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=[6.319301017266036], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 40857), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 43889), params={'x': -0.5138219939498572}, 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=[8.095422608000833], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 44191), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 47263), params={'x': 4.845245614705492}, 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.013788130053929808], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 47566), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 50620), params={'x': 1.8825771314695054}, 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.06628936669825221], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 50920), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 54017), params={'x': 2.2574672148026855}, 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=[0.08489016878107356], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 54339), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 57365), params={'x': 1.708640825129749}, 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=[1.7098256784389874], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 57664), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 60710), params={'x': 3.3076030278486614}, 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=[2.1328208658862358], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 61025), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 64052), params={'x': 0.5395819550942833}, 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.6160599602908378], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 64354), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 67418), params={'x': 1.2151051278732687}, 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=[19.502666743810956], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 67722), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 70833), params={'x': -2.416182372118588}, 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=[0.7843447614170365], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 71170), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 74226), params={'x': 2.885632407614489}, 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=[5.541475019026268], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 74530), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 77576), params={'x': -0.35403377610141074}, 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=[0.00013485426877479447], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 77881), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 80935), params={'x': 2.011612677071838}, 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.005467997142642377], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 81256), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 84317), params={'x': 2.0739459068687536}, 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=[0.003430832749100042], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 84622), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 87671), params={'x': 2.058573310894127}, 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=[0.6319405503955284], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 87977), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 91057), params={'x': 2.794946885266889}, 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.984426160294275], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 91363), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 94460), params={'x': 1.0078174763208763}, 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=[3.7038360381603286], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 94764), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 97831), params={'x': 3.9245352784920127}, 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=[108.08938983495507], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 98138), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 101243), params={'x': -8.396604726301518}, 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=[10.727168390991263], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 101551), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 104612), params={'x': -1.2752356237362927}, 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=[3.24435359840736], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 104918), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 107996), params={'x': 0.19879107308248112}, 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.1816721608030648], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 108304), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 111405), params={'x': 2.4262301735014367}, 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.17872517727774725], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 111714), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 114842), params={'x': 1.577240993853771}, 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=[1.2578467415571615], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 115149), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 118255), params={'x': 3.121537668363021}, 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.0018649331759364183], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 118562), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 121682), params={'x': 1.956815127927289}, 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=[1.7323400395098536], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 121988), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 125087), params={'x': 0.6838161072593794}, 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=[0.0033509757387634883], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 125395), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 128473), params={'x': 2.0578876129993584}, 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=[5.761928850310014], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 128781), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 131896), params={'x': 4.400401810178874}, 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=[2.435685283020831], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 132209), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 135348), params={'x': 3.5606682168291988}, 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=[0.00436450760510769], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 135659), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 138782), params={'x': 1.933935579885178}, 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.4832577489976645], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 139096), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 142228), params={'x': 2.6951674251557423}, 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=[0.659886239211811], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 142540), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 145666), params={'x': 1.1876661774788575}, 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=[13.472962438706896], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 145983), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 149113), params={'x': 5.670553424036612}, 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=[5.62566326851392e-09], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 149426), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 152522), params={'x': 1.9999249955783402}, 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.06381913272140644], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 152835), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 155947), params={'x': 2.252624489551996}, 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=[4.522726218006175], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 156259), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 159388), params={'x': -0.12667021844153714}, 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=[2.1677548941481444], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 159702), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 162841), params={'x': 0.5276702495201204}, 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.2870983825912869], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 163154), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 166283), params={'x': 1.4641843763090825}, 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=[2.231374024264085e-07], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 166599), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 169751), params={'x': 2.00047237421863}, 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=[1.350868506205614], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 170085), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 173221), params={'x': 3.162268689333759}, 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=[7.711834710018447], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 173538), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 176935), params={'x': 4.777019033067373}, 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=[3.560878199663311], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 177271), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 180843), params={'x': 3.887028934506122}, 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=[0.9681606278587744], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 181240), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 184361), params={'x': 1.0160484626472834}, 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.00017990205627075917], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 184678), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 187810), params={'x': 2.0134127572210474}, 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.38727743592385394], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 188130), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 191304), params={'x': 2.6223161864549676}, 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.005377691054664832], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 191624), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 194794), params={'x': 1.9266672579630024}, 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=[0.17226400892252455], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 195117), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 198272), params={'x': 1.5849530039591606}, 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=[3.1507333861476807], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 198592), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 201774), params={'x': 0.2249694689533701}, 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=[2.1736636813189216], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 202093), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 205267), params={'x': 3.474334996301357}, 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=[0.2630135970203535], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 205588), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 208727), params={'x': 2.5128485127407054}, 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.004126295218882607], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 209063), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 212218), params={'x': 1.9357637546327418}, 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=[1.0403740902303982], datetime_start=datetime.datetime(2021, 3, 8, 6, 46, 24, 212542), datetime_complete=datetime.datetime(2021, 3, 8, 6, 46, 24, 215700), params={'x': 3.0199872990534726}, 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.9999249955783402, (x - 2)^2: 5.62566326851392e-09

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

Gallery generated by Sphinx-Gallery