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.9964188979810655, (x - 2)^2: 1.2824291670016521e-05

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

To get the best observed value of the objective function:

study.best_value

Out:

1.2824291670016521e-05

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=51, values=[1.2824291670016521e-05], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 554048), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 556951), params={'x': 1.9964188979810655}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=51, state=TrialState.COMPLETE, value=None)

To get all trials:

study.trials

Out:

[FrozenTrial(number=0, values=[86.0841852921764], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 414398), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 414746), params={'x': -7.278156352000995}, 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=[42.46417085158586], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 415081), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 415389), params={'x': 8.516453855555632}, 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=[2.793212132713765], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 415673), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 415938), params={'x': 3.6712905590332774}, 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=[0.37171629577984905], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 416215), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 416491), params={'x': 1.3903145927776777}, 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=[15.080193625524364], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 416770), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 417034), params={'x': -1.8833224982641301}, 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=[8.530349780557696], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 417312), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 417581), params={'x': 4.920676253979153}, 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=[76.7922849066879], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 417858), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 418141), params={'x': -6.7631207287522805}, 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=[11.495758763426842], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 418417), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 418686), params={'x': -1.3905395976786412}, 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=[113.1887722397669], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 418961), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 419230), params={'x': -8.639021206848255}, 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=[0.046377136926483105], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 419501), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 419773), params={'x': 1.784646483830695}, 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=[59.832164073968016], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 420043), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 424307), params={'x': 9.735125343132328}, 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=[0.007134938810258658], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 424628), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 427574), params={'x': 2.0844685669954135}, 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=[28.502736038710015], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 427893), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 430746), params={'x': -3.3387953733693534}, 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.18700530348541353], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 431063), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 433899), params={'x': 2.4324410982843947}, 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=[20.10358124414831], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 434234), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 437049), params={'x': 6.483701734521188}, 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=[2.096820364499553], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 437366), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 440196), params={'x': 0.5519598194457611}, 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=[38.63544240835688], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 440511), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 443362), params={'x': -4.215741501088738}, 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=[14.356804727629633], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 443678), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 446511), params={'x': 5.789037440779602}, 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=[6.037339441674088], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 446829), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 449662), params={'x': -0.45709980295349173}, 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=[2.6548913934202325], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 449981), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 452808), params={'x': 3.6293837465189815}, 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=[28.602844027788183], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 453142), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 456018), params={'x': 7.348162677760296}, 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.017331232609421588], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 456338), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 459212), params={'x': 1.8683518605926328}, 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.07846330138536468], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 459529), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 462405), params={'x': 2.280113015380158}, 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=[2.96994974915738], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 462723), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 465559), params={'x': 3.7233542146515846}, 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.4772290874067187], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 465877), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 468739), params={'x': 0.42607843670444656}, 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=[23.63442320094251], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 469060), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 472200), params={'x': -2.8615247814798304}, 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.009280301032293733], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 472540), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 475419), params={'x': 1.9036656809216272}, 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=[47.811430633627126], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 475742), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 478598), params={'x': -4.914581016491681}, 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=[9.736727706933689], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 478921), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 481799), params={'x': 5.120373007660092}, 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=[5.917361874535824], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 482138), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 485031), params={'x': -0.43256282026504395}, 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=[1.114339109035281], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 485355), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 488278), params={'x': 3.0556226167694973}, 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.4292260384544612], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 488602), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 491527), params={'x': 1.3448465535048593}, 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.06491351711616687], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 491851), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 494804), params={'x': 1.7452186876629943}, 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.668176030818251], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 495130), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 498029), params={'x': 4.3807931516236875}, 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=[11.028423213794586], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 498371), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 501274), params={'x': -1.3209069866219658}, 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=[1.0409840143316025], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 501602), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 504552), params={'x': 0.9797137586286864}, 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=[0.46465366408026765], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 504879), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 507810), params={'x': 2.681655091729144}, 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=[5.187305455527506], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 508139), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 511069), params={'x': -0.27756568632553513}, 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=[5.08197953253378], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 511393), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 514340), params={'x': 4.254324628915228}, 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=[18.864057209214476], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 514666), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 517606), params={'x': -2.34327724296003}, 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=[20.775286982254507], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 517934), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 520908), params={'x': 6.557991551358395}, 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.033952031203198334], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 521235), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 524207), params={'x': 1.8157392304281827}, 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.12949180959699394], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 524555), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 527476), params={'x': 1.6401502958220002}, 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=[9.228621912492773], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 527809), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 530849), params={'x': -1.0378646962122544}, 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=[1.7533034656935302], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 531179), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 534127), params={'x': 3.3241236595173165}, 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=[0.00022921069065384044], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 534455), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 537359), params={'x': 1.9848602942348987}, 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.5110600616976886], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 537689), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 540617), params={'x': 0.7707481699433234}, 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.06642633380784524], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 540951), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 543891), params={'x': 2.2577330669662805}, 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=[8.068978419763276], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 544219), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 547151), params={'x': 4.840594729940066}, 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=[139.64692214278213], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 547482), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 550417), params={'x': -9.817229884485709}, 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=[36.93662886479515], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 550747), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 553701), params={'x': 8.077551222720805}, 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=[1.2824291670016521e-05], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 554048), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 556951), params={'x': 1.9964188979810655}, 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.8985815343136941], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 557287), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 560235), params={'x': 2.947935406192687}, 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.008240010616933], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 560568), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 563510), params={'x': 0.26557213738451124}, 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=[0.0005229025466944191], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 563844), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 566798), params={'x': 2.0228670624850333}, 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=[3.8799210812588356], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 567136), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 570094), params={'x': 3.969751527797056}, 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=[12.164610712279586], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 570430), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 573384), params={'x': 5.487780198389742}, 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=[0.7043135173435283], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 573722), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 576668), params={'x': 1.1607661128484335}, 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.2339242104871257], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 577005), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 579925), params={'x': 2.4836571207861264}, 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=[4.227507251814443], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 580315), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 583325), params={'x': -0.056090282992077745}, 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.653928633654527], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 583699), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 586677), params={'x': -0.9417560459111027}, 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.00015165731232983067], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 587050), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 590080), params={'x': 1.9876850776563622}, 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=[2.283231902850518], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 590419), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 593371), params={'x': 3.5110366980488985}, 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.0026238562917154174], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 593709), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 596663), params={'x': 1.948776408836207}, 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=[1.4529458563069546], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 597001), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 599973), params={'x': 0.7946179625085852}, 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.07708964967637642], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 600309), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 603306), params={'x': 2.2776502290227336}, 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=[6.740869167195857], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 603647), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 606645), params={'x': 4.596318387100445}, 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.1950408459340442], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 606990), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 610153), params={'x': 3.0931792377895055}, 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=[0.3425422428108985], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 610494), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 613460), params={'x': 1.414728915107795}, 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=[3.1259223373098664], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 613802), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 616773), params={'x': 0.23197218989353385}, 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=[15.006453523325108], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 617113), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 620108), params={'x': -1.8738164028932902}, 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.0018705716995619617], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 620448), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 623455), params={'x': 1.9567498936468133}, 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.03471230445814135], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 623796), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 627831), params={'x': 2.1863123840707894}, 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.5666763125501229], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 628171), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 631183), params={'x': 2.752779059585296}, 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=[3.7626002941983296], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 631525), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 634540), params={'x': 3.939742326753306}, 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=[0.7172563322914965], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 634938), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 637913), params={'x': 1.1530901274093586}, 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=[6.598797986083779], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 638273), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 641265), params={'x': -0.5688125634393373}, 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.16766589852591268], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 641605), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 644626), params={'x': 1.590529734259113}, 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=[1.9802454574824055], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 644971), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 647976), params={'x': 0.5927880552374474}, 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.5839470875736932], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 648318), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 651319), params={'x': 3.2585495967873865}, 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=[17.779683884337427], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 651662), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 654701), params={'x': 6.216596243931523}, 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.0026898977858979016], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 655044), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 658639), params={'x': 1.9481357754719315}, 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.018848561518108764], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 658985), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 661997), params={'x': 2.137290063435446}, 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.36443155098303703], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 662360), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 665366), params={'x': 2.6036816636133957}, 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.06927710135202728], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 665713), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 668753), params={'x': 1.7367945643569889}, 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.1009306527651113], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 669103), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 672145), params={'x': 0.9507475743344163}, 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=[81.82986330730091], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 672494), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 675561), params={'x': -7.045986032893314}, 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=[61.26396390769753], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 675909), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 678958), params={'x': 9.827129991746498}, 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.877766546555761], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 679306), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 682377), params={'x': 3.9692045466522163}, 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=[0.793165510568552], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 682726), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 685746), params={'x': 2.8905984002728458}, 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=[3.973847325379493], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 686114), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 689131), params={'x': 0.006548890647304351}, 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.0002867583781638611], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 689481), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 692546), params={'x': 2.016933941601525}, 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.011497326813516902], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 692896), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 695987), params={'x': 1.8927744115729976}, 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=[2.4058382649459786], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 696336), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 699386), params={'x': 3.5510764858465165}, 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.6827003489392177], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 699735), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 702809), params={'x': 1.1737431701103962}, 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.101429699682734], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 703173), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 706265), params={'x': 0.5503691160565274}, 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.3125622250307248], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 706616), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 709659), params={'x': 2.559072647364119}, 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.3863331901205222], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 710011), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 713077), params={'x': 1.3784429309222506}, 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=[3.0221819793395695e-05], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 713434), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 716525), params={'x': 1.9945025624338792}, 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.4419593081812005], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 11, 716882), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 11, 719955), params={'x': 3.200816100900217}, 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: 2.000196593566275, (x - 2)^2: 3.864903030076412e-08

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

Gallery generated by Sphinx-Gallery