smash.generate_samples#
- smash.generate_samples(problem, generator='uniform', n=1000, random_state=None, mean=None, coef_std=None)[source]#
Generate a multiple set of spatially uniform Model parameters/states.
- Parameters:
- problemdict
Problem definition. The keys are
‘num_vars’ : the number of Model parameters/states.
‘names’ : the name of Model parameters/states.
‘bounds’ : the upper and lower bounds of each Model parameter/state (a sequence of
(min, max)).
Hint
This problem can be created using the Model object. See
smash.Model.get_bound_constraintsfor more.- generatorstr, default ‘uniform’
Samples generator. Should be one of
‘uniform’
‘normal’ or ‘gaussian’
- nint, default 1000
Number of generated samples.
- random_stateint or None, default None
Random seed used to generate samples.
Note
If not given, generates parameters sets with a random seed.
- meandict or None, default None
If the samples are generated using a Gaussian distribution, mean is used to define the mean of the distribution for each Model parameter/state. It is a dictionary where keys are the name of the parameters/states defined in the problem argument. In this case, the truncated normal distribution may be used with respect to the boundary conditions defined in problem. None value inside the dictionary will be filled in with the center of the parameter/state bounds.
Note
If not given and Gaussian distribution is used, the mean of the distribution will be set to the center of the parameter/state bounds.
- coef_stdfloat or None
A coefficient related to the standard deviation in case of Gaussian generator:
\[std = \frac{u - l}{coef\_std}\]where \(u\) and \(l\) are the upper and lower bounds of Model parameters/states.
Note
If not given and Gaussian distribution is used, coef_std is set to 3 as default:
\[std = \frac{u - l}{3}\]
- Returns:
- resSampleResult
The generated samples result represented as a
SampleResultobject.
See also
SampleResultRepresents the generated samples using
smash.generate_samplesmethod.Model.get_bound_constraintsGet the boundary constraints of the Model parameters/states.
Examples
Define the problem by a dictionary:
>>> problem = { ... 'num_vars': 4, ... 'names': ['cp', 'cft', 'exc', 'lr'], ... 'bounds': [[1,2000], [1,1000], [-20,5], [1,1000]] ... }
Generate samples with the uniform generator:
>>> sr = smash.generate_samples(problem, n=3, random_state=99) >>> sr.to_dataframe() # convert SampleResult object to pandas.DataFrame cp cft exc lr 0 1344.884839 32.414941 -12.559438 7.818907 1 976.668720 808.241913 -18.832607 770.023235 2 1651.164853 566.051802 4.765685 747.020334