smash.Model.bayes_optimize#

Model.bayes_optimize(sample=None, alpha=4, n=1000, random_state=None, de_bw_method=None, de_weights=None, mapping='uniform', algorithm=None, control_vector=None, bounds=None, jobs_fun='nse', wjobs_fun=None, event_seg=None, gauge='downstream', wgauge='mean', ost=None, options=None, ncpu=1, verbose=True, inplace=False, return_br=False)[source]#

Optimize the Model using Bayesian approach.

Hint

See the User Guide and Math / Num Documentation for more.

Parameters:
sampleSampleResult or None, default None

An instance of the SampleResult object, which should be created using the smash.generate_samples method.

Note

If not given, the Model parameters samples will be generated automatically using the uniform generator based on both control_vector and bounds arguments.

alphaint, float or sequence, default 4

A regularization parameter that controls the decay rate of the likelihood function.

Note

If alpha is a sequence, then the L-curve approach will be used to find an optimal value for the regularization parameter.

nint, default 1000

Number of generated samples. Only used if sample is not set.

random_stateint or None, default None

Random seed used to generate samples. Only used if sample is not set.

Note

If not given and sample is not set, generates the parameters set with a random seed.

de_bw_methodstr, scalar, callable or None, default None

The method used to calculate the estimator bandwidth to estimate the density distribution. This can be ‘scott’, ‘silverman’, a scalar constant or a callable.

Note

If not given, ‘scott’ is used as default.

See here for more details.

de_weightsarray-like or None, default None

A parameter related to weights of datapoints to estimate the density distribution.

Note

If not given, the samples are assumed to be equally weighted.

See here for more details.

mapping, algorithm, jobs_fun, wjobs_fun, event_seg, gauge, wgauge, ost, optionsmultiple types

Optimization setting to optimize the Model using each generated spatially uniform parameters/states set as a first guess. See smash.Model.optimize for more.

control_vectorstr, sequence or None, default None

Parameters and/or states to be optimized. The control vector argument can be any parameter or state name or any sequence of parameter and/or state names.

Note

If not given, the control vector will be composed of the parameters of the structure defined in the Model setup.

boundsdict or None, default None

Bounds on control vector. The bounds argument is a dictionary where keys are the name of the parameters and/or states in the control vector (can be a subset of control vector sequence) and the values are pairs of (min, max) values (i.e. list or tuple) with min lower than max. None value inside the dictionary will be filled in with default bound values.

Note

If not given, the bounds will be filled in with default bound values.

ncpuinteger, default 1

If ncpu > 1, perform a parallel computation through the parameters set.

verbosebool, default True

Display information while optimizing.

inplacebool, default False

If True, perform operation in-place.

return_brbool, default False

If True, also return the Bayesian optimization result BayesResult.

Returns:
ModelModel or None

Model with optimize outputs if not inplace.

resBayesResult

The Bayesian optimization results represented as a BayesResult object if return_br.

See also

BayesResult

Represents the Bayesian estimation or optimization result.

SampleResult

Represents the generated sample result.

Examples

>>> setup, mesh = smash.load_dataset("cance")
>>> model = smash.Model(setup, mesh)
>>> br = model.bayes_optimize(alpha=1.75, n=100, inplace=True, options={"maxiter": 2}, return_br=True, random_state=99)

Access to cost values of the optimizations with different set of Model parameters

>>> cost = br.data["cost"]
>>> cost.sort()  # sort the values by ascending order
>>> cost
array([0.04417887, 0.04713613, 0.05019313, 0.0512022 , 0.0563822 ,
    ...
    1.14625084, 1.15444124, 1.17005932, 1.19171917, 1.19486201])

Compare to the cost value of the Model with the optimized parameters using Bayesian apporach

>>> model.output.cost
0.04369253292679787