smash.Model.optimize#
- Model.optimize(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, verbose=True, inplace=False)[source]#
Optimize the Model.
Hint
See the User Guide and Math / Num Documentation for more.
- Parameters:
- mappingstr, default ‘uniform’
Type of mapping. Should be one of
‘uniform’
‘distributed’
‘hyper-linear’
‘hyper-polynomial’
- algorithmstr or None, default None
Type of algorithm. Should be one of
‘sbs’
‘nelder-mead’
‘l-bfgs-b’
Note
If not given, chosen to be one of ‘sbs’ or ‘l-bfgs-b’ depending on the optimization mapping.
- 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) withminlower thanmax. 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.
- jobs_funstr or sequence, default ‘nse’
Type of objective function(s) to be minimized. Should be one or a sequence of any
‘nse’, ‘kge’, ‘kge2’, ‘se’, ‘rmse’, ‘logarithmic’ (classical objective function)
‘Crc’, ‘Cfp2’, ‘Cfp10’, ‘Cfp50’, ‘Cfp90’ (continuous signature)
‘Epf’, ‘Elt’, ‘Erc’ (flood event signature)
Hint
See a detailed explanation on the objective function in Math / Num Documentation section.
- wjobs_funsequence or None, default None
Objective function(s) weights in case of multi-criteria optimization (i.e. a sequence of objective functions to minimize).
Note
If not given, the cost value will be computed as the mean of the objective functions.
- event_segdict or None, default None
A dictionary of event segmentation options when calculating flood event signatures for cost computation. The keys are
‘peak_quant’
‘max_duration’
See
smash.Model.event_segmentationfor more.Note
If not given in case flood signatures are computed, the default values will be set for these parameters.
- gaugestr, sequence, default ‘downstream’
Type of gauge to be optimized. There are two ways to specify it:
A gauge code or any sequence of gauge codes. The gauge code(s) given must belong to the gauge codes defined in the Model mesh.
An alias among ‘all’ and ‘downstream’. ‘all’ is equivalent to a sequence of all gauge codes. ‘downstream’ is equivalent to the gauge code of the most downstream gauge.
- wgaugestr, sequence, default ‘mean’
Type of gauge weights. There are two ways to specify it:
A sequence of value whose size must be equal to the number of gauges optimized.
An alias among ‘mean’, ‘median’, ‘area’ or ‘minv_area’.
- oststr, pandas.Timestamp or None, default None
The optimization start time. The optimization will only be performed between the optimization start time and the end time. The value can be a str which can be interpreted by pandas.Timestamp (see here). The ost date value must be between the start time and the end time defined in the Model setup.
Note
If not given, the optimization start time will be equal to the start time.
- optionsdict or None, default None
A dictionary of algorithm options. Depending on the algorithm, different options can be pass.
- verbosebool, default True
Display information while optimizing.
- inplacebool, default False
If True, perform operation in-place.
- Returns:
- ModelModel or None
Model with optimize outputs if not inplace.
Examples
>>> setup, mesh = smash.load_dataset("cance") >>> model = smash.Model(setup, mesh) >>> model.optimize(inplace=True) >>> model Structure: 'gr-a' Spatio-Temporal dimension: (x: 28, y: 28, time: 1440) Last update: SBS Optimization
Access to simulated discharge
>>> model.output.qsim[0,:] array([5.7140866e-04, 4.7018618e-04, 3.5345653e-04, ..., 1.9017689e+01, 1.8781073e+01, 1.8549627e+01], dtype=float32)
Access to optimized parameters
>>> ind = tuple(model.mesh.gauge_pos[0,:]) >>> ind (20, 27) >>> ( ... "cp", model.parameters.cp[ind], ... "cft", model.parameters.cft[ind], ... "exc", model.parameters.exc[ind], ... "lr", model.parameters.lr[ind], ... ) ('cp', 76.57858, 'cft', 263.64627, 'exc', -1.455813, 'lr', 30.859276)