.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/uncertainty/statistics/plot_emp_stats.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_uncertainty_statistics_plot_emp_stats.py: Empirical estimation of statistics ================================== In this example, we want to empirically estimate statistics associated with the range of the Mission discipline of the Sobieski's SSBJ problem. For simplification, we use uniform distributions for the discipline inputs based on the bounds of the design parameters. .. GENERATED FROM PYTHON SOURCE LINES 33-43 .. code-block:: default from __future__ import annotations from gemseo import configure_logger from gemseo import create_discipline from gemseo import create_scenario from gemseo.problems.sobieski.core.problem import SobieskiProblem from gemseo.uncertainty import create_statistics configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-52 Create the dataset ------------------ First of all, we create the dataset. For that, we instantiate the discipline :class:`~gems.problems.sobieski.disciplines.SobieskiMission` of the Sobieski's SSBJ problem which is known to |g|. .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: default discipline = create_discipline("SobieskiMission") .. GENERATED FROM PYTHON SOURCE LINES 55-60 Then, we load the design space of the Sobieski's SSBJ problem by means of the property :meth:`.SobieskiProblem.design_space` and :meth:`.DesignSpace.filter` the inputs of the discipline :class:`~gems.problems.sobieski.disciplines.SobieskiMission`. .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: default parameter_space = SobieskiProblem().design_space parameter_space.filter(discipline.get_input_data_names()) .. raw:: html
Design space:
name lower_bound value upper_bound type
x_shared[0] 0.01 0.05 0.09 float
x_shared[1] 30000 45000 60000 float
x_shared[2] 1.4 1.6 1.8 float
x_shared[3] 2.5 5.5 8.5 float
x_shared[4] 40 55 70 float
x_shared[5] 500 1000 1500 float
y_14[0] 24850 50606.9741711 77100 float
y_14[1] -7700 7306.20262124 45000 float
y_24 0.44 4.15006276 11.13 float
y_34 0.44 1.10754577 1.98 float


