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.99147435635221, (x - 2)^2: 7.268659960910319e-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.99147435635221}

To get the best observed value of the objective function:

study.best_value

Out:

7.268659960910319e-05

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=35, values=[7.268659960910319e-05], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 4127), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 7385), params={'x': 1.99147435635221}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=35, state=TrialState.COMPLETE, value=None)

To get all trials:

study.trials

Out:

[FrozenTrial(number=0, values=[1.4237375343237288], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 910239), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 910597), params={'x': 0.8067952672220375}, 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=[122.86177399374384], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 910988), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 911277), params={'x': -9.084303045015679}, 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=[52.698941014071266], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 911590), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 911853), params={'x': -5.259403626612262}, 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=[11.340903894401794], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 912159), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 912415), params={'x': -1.3676258542780246}, 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.76221179619679], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 912724), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 912981), params={'x': -4.462368899729943}, 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=[0.002318208091990057], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 913288), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 913550), params={'x': 2.048147773489436}, 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=[19.65052297319346], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 913857), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 914119), params={'x': 6.432891040076832}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=6, state=TrialState.COMPLETE, value=None), FrozenTrial(number=7, values=[8.617699247838246], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 914424), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 914704), params={'x': 4.935591805384094}, 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=[0.22471527512804643], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 915007), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 915273), params={'x': 1.5259585723504259}, 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=[23.118640447898535], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 915574), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 915850), params={'x': -2.808184735209176}, 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=[52.51974563657867], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 916153), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 919483), params={'x': 9.24705082337489}, 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.13953054421307542], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 919835), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 923058), params={'x': 2.373537875205548}, 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.448935438490695], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 923408), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 926472), params={'x': 3.564907485601208}, 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.06814310200945242], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 926840), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 930232), params={'x': 2.2610423375804247}, 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=[27.715399346716165], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 930582), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 933651), params={'x': 7.26454170338845}, 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=[6.3373322548747755], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 934001), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 937090), params={'x': -0.5174058581950538}, 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=[5.255915887346466], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 937438), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 940533), params={'x': 4.2925784364654715}, 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=[99.9321460013108], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 940884), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 943979), params={'x': -7.996606724349558}, 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=[60.924864629230214], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 944327), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 947428), params={'x': 9.805438144603428}, 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=[24.97155562516112], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 947781), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 950872), params={'x': -2.9971547529730476}, 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=[17.083292307203266], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 951224), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 954322), params={'x': 6.133193959543063}, 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.11392579640102306], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 954691), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 957798), params={'x': 2.337528956388964}, 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.20361545190403335], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 958152), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 961270), params={'x': 2.4512376889224052}, 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=[3.1178266573095637], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 961622), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 964734), params={'x': 0.23426314041147012}, 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=[1.6159125198284725], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 965090), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 968211), params={'x': 3.271185478137818}, 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=[15.449277159458333], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 968567), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 971982), params={'x': -1.9305568510655502}, 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=[10.199322637778593], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 972358), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 975481), params={'x': 5.193637837604413}, 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=[0.5177804253171769], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 975852), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 978950), params={'x': 1.2804303888315065}, 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=[32.602430007247634], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 979307), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 982442), params={'x': 7.70985376408605}, 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=[3.587053543915621], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 982816), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 985967), params={'x': 0.10604816747742474}, 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=[0.0015095852224412513], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 986325), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 989511), params={'x': 2.0388533810940728}, 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.016334801332930655], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 989876), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 993082), params={'x': 2.1278076732161675}, 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=[1.4415916924985266], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 993443), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 15, 996648), params={'x': 0.7993369779582089}, 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=[2.061153054852026], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 15, 997009), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 218), params={'x': 3.435671638938384}, 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=[9.916826523809863], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 576), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 3765), params={'x': -1.1490993194578452}, 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=[7.268659960910319e-05], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 4127), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 7385), params={'x': 1.99147435635221}, 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=[43.73909656802818], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 7750), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 10927), params={'x': -4.613554004317813}, 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.848153510367566], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 11289), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 14494), params={'x': 4.418295579611303}, 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=[78.71355587831624], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 14875), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 19233), params={'x': -6.872066043392388}, 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.22575574048161745], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 19601), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 22848), params={'x': 1.5248623983711482}, 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=[19.468629900341508], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 23212), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 26438), params={'x': -2.412327039141762}, 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.6737589154622614], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 26832), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 29995), params={'x': 2.8208281887595366}, 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.11057256665518443], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 30361), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 33571), params={'x': 1.6674754645816576}, 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=[6.076345042364144], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 33935), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 37164), params={'x': -0.4650243492436632}, 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=[9.80127776321864], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 37530), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 40756), params={'x': 5.130699245091844}, 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.780627301641764], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 41120), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 44327), params={'x': 4.18646456674737}, 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.3460966879485623], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 44697), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 47964), params={'x': 0.839785930119548}, 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=[9.732255664426699], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 48330), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 51552), params={'x': -1.1196563375517339}, 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=[17.478648556212214], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 51916), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 55152), params={'x': 6.18074736814032}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=48, state=TrialState.COMPLETE, value=None), FrozenTrial(number=49, values=[0.022478390038685032], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 55518), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 58756), params={'x': 1.8500720505086359}, 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=[31.53043331333707], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 59123), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 62362), params={'x': -3.61519664066514}, 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.0033980630173597115], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 62746), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 65974), params={'x': 2.0582929070930565}, 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.018655934869677662], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 66346), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 69607), params={'x': 1.8634132697892007}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=52, state=TrialState.COMPLETE, value=None), FrozenTrial(number=53, values=[1.3428385211786198], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 69977), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 73214), params={'x': 3.1588090960890063}, 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=[2.05201848339141], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 73582), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 76840), params={'x': 0.5675131821229873}, 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=[5.288920708183714], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 77213), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 80473), params={'x': -0.2997653593755416}, 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=[3.8657173228723245], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 80841), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 84166), params={'x': 3.966142752414566}, 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.46091957095121444], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 84538), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 87828), params={'x': 2.678910576549824}, 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.7330496309981498], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 88202), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 91450), params={'x': 1.1438168239225033}, 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.03298650982571961], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 91826), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 95095), params={'x': 2.181621886967732}, 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=[7.847427500080431], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 95467), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 98752), params={'x': 4.8013260253102334}, 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.021676701748590325], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 99125), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 103017), params={'x': 1.852769902028864}, 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.9799712084945356], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 103394), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 107317), params={'x': 3.407114497293854}, 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.003859106615451978], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 107699), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 111288), params={'x': 1.9378782919145652}, 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=[2.4904627236474006], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 111674), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 114969), params={'x': 0.4218800034067749}, 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.48918602056286437], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 115350), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 118641), params={'x': 2.699418344456924}, 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=[2.792144630189666], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 119041), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 122307), params={'x': 3.6709711637816094}, 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=[13.576468101925622], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 122702), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 125993), params={'x': -1.6846259107168018}, 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=[13.883796560368197], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 126371), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 129637), params={'x': 5.726096692299892}, 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.7269388464400712], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 130011), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 133298), params={'x': 1.147392912039742}, 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=[4.766455213339167], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 133673), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 136991), params={'x': -0.18322129280088495}, 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.008972845036594852], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 137371), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 140680), params={'x': 1.9052748975371636}, 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.022678068041027986], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 141055), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 144368), params={'x': 2.15059239038221}, 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.0705544483080702], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 144744), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 148083), params={'x': 3.034676011275061}, 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.4009134878833938], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 148463), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 151808), params={'x': 1.3668227042262224}, 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=[8.024963861528917], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 152186), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 155534), params={'x': -0.832836716354989}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=75, state=TrialState.COMPLETE, value=None), FrozenTrial(number=76, values=[2.9164170034475365], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 155926), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 159240), params={'x': 0.29224796781045037}, 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.009183847132179112], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 159619), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 163017), params={'x': 1.904167609170077}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=77, state=TrialState.COMPLETE, value=None), FrozenTrial(number=78, values=[0.26730457668950103], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 163398), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 167066), params={'x': 2.5170150642771456}, 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=[4.0227466557903915], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 167447), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 170775), params={'x': 4.0056786023165305}, 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.7835417208154825], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 171152), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 174455), params={'x': 1.1148210797722968}, 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.012149921416516107], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 174850), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 178525), params={'x': 1.8897733180372551}, 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=[142.46916996633513], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 179153), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 182542), params={'x': -9.936044988451373}, 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=[1.5715202182573742], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 183007), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 186347), params={'x': 0.7463971050378935}, 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.9585471430860691], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 186764), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 190085), params={'x': 2.9790542084512324}, 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=[7.421127077085398], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 190512), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 193882), params={'x': 4.724174568027056}, 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.14384708023697823], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 194219), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 197671), params={'x': 1.620728223780126}, 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.05438920552105246], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 198055), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 201435), params={'x': 2.2332149341724334}, 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.0440852508501868], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 201815), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 205183), params={'x': 3.7447307101241116}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=88, state=TrialState.COMPLETE, value=None), FrozenTrial(number=89, values=[3.272263696980846], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 205563), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 208963), params={'x': 0.1910600626386607}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=89, state=TrialState.COMPLETE, value=None), FrozenTrial(number=90, values=[1.2681121254784817], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 209355), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 212721), params={'x': 0.8738951534255428}, 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.01858421712794934], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 213104), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 216511), params={'x': 1.863676058126427}, 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.0005310924869623778], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 216895), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 220299), params={'x': 1.976954556047618}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=92, state=TrialState.COMPLETE, value=None), FrozenTrial(number=93, values=[0.4741669898309394], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 220692), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 224078), params={'x': 2.688597843324345}, 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=[1.5528224833177124], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 224460), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 227865), params={'x': 3.2461229808159837}, 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=[0.043022235887424376], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 228248), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 231641), params={'x': 2.2074180220892687}, 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.12740132738564383], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 232027), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 235448), params={'x': 1.643066774612332}, 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=[7.524233929919729], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 235847), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 239363), params={'x': -0.7430337092204555}, 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.6286868107043238], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 239749), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 243166), params={'x': 1.207102269706664}, 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.482574942393487], datetime_start=datetime.datetime(2021, 8, 3, 5, 52, 16, 243553), datetime_complete=datetime.datetime(2021, 8, 3, 5, 52, 16, 247100), params={'x': 4.341489897990911}, 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.9996604521870749, (x - 2)^2: 1.1529271726222666e-07

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

Gallery generated by Sphinx-Gallery