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

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

To get the best observed value of the objective function:

study.best_value

Out:

0.0002675888851272072

To get the best trial:

study.best_trial

Out:

FrozenTrial(number=50, values=[0.0002675888851272072], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 13317), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 15997), params={'x': 1.9836418556942663}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=50, state=TrialState.COMPLETE, value=None)

To get all trials:

study.trials

Out:

[FrozenTrial(number=0, values=[5.2402522701891145], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 891212), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 891589), params={'x': -0.2891597301606357}, 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.81777845631512], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 891899), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 892207), params={'x': -9.082318279868844}, 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=[5.033935294528776], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 892454), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 892716), params={'x': 4.24364330822187}, 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=[2.028527140285607], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 892950), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 893206), params={'x': 3.4242637186580325}, 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=[4.807363978353222], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 893438), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 893695), params={'x': 4.192570176380501}, 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.05150379924490229], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 893926), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 894200), params={'x': 2.2269444849404856}, 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=[4.714151530746691], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 894432), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 894691), params={'x': 4.171209692946928}, 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=[66.44952182646502], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 894922), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 895180), params={'x': -6.151657612195511}, 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=[44.5299784618123], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 895410), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 895671), params={'x': 8.673078634469423}, 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=[56.31359114753071], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 895899), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 896160), params={'x': -5.504238212339125}, 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=[11.117087624205004], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 896386), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 899708), params={'x': -1.3342296897791854}, 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=[41.40888923706756], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 899986), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 902565), params={'x': 8.434973911141176}, 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=[0.07723628181082709], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 902866), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 905364), params={'x': 2.2779141626668693}, 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.39845143104033737], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 905612), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 908136), params={'x': 1.3687699064205372}, 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=[26.943872355921872], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 908386), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 910921), params={'x': -3.190748727873646}, 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=[28.62037204309206], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 911170), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 913677), params={'x': 7.3498011218261246}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=15, state=TrialState.COMPLETE, value=None), FrozenTrial(number=16, values=[0.7752506639689213], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 913928), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 916448), params={'x': 1.1195168008593683}, 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=[19.911901662559384], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 916705), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 919263), params={'x': 6.462275390712611}, 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=[17.671569144974463], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 919539), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 922118), params={'x': -2.203756551582699}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=18, state=TrialState.COMPLETE, value=None), FrozenTrial(number=19, values=[0.010721216402894567], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 922382), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 924907), params={'x': 2.1035433068956877}, 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=[19.75256750278594], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 925169), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 927712), params={'x': 6.4443860659022345}, 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.019297345075537976], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 927968), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 930521), params={'x': 1.8610851157163568}, 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=[3.6687952625692866], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 930805), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 933326), params={'x': 0.08459005365188554}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=22, state=TrialState.COMPLETE, value=None), FrozenTrial(number=23, values=[0.46592913965276717], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 933586), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 936172), params={'x': 2.682590023112532}, 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=[13.153230829058446], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 936431), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 938988), params={'x': 5.626738318249394}, 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=[37.06713054539], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 939242), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 941806), params={'x': -4.088278126481247}, 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=[3.1421752425900555], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 942071), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 944628), params={'x': 0.2273818113902657}, 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=[10.886372261173896], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 944928), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 947474), params={'x': -1.2994502968182284}, 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=[0.22084234261152447], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 947758), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 950348), params={'x': 2.469938658349709}, 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=[9.323760709232687], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 950631), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 953201), params={'x': 5.053483373007406}, 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.5921131990990096], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 953475), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 956080), params={'x': 1.230511079287681}, 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.23724679248479863], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 956364), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 959098), params={'x': 2.4870798625326227}, 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=[6.008645132291459], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 959379), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 961993), params={'x': -0.45125378781787084}, 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=[0.0736304047422692], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 962301), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 964919), params={'x': 1.7286507697776365}, 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=[1.6865888222957548], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 965211), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 968206), params={'x': 3.2986873458595625}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=34, state=TrialState.COMPLETE, value=None), FrozenTrial(number=35, values=[0.8163662491988726], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 968506), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 971196), params={'x': 1.096470117152248}, 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=[5.229649727790178], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 971487), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 974284), params={'x': 4.286842742251897}, 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=[6.611469828241783], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 974574), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 977173), params={'x': -0.5712778590113095}, 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=[2.5001864229728215], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 977451), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 980069), params={'x': 3.581197781105457}, 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=[7.505485003706083], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 980350), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 982996), params={'x': 4.739614024585595}, 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=[0.16492089481610414], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 983272), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 985883), params={'x': 1.5938954631919213}, 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.09008433850521888], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 986182), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 988823), params={'x': 2.3001405312603063}, 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=[143.67148592703072], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 989101), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 991763), params={'x': -9.986304097887334}, 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=[1.9393891747216059], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 992043), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 994695), params={'x': 3.3926195369596126}, 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=[3.646719323804314], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 994973), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 45, 997964), params={'x': 0.09036146776299203}, 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.00034159722699542703], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 45, 998261), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 938), params={'x': 2.0184823490659447}, 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=[9.936590631786286], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 1222), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 3907), params={'x': -1.152235814748999}, 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.2771062029916669], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 4230), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 7148), params={'x': 0.8699087634214364}, 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.82390977192316], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 7435), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 10068), params={'x': -2.2218372507621793}, 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=[11.603446219664777], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 10376), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 13021), params={'x': 5.406383158082011}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=49, state=TrialState.COMPLETE, value=None), FrozenTrial(number=50, values=[0.0002675888851272072], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 13317), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 15997), params={'x': 1.9836418556942663}, 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.01823836862394909], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 16289), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 19025), params={'x': 1.8649504956545597}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=51, state=TrialState.COMPLETE, value=None), FrozenTrial(number=52, values=[2.9530289163910797], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 19336), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 22033), params={'x': 3.7184379291644722}, 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=[2.306752030562424], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 22357), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 25008), params={'x': 0.4812004639971659}, 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.2931640667010333], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 25312), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 27990), params={'x': 3.137173718787518}, 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.0013409441662376215], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 28286), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 30973), params={'x': 1.9633810955074074}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=55, state=TrialState.COMPLETE, value=None), FrozenTrial(number=56, values=[0.7949528061515444], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 31271), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 33956), params={'x': 2.891601259617518}, 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.08363069369556243], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 34273), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 36928), params={'x': 1.7108102807920682}, 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=[4.8358949126174595], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 37226), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 39924), params={'x': 4.199066827683383}, 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.009387566403030826], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 40224), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 42938), params={'x': 2.096889454550177}, 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=[60.559679252809914], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 43230), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 45893), params={'x': 9.78200997511632}, 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=[2.212683298974273], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 46207), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 48876), params={'x': 0.5124909079355942}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=61, state=TrialState.COMPLETE, value=None), FrozenTrial(number=62, values=[0.00777108955695584], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 49179), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 51940), params={'x': 1.9118462164342571}, 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.01811879120917934], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 52239), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 54945), params={'x': 2.134606059333075}, 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=[15.939525984092686], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 55242), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 57933), params={'x': 5.9924335916947555}, 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=[1.353176836292374], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 58245), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 60942), params={'x': 0.8367387067849399}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=65, state=TrialState.COMPLETE, value=None), FrozenTrial(number=66, values=[5.945167806020383], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 61232), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 63947), params={'x': -0.43827147914673015}, 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=[0.2858929539113191], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 64247), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 66964), params={'x': 2.5346895864997925}, 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=[16.363421653843268], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 67257), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 69942), params={'x': -2.0451726358516846}, 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.251080945816082], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 70250), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 72930), params={'x': 3.803075413235975}, 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=[7.279156268757217], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 73221), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 75932), params={'x': 4.697991154314116}, 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.008900435198933982], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 76223), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 79292), params={'x': 1.9056578821578931}, 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.7680307136937622], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 79582), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 82326), params={'x': 2.876373615356922}, 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.006215893584787611], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 82621), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 85320), params={'x': 2.0788409385077804}, 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.32123354075977106], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 85619), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 88360), params={'x': 1.4332253174675398}, 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=[1.2022034380626303], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 88657), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 91400), params={'x': 0.9035496189691801}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=75, state=TrialState.COMPLETE, value=None), FrozenTrial(number=76, values=[0.0065137252437781215], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 91694), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 94417), params={'x': 2.0807076529443034}, 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=[8.075847267696748], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 94708), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 97410), params={'x': -0.8418035237673887}, 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=[4.395522847883816], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 97703), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 100435), params={'x': -0.09655022546177428}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=78, state=TrialState.COMPLETE, value=None), FrozenTrial(number=79, values=[0.5362777187395087], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 100751), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 103494), params={'x': 1.2676901484074459}, 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.6357345167620488], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 103801), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 106590), params={'x': 2.7973296161325307}, 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.007984590341527188], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 106890), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 109598), params={'x': 2.0893565349682226}, 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.03679670763095655], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 109894), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 112661), params={'x': 2.1918246794105403}, 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=[3.4946823152313775], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 112961), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 115731), params={'x': 3.869406942115969}, 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.2898183540337946], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 116025), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 118776), params={'x': 0.4867854236646427}, 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.3861190462656277], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 119066), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 121810), params={'x': 3.1773355707977347}, 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.05439161322091848], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 122116), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 124831), params={'x': 1.7667799039085215}, 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.032054739011177856], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 125126), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 127893), params={'x': 2.1790383730130998}, 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=[6.179847764125405], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 128185), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 131034), params={'x': 4.48592995961781}, 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.6177615601562758], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 131325), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 134059), params={'x': 1.2140219086028696}, 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=[94.71757474235383], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 134367), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 137194), params={'x': -7.732295450835524}, 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.21467751636728638], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 137483), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 140256), params={'x': 2.463333051235595}, 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=[1.5181618870713522], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 140558), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 143318), params={'x': 3.2321371218623973}, 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.08858878756189532], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 143612), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 146381), params={'x': 1.7023613137344284}, 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.5035091755931023], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 146672), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 149420), params={'x': 0.7738233505758225}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=94, state=TrialState.COMPLETE, value=None), FrozenTrial(number=95, values=[3.4076116611691365], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 149710), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 152489), params={'x': 0.15402826100475298}, 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.012853590647210715], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 152778), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 155549), params={'x': 2.113373677047235}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=96, state=TrialState.COMPLETE, value=None), FrozenTrial(number=97, values=[2.682956312056744], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 155845), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 158635), params={'x': 3.637973233009851}, 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.7007699903189013], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 158940), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 161767), params={'x': 2.8371200572910085}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=98, state=TrialState.COMPLETE, value=None), FrozenTrial(number=99, values=[0.3012042640339105], datetime_start=datetime.datetime(2021, 4, 5, 3, 40, 46, 162070), datetime_complete=datetime.datetime(2021, 4, 5, 3, 40, 46, 164846), params={'x': 1.451179205902409}, 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.004034266860632, (x - 2)^2: 1.627530910279462e-05

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

Gallery generated by Sphinx-Gallery