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

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

To get the best observed value of the objective function:

study.best_value

Out:

0.0004888643623823775

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=96, values=[0.0004888643623823775], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 750317), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 753742), params={'x': 2.0221102773022497}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=96, state=TrialState.COMPLETE, value=None)

To get all trials:

study.trials

Out:

[FrozenTrial(number=0, values=[110.74889538836771], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 426550), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 426909), params={'x': -8.523730108111273}, 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.65188657766726], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 427283), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 427614), params={'x': -4.5308411845387315}, 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=[15.337924163372612], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 427931), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 428236), params={'x': -1.916366193727626}, 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=[3.7929567305349776], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 428546), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 428850), params={'x': 0.052448529425992874}, 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=[41.229506208990365], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 429163), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 429454), params={'x': -4.421020651655807}, 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=[34.712152729081645], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 429765), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 430057), params={'x': -3.891702023106875}, 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=[43.743708067865356], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 430366), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 430675), params={'x': -4.613902635196965}, 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=[6.130219848865181], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 430978), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 431272), params={'x': 4.4759280782900746}, 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=[32.68915853704431], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 431579), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 431874), params={'x': 7.717443356697494}, 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.5414671474181468], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 432198), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 432500), params={'x': 1.264155486928015}, 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.2811030813691333], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 432804), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 436177), params={'x': 2.530191551582193}, 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.2531483277114629], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 436533), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 439788), params={'x': 2.5031384776693817}, 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=[18.67992966967476], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 440137), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 443255), params={'x': 6.322028420738897}, 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=[1.7955167251001303], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 443601), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 446703), params={'x': 3.339968926915893}, 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=[49.15142524768932], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 447053), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 450163), params={'x': 9.010807745737242}, 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=[0.07177991551357589], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 450514), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 453632), params={'x': 2.2679177401994424}, 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=[9.780169425046493], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 454047), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 457131), params={'x': 5.127326242183008}, 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.168853798581932], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 457516), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 460624), params={'x': -1.488388424270143}, 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.12461592737006613], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 460998), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 464114), params={'x': 1.6469901879974636}, 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=[135.10693443801972], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 464511), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 467647), params={'x': -9.623550853247028}, 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=[7.140958736494708], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 468047), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 471149), params={'x': -0.6722572362133681}, 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.0569310355059273], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 471547), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 474642), params={'x': 2.23860225377378}, 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.6256208249952313], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 475038), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 478493), params={'x': 1.2090380382121835}, 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=[14.182128478666874], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 478913), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 481967), params={'x': 5.765916685040559}, 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=[3.445535490093906], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 482369), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 485442), params={'x': 3.8562153673789865}, 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=[1.0085523567061607], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 485846), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 489084), params={'x': 0.9957329256088493}, 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=[28.155310289279356], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 489509), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 492599), params={'x': 7.306157770862016}, 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=[16.06806877476915], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 493007), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 496185), params={'x': -2.0084995665172714}, 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=[1.0677297217732806], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 496587), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 499748), params={'x': 3.0333100801662978}, 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=[71.39884534723794], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 500149), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 503308), params={'x': -6.449783745590056}, 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.351252282663062], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 503713), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 506902), params={'x': -0.08596555164821984}, 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.03590754808153918], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 507316), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 510474), params={'x': 2.1894928707934396}, 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.02039166922985495], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 510900), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 514049), params={'x': 1.8572005979359334}, 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=[4.880558300252053], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 514453), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 517637), params={'x': 4.209198565148016}, 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=[25.03218102630641], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 518046), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 521213), params={'x': -3.003217067678197}, 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=[3.0527476741966217], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 521619), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 524806), params={'x': 0.25278860059905117}, 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.05414239305299092], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 525215), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 528401), params={'x': 1.7673148198681512}, 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=[7.466968637367616], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 528811), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 532038), params={'x': -0.732575458677695}, 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=[9.894251319977677], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 532448), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 535665), params={'x': 5.145512886633542}, 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=[2.635059895799733], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 536076), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 539301), params={'x': 0.376713242892762}, 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=[23.39133685825762], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 539714), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 542963), params={'x': -2.836459124013933}, 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.024508443974154897], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 543372), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 546564), params={'x': 2.1565517293873016}, 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.07172690644021625], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 546971), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 550180), params={'x': 1.7321812059615378}, 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.5758177124515327], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 550588), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 554160), params={'x': 3.604935423140611}, 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.5090447131816466], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 554567), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 557849), params={'x': 2.713473694807066}, 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=[6.189991729756727], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 558258), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 561447), params={'x': 4.487969398878677}, 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=[8.943039405033451], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 561860), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 565438), params={'x': -0.990491498906735}, 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=[1.533751326483735], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 565965), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 569527), params={'x': 0.7615528568066641}, 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=[0.006181068723599356], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 569944), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 573190), params={'x': 2.0786197731082923}, 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=[21.74815749609894], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 573604), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 576821), params={'x': 6.663491985207966}, 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=[57.74662853892096], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 577232), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 580494), params={'x': -5.599120247694529}, 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.360825637688354], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 580908), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 584136), params={'x': 2.6006876373693353}, 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.01741709784376245], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 584552), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 587836), params={'x': 1.8680261471208692}, 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.08408443358379605], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 588255), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 591462), params={'x': 1.7100268398906615}, 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.7148428412780055], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 591877), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 595111), params={'x': 3.3095200805172884}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=54, state=TrialState.COMPLETE, value=None), FrozenTrial(number=55, values=[0.0007760505600416165], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 595528), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 598827), params={'x': 1.9721423159605538}, 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=[4.670917259083784], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 599244), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 602457), params={'x': -0.16123049651900478}, 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=[9.387157978931343], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 602898), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 606110), params={'x': 5.063846924853026}, 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.5642761443914878], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 606529), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 609776), params={'x': 1.2488168369888155}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=58, state=TrialState.COMPLETE, value=None), FrozenTrial(number=59, values=[0.03225177171697311], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 610195), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 613804), params={'x': 2.1795877827608914}, 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=[14.574773369196349], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 614224), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 617498), params={'x': -1.8176921522297143}, 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.023792405440314655], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 617919), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 621626), params={'x': 2.1542478701321826}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=61, state=TrialState.COMPLETE, value=None), FrozenTrial(number=62, values=[1.311294848300267], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 622049), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 625743), params={'x': 3.145117831622697}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=62, state=TrialState.COMPLETE, value=None), FrozenTrial(number=63, values=[1.694780724111533], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 626164), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 629781), params={'x': 0.698162558492216}, 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=[4.148971296720208], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 630203), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 633454), params={'x': 4.0369023778080795}, 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.005404221120180096], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 633878), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 637149), params={'x': 1.9264865922420944}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=65, state=TrialState.COMPLETE, value=None), FrozenTrial(number=66, values=[0.5825905110343593], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 637591), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 641147), params={'x': 1.2367238304294053}, 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=[8.1777545858261], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 641571), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 644853), params={'x': 4.859677356945378}, 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=[5.8511414327266555], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 645278), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 648574), params={'x': -0.4189132751561506}, 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=[2.6895667538986645], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 649002), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 652294), params={'x': 3.6399898639621724}, 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.7950943084260798], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 652718), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 655979), params={'x': 2.8916806089772726}, 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.10029378098206206], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 656400), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 659708), params={'x': 2.3166919338759073}, 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.007113668664483681], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 660136), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 663426), params={'x': 1.9156574326660394}, 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.7126088743564476], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 663798), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 667125), params={'x': 0.6913331690776114}, 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.0458921260846531], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 667511), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 670873), params={'x': 1.7857755240766053}, 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=[3.626945291120422], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 671243), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 674586), params={'x': 0.09554593357560281}, 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=[13.866775726351651], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 674956), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 678320), params={'x': 5.7238119885879915}, 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.5142945614156118], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 678712), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 682038), params={'x': 1.2828566660592795}, 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=[9.413269347886963], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 682413), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 685726), params={'x': -1.0681051722336643}, 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.0509894325799527], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 686099), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 689446), params={'x': 3.0251777565768547}, 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.0018450060680544082], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 689818), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 693176), params={'x': 1.9570464661750118}, 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.0018789382893373812], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 693549), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 696967), params={'x': 1.9566532782169472}, 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=[2.1060421448411093], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 697360), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 700803), params={'x': 0.5487790847561804}, 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.21375734003629582], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 701183), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 704560), params={'x': 1.5376610117713456}, 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.5275166055478264], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 704938), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 708344), params={'x': 3.589816532040042}, 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.3669762479206687], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 708723), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 712114), params={'x': 2.6057856451919843}, 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=[6.356358402261299], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 712496), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 715888), params={'x': 4.521181945489317}, 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=[0.010705046343839036], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 716266), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 719671), params={'x': 1.896534806123803}, 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=[0.9868378851098225], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 720050), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 723452), params={'x': 1.006602856300753}, 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.0007921542497540269], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 723833), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 727226), params={'x': 1.9718547650613105}, 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=[4.369994144516628], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 727619), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 731021), params={'x': 4.090453095507438}, 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.03263358785139928], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 731397), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 734813), params={'x': 1.8193523101409839}, 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.5239939263295699], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 735196), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 738627), params={'x': 2.723874247593855}, 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.7566614715464977], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 739006), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 742366), params={'x': 0.33968031043822844}, 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.328130855413302], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 742774), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 746148), params={'x': 1.4271729271295726}, 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=[1.9594524372220334], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 746525), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 749933), params={'x': 3.399804428204895}, 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.0004888643623823775], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 750317), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 753742), params={'x': 2.0221102773022497}, 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.17674107972385442], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 754123), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 757555), params={'x': 2.4204058512007824}, 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=[1.1077372508780103], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 757939), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 761370), params={'x': 3.0524909742501407}, 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=[5.141987565240512], datetime_start=datetime.datetime(2021, 8, 2, 6, 38, 55, 761776), datetime_complete=datetime.datetime(2021, 8, 2, 6, 38, 55, 765197), params={'x': -0.267595106107021}, 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.9997368418660963, (x - 2)^2: 6.925220343965217e-08

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

Gallery generated by Sphinx-Gallery