.. GENERATED FROM PYTHON SOURCE LINES 64-68 Then, we sample the discipline over this design space by means of a :class:`.DOEScenario` executed with a Monte Carlo algorithm and 100 samples. .. GENERATED FROM PYTHON SOURCE LINES 68-73 .. code-block:: default scenario = create_scenario( [discipline], "DisciplinaryOpt", "y_4", parameter_space, scenario_type="DOE" ) scenario.execute({"algo": "OT_MONTE_CARLO", "n_samples": 100}) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 08:23:01: INFO - 08:23:01: *** Start DOEScenario execution *** INFO - 08:23:01: DOEScenario INFO - 08:23:01: Disciplines: SobieskiMission INFO - 08:23:01: MDO formulation: DisciplinaryOpt INFO - 08:23:01: Optimization problem: INFO - 08:23:01: minimize y_4(x_shared, y_14, y_24, y_34) INFO - 08:23:01: with respect to x_shared, y_14, y_24, y_34 INFO - 08:23:01: over the design space: INFO - 08:23:01: +-------------+-------------+---------------+-------------+-------+ INFO - 08:23:01: | name | lower_bound | value | upper_bound | type | INFO - 08:23:01: +-------------+-------------+---------------+-------------+-------+ INFO - 08:23:01: | x_shared[0] | 0.01 | 0.05 | 0.09 | float | INFO - 08:23:01: | x_shared[1] | 30000 | 45000 | 60000 | float | INFO - 08:23:01: | x_shared[2] | 1.4 | 1.6 | 1.8 | float | INFO - 08:23:01: | x_shared[3] | 2.5 | 5.5 | 8.5 | float | INFO - 08:23:01: | x_shared[4] | 40 | 55 | 70 | float | INFO - 08:23:01: | x_shared[5] | 500 | 1000 | 1500 | float | INFO - 08:23:01: | y_14[0] | 24850 | 50606.9741711 | 77100 | float | INFO - 08:23:01: | y_14[1] | -7700 | 7306.20262124 | 45000 | float | INFO - 08:23:01: | y_24 | 0.44 | 4.15006276 | 11.13 | float | INFO - 08:23:01: | y_34 | 0.44 | 1.10754577 | 1.98 | float | INFO - 08:23:01: +-------------+-------------+---------------+-------------+-------+ INFO - 08:23:01: Solving optimization problem with algorithm OT_MONTE_CARLO: INFO - 08:23:01: ... 0%| | 0/100 [00:00
SobieskiMission
  • n_samples: 86
  • n_variables: 5
  • variables: x_shared, y_14, y_24, y_34, y_4


.. GENERATED FROM PYTHON SOURCE LINES 85-87 and easily obtain statistics, such as the minimum values of the different variables over the dataset: .. GENERATED FROM PYTHON SOURCE LINES 87-89 .. code-block:: default analysis.compute_minimum() .. rst-class:: sphx-glr-script-out .. code-block:: none {'x_shared': array([1.13352258e-02, 3.01398316e+04, 1.40041295e+00, 2.55929483e+00, 4.05869021e+01, 5.05494083e+02]), 'y_14': array([26794.72022057, -6556.01459554]), 'y_24': array([0.48388241]), 'y_34': array([0.44667594]), 'y_4': array([-1532.4108456])} .. GENERATED FROM PYTHON SOURCE LINES 90-93 Create an :class:`.EmpiricalStatistics` object for the range ------------------------------------------------------------ We can only reduce the statistical analysis to the range variable: .. GENERATED FROM PYTHON SOURCE LINES 93-98 .. code-block:: default analysis = create_statistics( dataset, variable_names=["y_4"], name="SobieskiMission.range" ) analysis .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 08:23:01: Create SobieskiMission.range, a EmpiricalStatistics library. .. raw:: html
SobieskiMission.range
  • n_samples: 86
  • n_variables: 1
  • variables: y_4


.. GENERATED FROM PYTHON SOURCE LINES 99-102 Get minimum ~~~~~~~~~~~ Here is the minimum value: .. GENERATED FROM PYTHON SOURCE LINES 102-104 .. code-block:: default analysis.compute_minimum() .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([-1532.4108456])} .. GENERATED FROM PYTHON SOURCE LINES 105-108 Get maximum ~~~~~~~~~~~ Here is the maximum value: .. GENERATED FROM PYTHON SOURCE LINES 108-110 .. code-block:: default analysis.compute_maximum() .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([62030.01439676])} .. GENERATED FROM PYTHON SOURCE LINES 111-114 Get range ~~~~~~~~~ Here is the (different between minimum and maximum values): .. GENERATED FROM PYTHON SOURCE LINES 114-116 .. code-block:: default analysis.compute_range() .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([63562.42524236])} .. GENERATED FROM PYTHON SOURCE LINES 117-120 Get mean ~~~~~~~~ Here is the mean value: .. GENERATED FROM PYTHON SOURCE LINES 120-122 .. code-block:: default analysis.compute_mean() .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([4539.61303269])} .. GENERATED FROM PYTHON SOURCE LINES 123-126 Get central moment ~~~~~~~~~~~~~~~~~~ Here is the second central moment: .. GENERATED FROM PYTHON SOURCE LINES 126-128 .. code-block:: default analysis.compute_moment(2) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([85150303.53546816])} .. GENERATED FROM PYTHON SOURCE LINES 129-132 Get standard deviation ~~~~~~~~~~~~~~~~~~~~~~ Here is the standard deviation: .. GENERATED FROM PYTHON SOURCE LINES 132-134 .. code-block:: default analysis.compute_standard_deviation() .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([9227.6922107])} .. GENERATED FROM PYTHON SOURCE LINES 135-138 Get variance ~~~~~~~~~~~~ Here is the variance. .. GENERATED FROM PYTHON SOURCE LINES 138-140 .. code-block:: default analysis.compute_variance() .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([85150303.53546816])} .. GENERATED FROM PYTHON SOURCE LINES 141-144 Get quantile ~~~~~~~~~~~~ Here is the quantile with level equal to 80%: .. GENERATED FROM PYTHON SOURCE LINES 144-146 .. code-block:: default analysis.compute_quantile(0.8) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([5261.95981236])} .. GENERATED FROM PYTHON SOURCE LINES 147-151 Get probability ~~~~~~~~~~~~~~~ Here are the probability to respectively be greater and lower than the default output value: .. GENERATED FROM PYTHON SOURCE LINES 151-156 .. code-block:: default default_output = discipline.execute() analysis.compute_probability(default_output), analysis.compute_probability( default_output, greater=False ) .. rst-class:: sphx-glr-script-out .. code-block:: none ({'y_4': array([0.76744186])}, {'y_4': array([0.23255814])}) .. GENERATED FROM PYTHON SOURCE LINES 157-160 Get quartile ~~~~~~~~~~~~ Here is the second quartile: .. GENERATED FROM PYTHON SOURCE LINES 160-162 .. code-block:: default analysis.compute_quartile(2) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([2117.20788623])} .. GENERATED FROM PYTHON SOURCE LINES 163-166 Get percentile ~~~~~~~~~~~~~~ Here is the 50the percentile: .. GENERATED FROM PYTHON SOURCE LINES 166-168 .. code-block:: default analysis.compute_percentile(50) .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([2117.20788623])} .. GENERATED FROM PYTHON SOURCE LINES 169-172 Get median ~~~~~~~~~~ Here is the median: .. GENERATED FROM PYTHON SOURCE LINES 172-173 .. code-block:: default analysis.compute_median() .. rst-class:: sphx-glr-script-out .. code-block:: none {'y_4': array([2117.20788623])} .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.136 seconds) .. _sphx_glr_download_examples_uncertainty_statistics_plot_emp_stats.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_emp_stats.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_emp_stats.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_