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.01204497628707, (x - 2)^2: 0.00014508145375607373

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.01204497628707}

To get the best observed value of the objective function:

study.best_value

Out:

0.00014508145375607373

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=81, values=[0.00014508145375607373], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 616846), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 619989), params={'x': 2.01204497628707}, 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=[69.34000849259169], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 372801), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 373148), params={'x': -6.327064818565525}, 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.54750055245735], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 373469), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 373782), params={'x': -4.208663346683998}, 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=[22.35552357251056], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 374036), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 374310), params={'x': 6.728162811548536}, 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=[21.736594736998725], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 374558), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 374826), params={'x': -2.662252109978473}, 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=[0.0017228420177850192], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 375071), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 375340), params={'x': 1.9584928678684612}, 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=[1.4569561198310255], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 375586), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 375858), params={'x': 3.207044373596524}, 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=[6.081784463370682], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 376103), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 376374), params={'x': 4.466127422371091}, 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=[103.97051616413772], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 376618), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 376891), params={'x': -8.196593360732678}, 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=[53.56176253254173], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 377132), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 377406), params={'x': 9.318590201161815}, 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=[107.23482406860418], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 377658), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 377936), params={'x': -8.355424861810556}, 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.17213877377064124], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 378177), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 381262), params={'x': 1.5851039000296083}, 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.1705256127152326], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 381566), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 384548), params={'x': 0.9180916800785601}, 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=[2.1179879015822856], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 384880), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 387810), params={'x': 0.5446691436026357}, 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=[13.663883608901477], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 388094), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 390946), params={'x': -1.6964690731698915}, 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=[1.6763995013421118], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 391231), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 394083), params={'x': 3.294758472203257}, 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=[29.000793343731996], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 394367), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 397313), params={'x': 7.3852384667470385}, 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=[1.378410457285398], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 397616), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 400546), params={'x': 0.8259427367945814}, 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=[10.193748817107048], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 400830), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 403807), params={'x': 5.1927650738986495}, 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=[10.103226935152469], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 404094), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 407081), params={'x': -1.1785573669752238}, 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.7402586933089665], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 407368), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 410359), params={'x': 2.8603828759970567}, 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=[38.934708683747715], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 410647), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 413646), params={'x': -4.239768319717305}, 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.1267512381566015], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 413940), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 416895), params={'x': 2.356021401262061}, 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.0005590380243006055], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 417193), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 420154), params={'x': 2.023643984949678}, 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=[17.63090586901976], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 420443), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 423438), params={'x': 6.198917225788067}, 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=[0.19713402419609408], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 423734), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 426708), params={'x': 2.4439977749900264}, 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=[50.56589870049468], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 426999), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 429970), params={'x': 9.110970306540077}, 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=[6.18884687810944], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 430264), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 433260), params={'x': 4.4877393107215715}, 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=[6.859081796842702], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 433567), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 436587), params={'x': -0.6189848790786674}, 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=[25.912741480913137], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 436875), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 439791), params={'x': -3.0904559207317703}, 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.027865781260734197], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 440081), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 442989), params={'x': 1.8330695316584351}, 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=[4.117276700451556], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 443277), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 446301), params={'x': -0.029107365432286647}, 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.004775961105091352], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 446631), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 449651), params={'x': 2.069108328767894}, 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.02480197896118175], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 449960), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 453114), params={'x': 1.8425135594370685}, 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.907240865879762], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 453404), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 456431), params={'x': 4.430481611919696}, 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=[15.205871726215287], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 456722), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 459774), params={'x': 5.899470698212167}, 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=[33.516668890970394], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 460066), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 463121), params={'x': 7.789358245174537}, 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.6040000297279478], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 463414), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 466448), params={'x': 3.898420403843139}, 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=[17.920430191362673], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 466743), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 469777), params={'x': -2.233252908977052}, 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=[7.55927546833442], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 470072), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 473109), params={'x': -0.749413659007029}, 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=[0.1444037104897807], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 473407), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 476444), params={'x': 1.6199951178079672}, 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=[33.58167677166792], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 476739), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 479783), params={'x': -3.7949699543369437}, 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.0179641853247435], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 480083), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 483162), params={'x': 1.8659694612234081}, 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=[1.5120836495770156], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 483458), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 486539), params={'x': 3.2296681054565153}, 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=[2.092571767720907], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 486836), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 489908), params={'x': 0.5534275795104806}, 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.5164206882819693], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 490202), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 493252), params={'x': 1.2813758365585184}, 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=[4.777429845900979], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 493565), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 496630), params={'x': -0.18573325131429952}, 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=[2.0189807147631758], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 496926), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 500053), params={'x': 3.420908411813786}, 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=[0.0006464166807624356], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 500348), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 503442), params={'x': 2.02542472577556}, 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=[6.749100252865953], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 503739), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 506815), params={'x': 4.597903049165991}, 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=[134.39645986831866], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 507124), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 510246), params={'x': -9.59294871326181}, 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=[0.17534203436204895], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 510551), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 513876), params={'x': 2.418738622964313}, 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.0013213069719450288], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 514176), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 517227), params={'x': 2.03634978640852}, 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=[2.2232310510518767], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 517548), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 520611), params={'x': 0.5089496819181867}, 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=[3.7172767482797306], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 520909), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 523978), params={'x': 3.9280240528270727}, 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=[10.097696798891645], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 524287), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 527355), params={'x': 5.177687334979898}, 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=[11.119429885069772], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 527656), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 530730), params={'x': -1.3345809159577717}, 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.6265440806061585], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 531046), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 534166), params={'x': 2.7915453749508985}, 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=[1.1759721314814453], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 534465), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 537555), params={'x': 0.9155775124604594}, 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.008026392524403412], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 537857), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 540926), params={'x': 1.9104098636879963}, 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=[3.015411062086846], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 541229), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 544334), params={'x': 3.7364938992368635}, 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=[3.3322608855720413], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 544639), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 547730), params={'x': 0.17455186719204718}, 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.06822260422657359], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 548033), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 551148), params={'x': 2.2611945715871093}, 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.3015634541861067], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 551452), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 554587), params={'x': 1.4508520652992432}, 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.5703752638467198], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 554892), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 558003), params={'x': 2.755231927189734}, 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.6920033705929508], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 558305), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 561403), params={'x': 1.1681326003545092}, 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=[0.00388300787275853], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 561725), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 564839), params={'x': 1.9376862144244267}, 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=[5.463683673423509], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 565145), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 568247), params={'x': -0.33745238955224677}, 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=[1.2942686145442373], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 568555), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 571672), params={'x': 3.1376592699680503}, 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=[10.213331996588092], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 571975), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 575106), params={'x': 5.195830407982891}, 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.01359561573146305], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 575410), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 578528), params={'x': 2.1166002389854457}, 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=[8.542397277754318], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 578832), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 582014), params={'x': -0.9227379762397994}, 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.010121691802662227], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 582319), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 585449), params={'x': 2.1006066190797714}, 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=[1.856469519183183], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 585756), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 588870), params={'x': 0.6374767821489489}, 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.34190013696978], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 589180), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 592298), params={'x': 1.4152777266344474}, 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.6473595294545738], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 592605), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 595741), params={'x': 2.804586558087179}, 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.2976926007165295], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 596052), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 599242), params={'x': 4.301671696988198}, 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.0036792009079344534], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 599551), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 602704), params={'x': 2.0606564168735217}, 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=[3.861059395570659], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 603016), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 606165), params={'x': 0.03504213898346942}, 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=[2.2344988837918636], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 606476), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 609617), params={'x': 3.4948240310457495}, 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=[1.1523659764341478], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 609930), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 613076), params={'x': 0.9265168951333479}, 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=[0.02493853992177174], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 613385), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 616534), params={'x': 1.842080590421026}, 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.00014508145375607373], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 616846), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 619989), params={'x': 2.01204497628707}, 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.38965053575278946], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 620301), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 623474), params={'x': 2.6242199418096073}, 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.40228855726397234], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 623785), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 627039), params={'x': 1.3657377850888701}, 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=[3.2538918080840564], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 627354), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 630530), params={'x': 0.19614529185855534}, 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=[1.3909946840870595], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 630842), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 634103), params={'x': 3.1794043768305507}, 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.07176043838420806], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 634476), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 637627), params={'x': 2.267881388648424}, 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=[3.4897459320029123], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 637960), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 641121), params={'x': 3.8680861682489147}, 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=[8.592638449966364], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 641470), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 644656), params={'x': 4.931320257148025}, 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=[13.488027795066278], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 644991), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 648167), params={'x': -1.6726050420738519}, 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.061934202642853466], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 648501), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 651680), params={'x': 1.7511341673856102}, 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.006376693401812304], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 652059), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 655247), params={'x': 2.079854200902722}, 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.8642440576629962], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 655584), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 658797), params={'x': 1.0703527240598205}, 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=[1.1937751297847503], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 659134), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 662327), params={'x': 3.0926001692223695}, 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.28659448267985854], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 662693), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 665892), params={'x': 2.5353451995487197}, 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.17602097757892], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 666228), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 669430), params={'x': 0.524865776419339}, 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.121703895774858], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 669769), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 672964), params={'x': 1.6511391455395747}, 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=[2.802021009405593], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 673300), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 676486), params={'x': 3.6739238362021114}, 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.006577349793287186], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 676823), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 680045), params={'x': 2.0811008618529248}, 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=[0.08461556898671091], datetime_start=datetime.datetime(2021, 4, 5, 1, 58, 19, 680382), datetime_complete=datetime.datetime(2021, 4, 5, 1, 58, 19, 683611), params={'x': 2.2908875538532216}, 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.9968718971934352, (x - 2)^2: 9.785027168438806e-06

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

Gallery generated by Sphinx-Gallery