robustness module¶
Box plots to quantify optimum robustness.
Classes:

Uncertainty quantification at the optimum. 
Functions:

Draw random samples from a normal (Gaussian) distribution. 
 class gemseo.post.robustness.Robustness(opt_problem)[source]¶
Bases:
gemseo.post.opt_post_processor.OptPostProcessor
Uncertainty quantification at the optimum.
Compute the quadratic approximations of all the output functions, propagate analytically a normal distribution centered on the optimal design variables with a standard deviation which is a percentage of the mean passed in option (default: 1%) and plot the corresponding output boxplot.
 Parameters
opt_problem (OptimizationProblem) – The optimization problem to be postprocessed.
 Raises
ValueError – If the JSON grammar file for the options of the postprocessor does not exist.
 Return type
None
Attributes:
The default width and height of the figure, in inches.
The Matplotlib figures indexed by a name, or the nameless figure counter.
The paths to the output files.
Methods:
check_options
(**options)Check the options of the postprocessor.
execute
([save, show, file_path, ...])Postprocess the optimization problem.
 DEFAULT_FIG_SIZE = (8.0, 5.0)¶
The default width and height of the figure, in inches.
 Type
tuple(float, float)
 SR1_APPROX = 'SR1'¶
 check_options(**options)¶
Check the options of the postprocessor.
 Parameters
**options (Union[int, float, str, bool, Sequence[str]]) – The options of the postprocessor.
 Raises
InvalidDataException – If an option is invalid according to the grammar.
 Return type
None
 execute(save=True, show=False, file_path=None, directory_path=None, file_name=None, file_extension=None, fig_size=None, **options)¶
Postprocess the optimization problem.
 Parameters
save (bool) –
If True, save the figure.
By default it is set to True.
show (bool) –
If True, display the figure.
By default it is set to False.
file_path (Optional[Union[str, pathlib.Path]]) –
The path of the file to save the figures. If the extension is missing, use
file_extension
. If None, create a file path fromdirectory_path
,file_name
andfile_extension
.By default it is set to None.
directory_path (Optional[Union[str, pathlib.Path]]) –
The path of the directory to save the figures. If None, use the current working directory.
By default it is set to None.
file_name (Optional[str]) –
The name of the file to save the figures. If None, use a default one generated by the postprocessing.
By default it is set to None.
file_extension (Optional[str]) –
A file extension, e.g. ‘png’, ‘pdf’, ‘svg’, … If None, use a default file extension.
By default it is set to None.
fig_size (Optional[Tuple[float, float]]) –
The width and height of the figure in inches, e.g. (w, h). If None, use the
DEFAULT_FIG_SIZE
of the postprocessor.By default it is set to None.
**options (Union[int, float, str, bool, Sequence[str]]) – The options of the postprocessor.
 Returns
The figures, to be customized if not closed.
 Raises
ValueError – If the opt_problem.database is empty.
 Return type
Dict[str, matplotlib.figure.Figure]
 property figures¶
The Matplotlib figures indexed by a name, or the nameless figure counter.
 property output_files¶
The paths to the output files.
 gemseo.post.robustness.normal(loc=0.0, scale=1.0, size=None)¶
Draw random samples from a normal (Gaussian) distribution.
The probability density function of the normal distribution, first derived by De Moivre and 200 years later by both Gauss and Laplace independently 2, is often called the bell curve because of its characteristic shape (see the example below).
The normal distributions occurs often in nature. For example, it describes the commonly occurring distribution of samples influenced by a large number of tiny, random disturbances, each with its own unique distribution 2.
Note
New code should use the
normal
method of adefault_rng()
instance instead; please see the randomquickstart. Parameters
loc (float or array_like of floats) – Mean (“centre”) of the distribution.
scale (float or array_like of floats) – Standard deviation (spread or “width”) of the distribution. Must be nonnegative.
size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g.,
(m, n, k)
, thenm * n * k
samples are drawn. If size isNone
(default), a single value is returned ifloc
andscale
are both scalars. Otherwise,np.broadcast(loc, scale).size
samples are drawn.
 Returns
out – Drawn samples from the parameterized normal distribution.
 Return type
ndarray or scalar
See also
scipy.stats.norm
probability density function, distribution or cumulative density function, etc.
Generator.normal
which should be used for new code.
Notes
The probability density for the Gaussian distribution is
\[p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }} e^{  \frac{ (x  \mu)^2 } {2 \sigma^2} },\]where \(\mu\) is the mean and \(\sigma\) the standard deviation. The square of the standard deviation, \(\sigma^2\), is called the variance.
The function has its peak at the mean, and its “spread” increases with the standard deviation (the function reaches 0.607 times its maximum at \(x + \sigma\) and \(x  \sigma\) 2). This implies that normal is more likely to return samples lying close to the mean, rather than those far away.
References
 1
Wikipedia, “Normal distribution”, https://en.wikipedia.org/wiki/Normal_distribution
 2(1,2,3)
P. R. Peebles Jr., “Central Limit Theorem” in “Probability, Random Variables and Random Signal Principles”, 4th ed., 2001, pp. 51, 51, 125.
Examples
Draw samples from the distribution:
>>> mu, sigma = 0, 0.1 # mean and standard deviation >>> s = np.random.normal(mu, sigma, 1000)
Verify the mean and the variance:
>>> abs(mu  np.mean(s)) 0.0 # may vary
>>> abs(sigma  np.std(s, ddof=1)) 0.1 # may vary
Display the histogram of the samples, along with the probability density function:
>>> import matplotlib.pyplot as plt >>> count, bins, ignored = plt.hist(s, 30, density=True) >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * ... np.exp(  (bins  mu)**2 / (2 * sigma**2) ), ... linewidth=2, color='r') >>> plt.show()
Twobyfour array of samples from N(3, 6.25):
>>> np.random.normal(3, 2.5, size=(2, 4)) array([[4.49401501, 4.00950034, 1.81814867, 7.29718677], # random [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random