Note
Click here to download the full example code
1) Usage of the Uncertainty Quantification¶
The :class:~.StatisticsTool provides methods for quantifying uncertainties
on a model output.
The :class:~.BendingTestAnalytical is used to illustrate the use of this tool.
from __future__ import annotations
import logging
from pprint import pprint
from gemseo.datasets.dataset import Dataset
from gemseo.post.dataset.scatter import Scatter
from matplotlib import pyplot as plt
from numpy import array
from vimseo import EXAMPLE_RUNS_DIR
from vimseo.api import activate_logger
from vimseo.api import create_model
from vimseo.core.model_settings import IntegratedModelSettings
from vimseo.tools.doe.doe import DOETool
from vimseo.tools.space.space_tool import SpaceTool
from vimseo.tools.statistics.statistics_tool import StatisticsTool
activate_logger(level=logging.INFO)
model_name = "BendingTestAnalytical"
load_case = "Cantilever"
model = create_model(
model_name,
load_case,
model_options=IntegratedModelSettings(
directory_archive_root=EXAMPLE_RUNS_DIR / "archive/uq",
directory_scratch_root=EXAMPLE_RUNS_DIR / "scratch/uq",
cache_file_path=EXAMPLE_RUNS_DIR
/ f"caches/uq/{model_name}_{load_case}_cache.hdf",
),
)
Out:
INFO - 16:52:54: Found 100 entries in the cache file : /home/sebastien.bocquet/PycharmProjects/vimseo/docs/runnable_examples/model_runs/caches/uq/BendingTestAnalytical_Cantilever_cache.hdf node : node
It is possible to change a default input of the model.
model.default_input_data.update({"imposed_dplt": array([-15.0])})
2. Define the uncertain space¶
In addition to the model,
we need to define the uncertain space over which statistics will be computed.
The uncertainty is filled with independent random variables.
This operation is performed with the :class:~.SpaceTool.
Several builders can be used to construct the distributions.
space_tool = SpaceTool(working_directory="SpaceTool_results")
print(space_tool.get_available_space_builders())
Out:
['FromCenterAndCov', 'FromMinAndMax', 'FromModelCenterAndCov', 'FromModelMinAndMax', 'SpaceBuilder']
The model can be used as input such that the bounds of the model input variables
or the central value of its input variable intervals can be used to build
the probability distributions of the random variables.
Here the uncertain space is built from the model, using the central value of its
input variable intervals. A coefficient of variation is used to define the width
of the distribution, which is :math:\pm cov * central\_value.
We consider independent random variables triangularly distributed:
.. note::
A triangular distribution is a probability distribution defined by a lower bound, a mode and an upper bound:
.. figure:: /_examples/uq/_static/triangular_distribution.png
Probability density function of the random variable *friction*
distributed as a triangular distribution :math:`\mathcal{T}(0.1, 0.2, 0.3)`.
Here, the space of parameters is built in two steps. First, considering all input variables of the model except "relative_dplt_location".
retained_variables = model.get_input_data_names()
retained_variables.remove("relative_dplt_location")
space_tool.execute(
distribution_name="OTTriangularDistribution",
space_builder_name="FromModelCenterAndCov",
variable_names=retained_variables,
use_default_values_as_center=True,
model=model,
cov=0.05,
)
Out:
INFO - 16:52:54: Working directory is /home/sebastien.bocquet/PycharmProjects/vimseo/docs/runnable_examples/11_uncertainty_quantification/SpaceTool_results
/home/sebastien.bocquet/PycharmProjects/vimseo/.tox/doc/lib/python3.11/site-packages/pydantic/main.py:209: DeprecationWarning:
Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
SpaceToolResult(metadata=ToolResultMetadata(generic={'datetime': '11-05-2026_16-52-54', 'version': '0.1.7.dev11+g45528c259'}, misc={}, settings={'distribution_name': 'OTTriangularDistribution', 'space_builder_name': 'FromModelCenterAndCov', 'minimum_values': None, 'maximum_values': None, 'center_value_expr': '', 'use_default_values_as_center': True, 'variable_names': ['length', 'width', 'height', 'imposed_dplt', 'young_modulus', 'nu_p'], 'center_values': None, 'cov': 0.05, 'truncate_to_model_bounds': True, 'lower_bounds': None, 'upper_bounds': None, 'size': 1}, report={}, model=None), parameter_space=Parameter space:
+---------------+-------------+-------------------+-------------+-------+-----------------------------------------------------------+--------------------+
| Name | Lower bound | Value | Upper bound | Type | Initial distribution | Transformation(x)= |
+---------------+-------------+-------------------+-------------+-------+-----------------------------------------------------------+--------------------+
| young_modulus | 199500 | 210000.0000000001 | 220500 | float | Triangular(lower=199500.0, mode=210000.0, upper=220500.0) | Trunc(x) |
| nu_p | 0.285 | 0.3 | 0.315 | float | Triangular(lower=0.285, mode=0.3, upper=0.315) | x |
| length | 570 | 600.0000000000003 | 630 | float | Triangular(lower=570.0, mode=600.0, upper=630.0) | Trunc(x) |
| width | 28.5 | 30.00000000000004 | 31.5 | float | Triangular(lower=28.5, mode=30.0, upper=31.5) | Trunc(x) |
| height | 38 | 40.00000000000004 | 42 | float | Triangular(lower=38.0, mode=40.0, upper=42.0) | Trunc(x) |
| imposed_dplt | -15.75 | -15 | -14.25 | float | Triangular(lower=-15.75, mode=-15.0, upper=-14.25) | x |
+---------------+-------------+-------------------+-------------+-------+-----------------------------------------------------------+--------------------+)
Then, specifically for "relative_dplt_location".
space_tool.execute(
distribution_name="OTTriangularDistribution",
space_builder_name="FromCenterAndCov",
center_values={"relative_dplt_location": 0.9},
cov=0.05,
)
parameter_space = space_tool.parameter_space
Out:
INFO - 16:52:54: Working directory is /home/sebastien.bocquet/PycharmProjects/vimseo/docs/runnable_examples/11_uncertainty_quantification/SpaceTool_results
/home/sebastien.bocquet/PycharmProjects/vimseo/.tox/doc/lib/python3.11/site-packages/pydantic/main.py:209: DeprecationWarning:
Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
Other distributions can be used and the available ones can be listed with:
print(space_tool.get_available_distributions())
Out:
('OTUniformDistribution', 'OTTriangularDistribution', 'OTNormalDistribution')
.. note::
For a one-shot use,
we can also instantiate a uncertain space
directly from :class:ParameterSpace.
.. code::
from gemseo.api import create_parameter_space
parameter_space = create_parameter_space()
for (name, minimum, mode, maximum) in [
("plate_len", 210, 214.3, 220.0),
("plate_wid", 50.5, 50.8, 51.0),
("plate_thick", 2.9, 3.0, 3.1),
("friction", 0.1, 0.2, 0.3),
("boundary", 57000.0, 60000.0, 63000.0),
("huth_factor", 0.95, 1., 1.05),
("preload", -10500., -10000., -9500.)
]:
parameter_space.add_random_variable(
name,
"OTTriangularDistribution",
minimum=minimum,
maximum=maximum,
mode=mode
)
In this case, we can use any distribution of
OpenTURNS <https://openturns.github.io/openturns/latest/user_manual/
probabilistic_modelling.html>
and
SciPy <https://docs.scipy.org/doc/scipy/reference/
stats.html#probability-distributions>.
Discover this uncertain space and check its content by printing it:
print(parameter_space)
Out:
Uncertain space:
+------------------------+-------------------------------------------------------------+--------------------+
| Name | Initial distribution | Transformation(x)= |
+------------------------+-------------------------------------------------------------+--------------------+
| young_modulus | Triangular(lower=199500.0, mode=210000.0, upper=220500.0) | Trunc(x) |
| nu_p | Triangular(lower=0.285, mode=0.3, upper=0.315) | x |
| length | Triangular(lower=570.0, mode=600.0, upper=630.0) | Trunc(x) |
| width | Triangular(lower=28.5, mode=30.0, upper=31.5) | Trunc(x) |
| height | Triangular(lower=38.0, mode=40.0, upper=42.0) | Trunc(x) |
| imposed_dplt | Triangular(lower=-15.75, mode=-15.0, upper=-14.25) | x |
| relative_dplt_location | Triangular(lower=0.855, mode=0.9, upper=0.9450000000000001) | x |
+------------------------+-------------------------------------------------------------+--------------------+
We can also sample this uncertain space:
three_samples = parameter_space.compute_samples(3, as_dict=True)
print("Three samples in the parameter space", three_samples)
Out:
Three samples in the parameter space [{'young_modulus': array([210516.88831882]), 'nu_p': array([0.29960532]), 'length': array([586.21006641]), 'width': array([28.80434091]), 'height': array([40.09594002]), 'imposed_dplt': array([-14.72569875]), 'relative_dplt_location': array([0.91464202])}, {'young_modulus': array([210712.2653891]), 'nu_p': array([0.30235434]), 'length': array([610.99460534]), 'width': array([29.51159661]), 'height': array([39.0704446]), 'imposed_dplt': array([-15.28305219]), 'relative_dplt_location': array([0.86620871])}, {'young_modulus': array([209439.41470779]), 'nu_p': array([0.29295192]), 'length': array([589.52132908]), 'width': array([30.31094036]), 'height': array([39.21836595]), 'imposed_dplt': array([-15.04014776]), 'relative_dplt_location': array([0.87377835])}]
3. Post-process¶
Lastly, we can generate some visualizations from 200 realizations of the input variables:
dataset = Dataset.from_array(
parameter_space.compute_samples(200), parameter_space.uncertain_variables
)
|gemseo| provides several plots in package gemseo.post.dataset.
Here, these 200 realizations for a pair of variables are shown in a scatter plot:
scatter_plot = Scatter(
dataset,
x="length",
y="width",
)
fig = scatter_plot.execute(
show=True,
save=False,
directory_path=space_tool.working_directory,
file_format="html",
)
fig
Out:
[Figure({
'data': [{'hovertemplate': 'length=%{x}<br>width=%{y}<extra></extra>',
'legendgroup': '',
'marker': {'color': '#000001', 'symbol': 'circle'},
'mode': 'markers',
'name': '',
'orientation': 'v',
'showlegend': False,
'type': 'scatter',
'x': array([596.36832156, 602.16257682, 605.713234 , 593.09388153, 601.26208619,
594.04713449, 602.11180737, 591.88375271, 597.24939218, 608.66739967,
614.28423183, 608.80683105, 575.9395304 , 609.5596803 , 626.07392033,
594.61187637, 592.33705005, 615.41717014, 599.54334812, 591.50415728,
621.7246179 , 616.07797563, 600.65125904, 608.57849483, 580.13267546,
584.05651961, 589.83730904, 587.53428936, 616.48124475, 598.76204286,
589.51287506, 617.96211498, 583.52277796, 600.88415404, 588.76360887,
577.72002813, 628.02700867, 598.69413553, 592.5704293 , 622.35667716,
601.69820937, 590.98953528, 611.11613176, 607.13559817, 614.63829661,
598.84808639, 575.73983257, 587.97557186, 590.82857943, 606.62802334,
589.55671687, 617.32759496, 585.72040595, 595.58414951, 618.39392815,
595.96019826, 583.00348015, 606.54531932, 580.91511928, 591.27398692,
588.65571979, 599.68187255, 612.59514721, 592.73201144, 621.79948845,
594.75327317, 584.11155516, 611.47963693, 594.16292106, 589.61388854,
613.24955986, 615.06291962, 584.5779192 , 580.78252488, 622.07763545,
595.22741537, 609.22189592, 604.18298061, 610.88384538, 595.56992614,
598.26702563, 613.69436267, 606.31449398, 610.04072928, 574.71032572,
599.37144003, 609.39020814, 598.32708864, 598.6805357 , 613.55298002,
603.68904675, 613.73686616, 605.21688874, 598.30110663, 610.60192632,
594.12873045, 606.67404186, 607.46272017, 614.10575527, 602.13787393,
580.69525906, 573.96720964, 592.78781451, 600.85882296, 620.68668996,
616.92586291, 601.53213118, 598.09431149, 598.35625186, 608.63680448,
610.41890616, 608.40791004, 605.93717228, 609.99109248, 607.24439263,
588.81353076, 613.95227798, 604.22166986, 604.64192989, 605.74948535,
611.46217688, 589.25271157, 607.10712054, 600.00286272, 600.73708089,
604.90945359, 594.8155867 , 601.17613414, 622.16102951, 602.00372853,
584.62946767, 593.72439032, 598.56575597, 596.84896542, 608.32914086,
592.42150685, 593.55933997, 605.30901218, 587.02213856, 607.30081413,
592.96203929, 599.70313126, 584.55304838, 603.32218356, 608.14577937,
609.60857874, 584.01591935, 599.43106382, 582.79336717, 621.43417039,
594.92513656, 593.58060673, 611.53483792, 607.73209472, 585.36755403,
603.77564146, 588.0789244 , 605.36002575, 601.39647939, 590.35403722,
603.07166048, 616.0186011 , 617.02873169, 600.74696429, 609.85715184,
592.65942617, 604.38186836, 610.65934365, 598.40412613, 609.41765443,
605.38165323, 589.73028747, 593.99328424, 615.13963775, 591.37368983,
575.27531676, 573.68593712, 576.06429494, 597.85772987, 599.94927459,
599.25242646, 613.82849295, 588.08021844, 614.46184649, 615.9736375 ,
586.46397503, 594.47098043, 587.76099895, 619.7154525 , 617.75285432,
616.19471783, 581.53745882, 585.64469343, 610.74027527, 604.21092482,
596.89099668, 600.95085792, 606.72584776, 607.96795259, 585.90420893]),
'xaxis': 'x',
'y': array([29.34223942, 30.55255109, 30.05929827, 30.6732329 , 31.25944261,
30.33382408, 29.81308663, 30.16803104, 29.94002455, 29.40442113,
30.20146777, 28.72209755, 30.17392209, 30.33143144, 30.31564737,
28.64809544, 29.12147815, 30.82890116, 29.28899554, 29.1208887 ,
30.24282714, 30.24206041, 29.66002723, 28.94022268, 30.99258554,
30.58736221, 30.66767132, 28.67313082, 29.19924158, 28.99415856,
30.3790275 , 30.6707359 , 29.32366106, 28.93841679, 29.68777089,
30.28428952, 29.74522442, 29.90767378, 29.95264811, 30.85525063,
28.85415464, 28.79833776, 30.46571263, 30.55949809, 29.33099088,
29.26190214, 29.78799337, 29.85819797, 30.12360842, 29.51782531,
30.98006164, 30.09209739, 29.02063703, 29.84216777, 30.50360446,
29.42116748, 29.12819524, 29.3920182 , 29.95711928, 29.88029334,
30.30861152, 30.70813861, 29.97247548, 30.81687037, 30.33669933,
30.07289415, 31.02052618, 30.6857635 , 29.9408155 , 29.96106855,
31.01923628, 30.7629263 , 30.15140393, 29.40745769, 29.51732212,
29.81569963, 30.21980687, 29.81503778, 31.37023232, 30.1490616 ,
31.20121324, 29.7462616 , 30.24369295, 29.9176852 , 30.37127849,
30.82815901, 29.44078091, 30.11366175, 29.18552995, 29.65596306,
30.03206372, 30.50587002, 29.92550551, 30.10996122, 30.23536692,
28.96997491, 31.16474617, 30.03241765, 30.09933603, 30.45320117,
30.31458356, 29.5535907 , 29.66284762, 30.28417664, 30.66721262,
31.16046593, 30.09997921, 29.02505871, 30.4281928 , 30.39623685,
30.47492994, 29.11938106, 29.32373495, 30.6189183 , 29.534852 ,
29.54740645, 30.56144084, 30.87981223, 28.75168197, 29.66795263,
30.78971842, 29.23524998, 29.17940474, 30.94903072, 30.98990227,
29.07813588, 30.08362678, 29.0668353 , 30.19024731, 30.03774755,
30.26437492, 29.00022307, 30.55978265, 29.18566707, 29.11386544,
30.05722039, 30.22596401, 31.06314609, 29.2961171 , 30.56366065,
28.77011526, 30.65290059, 29.61129542, 29.27114346, 29.30379909,
29.74246083, 29.99470065, 29.97737644, 29.24321391, 30.02635196,
30.85409535, 30.22043265, 29.85567353, 30.016258 , 29.64293077,
30.53818208, 30.12385113, 29.18424268, 30.29232411, 30.23479009,
30.79982004, 30.72854884, 29.53171242, 30.90891204, 30.37707524,
30.32041383, 30.39025401, 28.94465355, 30.85896206, 30.60576612,
30.85440273, 29.25264634, 30.05363729, 30.58210462, 31.13086375,
30.96521664, 29.84111832, 29.21140652, 29.90150026, 28.84688524,
29.47805078, 28.90228254, 29.24575204, 29.94668638, 30.11500724,
30.21478031, 30.23646009, 29.13124657, 30.04693346, 30.16896926,
29.82715273, 29.83620696, 28.92006375, 29.24420364, 30.36746657,
30.09000425, 28.75403246, 29.50754321, 30.52953592, 29.97956238]),
'yaxis': 'y'}],
'layout': {'legend': {'tracegroupgap': 0},
'margin': {'t': 60},
'template': '...',
'title': {'text': ''},
'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'length'}},
'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'width'}}}
})]
Dedicated plots from |v| tools can also be used.
For instance, the :class:~.SpaceTool provides a scatter matrix plot
where the diagonal blocks represent the histograms of the random variables
while the other blocks represents the value of a variable versus another.
space_tool.plot_results(space_tool.result, save=False, show=True, n_samples=200)
# Workaround for HTML rendering, instead of ``show=True``
plt.show()

Out:
/home/sebastien.bocquet/PycharmProjects/vimseo/.tox/doc/lib/python3.11/site-packages/gemseo/utils/matplotlib_figure.py:59: UserWarning:
FigureCanvasAgg is non-interactive, and thus cannot be shown
/home/sebastien.bocquet/PycharmProjects/vimseo/docs/runnable_examples/11_uncertainty_quantification/plot_01_uq.py:201: UserWarning:
FigureCanvasAgg is non-interactive, and thus cannot be shown
.. seealso::
Examples of visualization tools <https://gemseo.readthedocs.io/en/stable/examples/dataset/index.html>__
to post-process a :class:~.gemseo.datasets.dataset.Dataset.
3. Sample the model¶
Then,
we generate 100 input-output samples of the model
by sampling the discipline with the :class:~.DOETool executed from a design of
experiments (DOE). The :class:~.DOETool is based on :class:~.gemseo.core.doe_scenario.DOEScenario
To place the samples over the input space, we can use an optimal
latin hypercube sampling (LHS) <https://en.wikipedia.org/wiki/Latin_hypercube_sampling>__ technique.
.. note::
The LHS technique implemented by "OT_LHS" or "lhs" is stochastic:
given a number of samples :math:N and an input space of dimension :math:d,
executing it twice will lead to two different series of samples.
Here, we are looking for the series of samples that best covers the input space
(we talk about space-filling DOE);
for that,
we use "OT_OPT_LHS" relying on a global optimization algorithm
(simulated annealing).
doe_tool = DOETool(working_directory="doe_tool_results")
output_names = ["reaction_forces"]
dataset = doe_tool.execute(
model=model,
parameter_space=parameter_space,
output_names=output_names,
algo="OT_OPT_LHS",
n_samples=100,
).dataset
Out:
INFO - 16:52:56: Working directory is /home/sebastien.bocquet/PycharmProjects/vimseo/docs/runnable_examples/11_uncertainty_quantification/doe_tool_results
INFO - 16:52:56:
INFO - 16:52:56: *** Start DOE_BendingTestAnalytical_Cantilever_OT_OPT_LHS_100 execution ***
INFO - 16:52:56: DOE_BendingTestAnalytical_Cantilever_OT_OPT_LHS_100
INFO - 16:52:56: Disciplines: Model BendingTestAnalytical: An analytical model for the bending of a parallelepipedic beam
INFO - 16:52:56:
INFO - 16:52:56: Load case:
INFO - 16:52:56: Load case Cantilever: A cantilever load case.
INFO - 16:52:56:
INFO - 16:52:56: Boundary condition variables:
INFO - 16:52:56: ['imposed_dplt', 'relative_dplt_location']
INFO - 16:52:56:
INFO - 16:52:56: Plot parameters:
INFO - 16:52:56: {
INFO - 16:52:56: "curves": []
INFO - 16:52:56: }
INFO - 16:52:56: Load:
INFO - 16:52:56: Load(direction='', sign='', type='')
INFO - 16:52:56:
INFO - 16:52:56: Default values:
INFO - 16:52:56:
INFO - 16:52:56: Default geometrical variables:
INFO - 16:52:56: {"height": [40.00000000000004], "length": [600.0000000000003], "width": [30.000000000000036]}
INFO - 16:52:56:
INFO - 16:52:56: Default numerical variables:
INFO - 16:52:56: {}
INFO - 16:52:56:
INFO - 16:52:56: Default boundary conditions variables:
INFO - 16:52:56: {"imposed_dplt": [-15.0], "relative_dplt_location": [0.9]}
INFO - 16:52:56:
INFO - 16:52:56: Default material variables:
INFO - 16:52:56: {"nu_p": [0.3], "young_modulus": [210000.00000000006]}
INFO - 16:52:56: model_inputs:
INFO - 16:52:56: [
INFO - 16:52:56: "length",
INFO - 16:52:56: "width",
INFO - 16:52:56: "height",
INFO - 16:52:56: "imposed_dplt",
INFO - 16:52:56: "relative_dplt_location",
INFO - 16:52:56: "young_modulus",
INFO - 16:52:56: "nu_p"
INFO - 16:52:56: ]
INFO - 16:52:56: model_outputs:
INFO - 16:52:56: [
INFO - 16:52:56: "reaction_forces",
INFO - 16:52:56: "maximum_dplt",
INFO - 16:52:56: "dplt_grid",
INFO - 16:52:56: "location_max_dplt",
INFO - 16:52:56: "dplt",
INFO - 16:52:56: "moment",
INFO - 16:52:56: "moment_grid",
INFO - 16:52:56: "dplt_at_force_location",
INFO - 16:52:56: "error_code",
INFO - 16:52:56: "model",
INFO - 16:52:56: "load_case",
INFO - 16:52:56: "description",
INFO - 16:52:56: "job_name",
INFO - 16:52:56: "persistent_result_files",
INFO - 16:52:56: "n_cpus",
INFO - 16:52:56: "date",
INFO - 16:52:56: "cpu_time",
INFO - 16:52:56: "user",
INFO - 16:52:56: "machine",
INFO - 16:52:56: "vims_git_version",
INFO - 16:52:56: "directory_archive_root",
INFO - 16:52:56: "directory_archive_job",
INFO - 16:52:56: "directory_scratch_root",
INFO - 16:52:56: "directory_scratch_job"
INFO - 16:52:56: ]
INFO - 16:52:56: MDO formulation: DisciplinaryOpt
INFO - 16:52:56: Optimization problem:
INFO - 16:52:56: minimize reaction_forces(young_modulus, nu_p, length, width, height, imposed_dplt, relative_dplt_location)
INFO - 16:52:56: with respect to height, imposed_dplt, length, nu_p, relative_dplt_location, width, young_modulus
INFO - 16:52:56: over the design space:
INFO - 16:52:56: +------------------------+-------------------------------------------------------------+--------------------+
INFO - 16:52:56: | Name | Initial distribution | Transformation(x)= |
INFO - 16:52:56: +------------------------+-------------------------------------------------------------+--------------------+
INFO - 16:52:56: | young_modulus | Triangular(lower=199500.0, mode=210000.0, upper=220500.0) | Trunc(x) |
INFO - 16:52:56: | nu_p | Triangular(lower=0.285, mode=0.3, upper=0.315) | x |
INFO - 16:52:56: | length | Triangular(lower=570.0, mode=600.0, upper=630.0) | Trunc(x) |
INFO - 16:52:56: | width | Triangular(lower=28.5, mode=30.0, upper=31.5) | Trunc(x) |
INFO - 16:52:56: | height | Triangular(lower=38.0, mode=40.0, upper=42.0) | Trunc(x) |
INFO - 16:52:56: | imposed_dplt | Triangular(lower=-15.75, mode=-15.0, upper=-14.25) | x |
INFO - 16:52:56: | relative_dplt_location | Triangular(lower=0.855, mode=0.9, upper=0.9450000000000001) | x |
INFO - 16:52:56: +------------------------+-------------------------------------------------------------+--------------------+
INFO - 16:52:56: Solving optimization problem with algorithm OT_OPT_LHS:
INFO - 16:52:56: 1%| | 1/100 [00:00<00:01, 60.86 it/sec, obj=-9.37e+3]
INFO - 16:52:56: 2%|▏ | 2/100 [00:00<00:01, 81.45 it/sec, obj=-9.07e+3]
INFO - 16:52:56: 3%|▎ | 3/100 [00:00<00:01, 92.44 it/sec, obj=-1.1e+4]
INFO - 16:52:56: 4%|▍ | 4/100 [00:00<00:00, 99.43 it/sec, obj=-8.2e+3]
INFO - 16:52:56: 5%|▌ | 5/100 [00:00<00:00, 104.60 it/sec, obj=-9.45e+3]
INFO - 16:52:56: 6%|▌ | 6/100 [00:00<00:00, 108.21 it/sec, obj=-9.11e+3]
INFO - 16:52:56: 7%|▋ | 7/100 [00:00<00:00, 111.08 it/sec, obj=-8.51e+3]
INFO - 16:52:56: 8%|▊ | 8/100 [00:00<00:00, 113.12 it/sec, obj=-8.03e+3]
INFO - 16:52:56: 9%|▉ | 9/100 [00:00<00:00, 114.94 it/sec, obj=-9.3e+3]
INFO - 16:52:56: 10%|█ | 10/100 [00:00<00:00, 116.07 it/sec, obj=-7.85e+3]
INFO - 16:52:56: 11%|█ | 11/100 [00:00<00:00, 117.35 it/sec, obj=-1.02e+4]
INFO - 16:52:56: 12%|█▏ | 12/100 [00:00<00:00, 118.46 it/sec, obj=-8.24e+3]
INFO - 16:52:56: 13%|█▎ | 13/100 [00:00<00:00, 119.30 it/sec, obj=-1e+4]
INFO - 16:52:56: 14%|█▍ | 14/100 [00:00<00:00, 119.98 it/sec, obj=-9.05e+3]
INFO - 16:52:56: 15%|█▌ | 15/100 [00:00<00:00, 120.57 it/sec, obj=-9.73e+3]
INFO - 16:52:56: 16%|█▌ | 16/100 [00:00<00:00, 121.12 it/sec, obj=-8.26e+3]
INFO - 16:52:56: 17%|█▋ | 17/100 [00:00<00:00, 121.56 it/sec, obj=-9.72e+3]
INFO - 16:52:56: 18%|█▊ | 18/100 [00:00<00:00, 122.03 it/sec, obj=-8.27e+3]
INFO - 16:52:56: 19%|█▉ | 19/100 [00:00<00:00, 122.45 it/sec, obj=-9.32e+3]
INFO - 16:52:56: 20%|██ | 20/100 [00:00<00:00, 122.73 it/sec, obj=-9.74e+3]
INFO - 16:52:56: 21%|██ | 21/100 [00:00<00:00, 123.14 it/sec, obj=-1.06e+4]
INFO - 16:52:56: 22%|██▏ | 22/100 [00:00<00:00, 123.59 it/sec, obj=-8.66e+3]
INFO - 16:52:56: 23%|██▎ | 23/100 [00:00<00:00, 123.95 it/sec, obj=-8.83e+3]
INFO - 16:52:56: 24%|██▍ | 24/100 [00:00<00:00, 124.25 it/sec, obj=-8.79e+3]
INFO - 16:52:56: 25%|██▌ | 25/100 [00:00<00:00, 124.56 it/sec, obj=-1.13e+4]
INFO - 16:52:56: 26%|██▌ | 26/100 [00:00<00:00, 124.87 it/sec, obj=-9.27e+3]
INFO - 16:52:56: 27%|██▋ | 27/100 [00:00<00:00, 125.22 it/sec, obj=-8.01e+3]
INFO - 16:52:56: 28%|██▊ | 28/100 [00:00<00:00, 125.48 it/sec, obj=-9.87e+3]
INFO - 16:52:56: 29%|██▉ | 29/100 [00:00<00:00, 125.77 it/sec, obj=-9.84e+3]
INFO - 16:52:56: 30%|███ | 30/100 [00:00<00:00, 126.03 it/sec, obj=-1.11e+4]
INFO - 16:52:56: 31%|███ | 31/100 [00:00<00:00, 126.33 it/sec, obj=-8.74e+3]
INFO - 16:52:56: 32%|███▏ | 32/100 [00:00<00:00, 126.53 it/sec, obj=-7.77e+3]
INFO - 16:52:56: 33%|███▎ | 33/100 [00:00<00:00, 126.69 it/sec, obj=-1.02e+4]
INFO - 16:52:57: 34%|███▍ | 34/100 [00:00<00:00, 126.80 it/sec, obj=-9.89e+3]
INFO - 16:52:57: 35%|███▌ | 35/100 [00:00<00:00, 126.97 it/sec, obj=-1.01e+4]
INFO - 16:52:57: 36%|███▌ | 36/100 [00:00<00:00, 127.03 it/sec, obj=-1.04e+4]
INFO - 16:52:57: 37%|███▋ | 37/100 [00:00<00:00, 127.17 it/sec, obj=-1.22e+4]
INFO - 16:52:57: 38%|███▊ | 38/100 [00:00<00:00, 127.29 it/sec, obj=-1.05e+4]
INFO - 16:52:57: 39%|███▉ | 39/100 [00:00<00:00, 127.42 it/sec, obj=-9.66e+3]
INFO - 16:52:57: 40%|████ | 40/100 [00:00<00:00, 127.56 it/sec, obj=-1.09e+4]
INFO - 16:52:57: 41%|████ | 41/100 [00:00<00:00, 127.68 it/sec, obj=-1.14e+4]
INFO - 16:52:57: 42%|████▏ | 42/100 [00:00<00:00, 127.80 it/sec, obj=-9.71e+3]
INFO - 16:52:57: 43%|████▎ | 43/100 [00:00<00:00, 127.93 it/sec, obj=-1.07e+4]
INFO - 16:52:57: 44%|████▍ | 44/100 [00:00<00:00, 128.05 it/sec, obj=-9.63e+3]
INFO - 16:52:57: 45%|████▌ | 45/100 [00:00<00:00, 128.12 it/sec, obj=-1.17e+4]
INFO - 16:52:57: 46%|████▌ | 46/100 [00:00<00:00, 128.12 it/sec, obj=-1.1e+4]
INFO - 16:52:57: 47%|████▋ | 47/100 [00:00<00:00, 128.15 it/sec, obj=-9.43e+3]
INFO - 16:52:57: 48%|████▊ | 48/100 [00:00<00:00, 128.22 it/sec, obj=-1e+4]
INFO - 16:52:57: 49%|████▉ | 49/100 [00:00<00:00, 128.30 it/sec, obj=-9.99e+3]
INFO - 16:52:57: 50%|█████ | 50/100 [00:00<00:00, 128.38 it/sec, obj=-8.61e+3]
INFO - 16:52:57: 51%|█████ | 51/100 [00:00<00:00, 128.46 it/sec, obj=-9.75e+3]
INFO - 16:52:57: 52%|█████▏ | 52/100 [00:00<00:00, 128.53 it/sec, obj=-8.97e+3]
INFO - 16:52:57: 53%|█████▎ | 53/100 [00:00<00:00, 128.34 it/sec, obj=-9.97e+3]
INFO - 16:52:57: 54%|█████▍ | 54/100 [00:00<00:00, 128.37 it/sec, obj=-1.02e+4]
INFO - 16:52:57: 55%|█████▌ | 55/100 [00:00<00:00, 128.46 it/sec, obj=-1.02e+4]
INFO - 16:52:57: 56%|█████▌ | 56/100 [00:00<00:00, 128.55 it/sec, obj=-9.45e+3]
INFO - 16:52:57: 57%|█████▋ | 57/100 [00:00<00:00, 128.62 it/sec, obj=-1.07e+4]
INFO - 16:52:57: 58%|█████▊ | 58/100 [00:00<00:00, 128.70 it/sec, obj=-8.46e+3]
INFO - 16:52:57: 59%|█████▉ | 59/100 [00:00<00:00, 128.74 it/sec, obj=-9.61e+3]
INFO - 16:52:57: 60%|██████ | 60/100 [00:00<00:00, 128.82 it/sec, obj=-9.29e+3]
INFO - 16:52:57: 61%|██████ | 61/100 [00:00<00:00, 128.86 it/sec, obj=-7.4e+3]
INFO - 16:52:57: 62%|██████▏ | 62/100 [00:00<00:00, 128.89 it/sec, obj=-1.21e+4]
INFO - 16:52:57: 63%|██████▎ | 63/100 [00:00<00:00, 128.86 it/sec, obj=-9.36e+3]
INFO - 16:52:57: 64%|██████▍ | 64/100 [00:00<00:00, 128.87 it/sec, obj=-1.06e+4]
INFO - 16:52:57: 65%|██████▌ | 65/100 [00:00<00:00, 128.94 it/sec, obj=-9.85e+3]
INFO - 16:52:57: 66%|██████▌ | 66/100 [00:00<00:00, 129.04 it/sec, obj=-8.67e+3]
INFO - 16:52:57: 67%|██████▋ | 67/100 [00:00<00:00, 129.09 it/sec, obj=-9.66e+3]
INFO - 16:52:57: 68%|██████▊ | 68/100 [00:00<00:00, 129.16 it/sec, obj=-9.53e+3]
INFO - 16:52:57: 69%|██████▉ | 69/100 [00:00<00:00, 129.22 it/sec, obj=-1.21e+4]
INFO - 16:52:57: 70%|███████ | 70/100 [00:00<00:00, 129.29 it/sec, obj=-1.01e+4]
INFO - 16:52:57: 71%|███████ | 71/100 [00:00<00:00, 129.27 it/sec, obj=-8.71e+3]
INFO - 16:52:57: 72%|███████▏ | 72/100 [00:00<00:00, 129.33 it/sec, obj=-1.17e+4]
INFO - 16:52:57: 73%|███████▎ | 73/100 [00:00<00:00, 129.38 it/sec, obj=-1.04e+4]
INFO - 16:52:57: 74%|███████▍ | 74/100 [00:00<00:00, 129.47 it/sec, obj=-9.74e+3]
INFO - 16:52:57: 75%|███████▌ | 75/100 [00:00<00:00, 129.53 it/sec, obj=-8.81e+3]
INFO - 16:52:57: 76%|███████▌ | 76/100 [00:00<00:00, 129.61 it/sec, obj=-9.55e+3]
INFO - 16:52:57: 77%|███████▋ | 77/100 [00:00<00:00, 129.71 it/sec, obj=-9.78e+3]
INFO - 16:52:57: 78%|███████▊ | 78/100 [00:00<00:00, 129.77 it/sec, obj=-9.81e+3]
INFO - 16:52:57: 79%|███████▉ | 79/100 [00:00<00:00, 129.85 it/sec, obj=-1.06e+4]
INFO - 16:52:57: 80%|████████ | 80/100 [00:00<00:00, 129.94 it/sec, obj=-1.1e+4]
INFO - 16:52:57: 81%|████████ | 81/100 [00:00<00:00, 130.02 it/sec, obj=-9.65e+3]
INFO - 16:52:57: 82%|████████▏ | 82/100 [00:00<00:00, 130.08 it/sec, obj=-9.51e+3]
INFO - 16:52:57: 83%|████████▎ | 83/100 [00:00<00:00, 130.18 it/sec, obj=-9.38e+3]
INFO - 16:52:57: 84%|████████▍ | 84/100 [00:00<00:00, 130.26 it/sec, obj=-8.64e+3]
INFO - 16:52:57: 85%|████████▌ | 85/100 [00:00<00:00, 130.35 it/sec, obj=-1.26e+4]
INFO - 16:52:57: 86%|████████▌ | 86/100 [00:00<00:00, 130.42 it/sec, obj=-8.64e+3]
INFO - 16:52:57: 87%|████████▋ | 87/100 [00:00<00:00, 130.48 it/sec, obj=-9.26e+3]
INFO - 16:52:57: 88%|████████▊ | 88/100 [00:00<00:00, 130.51 it/sec, obj=-8.99e+3]
INFO - 16:52:57: 89%|████████▉ | 89/100 [00:00<00:00, 130.56 it/sec, obj=-1.09e+4]
INFO - 16:52:57: 90%|█████████ | 90/100 [00:00<00:00, 130.58 it/sec, obj=-1.07e+4]
INFO - 16:52:57: 91%|█████████ | 91/100 [00:00<00:00, 130.61 it/sec, obj=-8.82e+3]
INFO - 16:52:57: 92%|█████████▏| 92/100 [00:00<00:00, 130.60 it/sec, obj=-1.09e+4]
INFO - 16:52:57: 93%|█████████▎| 93/100 [00:00<00:00, 130.64 it/sec, obj=-1.05e+4]
INFO - 16:52:57: 94%|█████████▍| 94/100 [00:00<00:00, 130.68 it/sec, obj=-8.26e+3]
INFO - 16:52:57: 95%|█████████▌| 95/100 [00:00<00:00, 130.72 it/sec, obj=-7.9e+3]
INFO - 16:52:57: 96%|█████████▌| 96/100 [00:00<00:00, 130.75 it/sec, obj=-9.61e+3]
INFO - 16:52:57: 97%|█████████▋| 97/100 [00:00<00:00, 130.77 it/sec, obj=-7.71e+3]
INFO - 16:52:57: 98%|█████████▊| 98/100 [00:00<00:00, 130.81 it/sec, obj=-9.1e+3]
INFO - 16:52:57: 99%|█████████▉| 99/100 [00:00<00:00, 130.84 it/sec, obj=-8.73e+3]
INFO - 16:52:57: 100%|██████████| 100/100 [00:00<00:00, 130.86 it/sec, obj=-9.39e+3]
INFO - 16:52:57: Optimization result:
INFO - 16:52:57: Optimizer info:
INFO - 16:52:57: Status: None
INFO - 16:52:57: Message: None
INFO - 16:52:57: Number of calls to the objective function by the optimizer: 100
INFO - 16:52:57: Solution:
INFO - 16:52:57: Objective: -12628.333932773297
INFO - 16:52:57: Design space:
INFO - 16:52:57: +------------------------+-------------------------------------------------------------+--------------------+
INFO - 16:52:57: | Name | Initial distribution | Transformation(x)= |
INFO - 16:52:57: +------------------------+-------------------------------------------------------------+--------------------+
INFO - 16:52:57: | young_modulus | Triangular(lower=199500.0, mode=210000.0, upper=220500.0) | Trunc(x) |
INFO - 16:52:57: | nu_p | Triangular(lower=0.285, mode=0.3, upper=0.315) | x |
INFO - 16:52:57: | length | Triangular(lower=570.0, mode=600.0, upper=630.0) | Trunc(x) |
INFO - 16:52:57: | width | Triangular(lower=28.5, mode=30.0, upper=31.5) | Trunc(x) |
INFO - 16:52:57: | height | Triangular(lower=38.0, mode=40.0, upper=42.0) | Trunc(x) |
INFO - 16:52:57: | imposed_dplt | Triangular(lower=-15.75, mode=-15.0, upper=-14.25) | x |
INFO - 16:52:57: | relative_dplt_location | Triangular(lower=0.855, mode=0.9, upper=0.9450000000000001) | x |
INFO - 16:52:57: +------------------------+-------------------------------------------------------------+--------------------+
INFO - 16:52:57: *** End DOE_BendingTestAnalytical_Cantilever_OT_OPT_LHS_100 execution (time: 0:00:00.786627) ***
The Dataset containing the DOE result is a
Pandas <https://pandas.pydata.org>__
DataFrame.
People used to Pandas can go much further in terms of data analysis
(filtering, plotting, sorting, ...).
print(dataset.describe())
dataset.to_csv(doe_tool.working_directory / "data.csv", sep=";")
Out:
GROUP inputs outputs
VARIABLE young_modulus nu_p length width height imposed_dplt relative_dplt_location reaction_forces
COMPONENT 0 0 0 0 0 0 0 0
count 100.000000 100.000000 100.000000 100.000000 100.000000 100.000000 100.000000 100.000000
mean 210005.511999 0.299994 600.009767 30.000892 40.000695 -15.000093 0.899975 -9662.162514
std 4324.978485 0.006135 12.339617 0.612487 0.816029 0.308581 0.018516 1074.715533
min 200581.178400 0.286398 573.590282 28.687341 38.249402 -15.712991 0.857272 -12628.333933
25% 206998.379499 0.295729 591.408456 29.561105 39.419986 -15.219837 0.886844 -10251.378923
50% 210002.198295 0.300027 600.104095 29.996546 39.993815 -14.999020 0.900006 -9641.605037
75% 213057.306879 0.304340 608.517336 30.438497 40.585883 -14.784672 0.912774 -8826.880678
max 220348.631497 0.313206 628.926780 31.314395 41.731229 -14.309492 0.941171 -7395.834046
4. Compute statistics¶
The :class:~.StatisticsTool relies on |gemseo| to compute statistics
on a sampling. It allows to test several probability distributions
to find the one that best fits to the output distribution according
to a fitting criterion and a selection criterion.
Then, based on this synthetic distribution, several statistics indicators
can be computed like mean value, standard deviation or percentiles.
Select the output variable on which statistics are computed.
output_name = output_names[0]
The following options are used by default:
pprint(StatisticsTool().options)
Out:
{'confidence': 0.95,
'coverage': 0.05,
'dataset': None,
'fitting_criterion': 'Kolmogorov',
'level': 0.05,
'selection_criterion': 'best',
'tested_distributions': ['Uniform',
'Normal',
'LogNormal',
'Exponential',
'WeibullMin'],
'variable_names': []}
Default options can be overriden through the :meth:~.StatisticsTool.execute method.
Here the confidence value is modified.
statistic_tool = StatisticsTool(working_directory="statistics_tool_results")
results = statistic_tool.execute(
dataset=dataset,
variable_names=[output_name],
confidence=0.98,
)
print(results)
Out:
INFO - 16:52:57: Working directory is /home/sebastien.bocquet/PycharmProjects/vimseo/docs/runnable_examples/11_uncertainty_quantification/statistics_tool_results
INFO - 16:52:57: | Set goodness-of-fit criterion: Kolmogorov.
INFO - 16:52:57: | Set significance level of hypothesis test: 0.05.
INFO - 16:52:57: Fit different distributions (Uniform, Normal, LogNormal, Exponential, WeibullMin) per variable and compute the goodness-of-fit criterion.
INFO - 16:52:57: | Fit different distributions for reaction_forces.
INFO - 16:52:57: Select the best distribution for each variable.
INFO - 16:52:57: | The best distribution for reaction_forces[0] is WeibullMin([5697.67,5.737,-14933.6]).
Results of a Statistics analysis.
{
"generic": {
"datetime": "11-05-2026_16-52-57",
"version": "0.1.7.dev11+g45528c259"
},
"misc": {},
"model": null,
"report": {},
"settings": {
"confidence": 0.98,
"coverage": 0.05,
"fitting_criterion": "Kolmogorov",
"level": 0.05,
"selection_criterion": "best",
"tested_distributions": [
"Uniform",
"Normal",
"LogNormal",
"Exponential",
"WeibullMin"
],
"variable_names": [
"reaction_forces"
]
}
}
Best fitting distribution:
+--------------------------------------+
| reaction_forces |
+--------------------------------------+
| WeibullMin([5697.67,5.737,-14933.6]) |
+--------------------------------------+
Fitting matrix (goodness-of-fit measures):
+-----------------+-----------------------+--------------------+--------------------+-----------------------+--------------------+------------+
| Variable | Uniform | Normal | LogNormal | Exponential | WeibullMin | Selection |
+-----------------+-----------------------+--------------------+--------------------+-----------------------+--------------------+------------+
| reaction_forces | 5.713485287443738e-05 | 0.7680985200194305 | 0.7746323177782352 | 4.558305418956205e-11 | 0.8917679358498344 | WeibullMin |
+-----------------+-----------------------+--------------------+--------------------+-----------------------+--------------------+------------+
Statistics indicators:
OrderedDict([('maximum', {'reaction_forces': array([inf])}), ('minimum', {'reaction_forces': array([-14933.62924665])}), ('range', {'reaction_forces': array([inf])}), ('mean', {'reaction_forces': array([-9660.98586513])}), ('median', {'reaction_forces': array([-9588.57719802])}), ('compute_standard_deviation', {'reaction_forces': array([1064.73584445])}), ('variance', {'reaction_forces': array([1133662.41845893])}), ('percentile_5', {'reaction_forces': array([-11538.53804302])}), ('percentile_10', {'reaction_forces': array([-11084.67365462])}), ('percentile_25', {'reaction_forces': array([-10348.1809608])}), ('percentile_50', {'reaction_forces': array([-9588.57719802])}), ('percentile_75', {'reaction_forces': array([-8902.15269676])}), ('percentile_90', {'reaction_forces': array([-8344.40897986])}), ('percentile_95', {'reaction_forces': array([-8035.12191788])}), ('tolerance_interval', {'reaction_forces': [Bounds(lower=array([-9872.2535252]), upper=array([-9294.21362661]))]}), ('a_value', {'reaction_forces': array([[-12461.47306024]])}), ('b_value', {'reaction_forces': array([[-11202.39862381]])})])
The fitted synthetic distribution can be plotted.
statistic_tool.plot_results(results, variable=output_name, save=False, show=True)

Out:
/home/sebastien.bocquet/PycharmProjects/vimseo/.tox/doc/lib/python3.11/site-packages/gemseo/utils/matplotlib_figure.py:59: UserWarning:
FigureCanvasAgg is non-interactive, and thus cannot be shown
<Figure size 1200x600 with 2 Axes>
Total running time of the script: ( 0 minutes 3.335 seconds)
Download Python source code: plot_01_uq.py