33=====================================
44"""
55# %%
6- # We are interested in the evolution of an epidemic through a
7- # population (for instance, Covid!). We have an epidemiologic model describing
8- # the epidemic dynamics. More precisely, we focus on the evolution of the number
9- # of people infected by the disease.
10- #
11- # .. image:: /_static/epid.png
12- # :scale: 80 %
13- # :alt: alternate text
14- # :align: center
15- #
16- # --------
17- #
18- # See the epidemiological model :doc:`here<../../fmus/epid>`.
19- #
20- # --------
21- #
6+ # This example shows how to create a metamodel of the
7+ # :doc:`epidemiological model<../../examples/model_description>`.
228#
239# **To decrease the model simulation costs, let's create a metamodel.**
2410#
25- # Metamodeling a model which output depends on time is a difficult problem. We
26- # will combine two methods: Karhunen-Loeve dimension reduction should precede the Kriging metamodeling.
11+ # Metamodeling a model with time-dependent output is a difficult problem. We
12+ # will combine two methods: Karhunen-Loeve dimension reduction should precede
13+ # the Kriging metamodeling.
2714#
2815# We will proceed the following way:
2916#
6148)
6249
6350# %%
64- # We create a Monte-Carlo design of experiment, on which we
65- # simulate the FMU.
51+ # We create a Monte-Carlo design of experiment, on which we simulate the FMU.
6652# The simulation inputs and outputs will be used to train the metamodel.
6753
6854inputLaw = ot .Uniform (1.5 , 2.5 )
69- inputSample = inputLaw .getSample (30 )
55+ inputSample = inputLaw .getSample (10 )
7056outputFMUSample = function (inputSample )
7157
7258graph = outputFMUSample .draw ().getGraph (0 , 0 )
7359graph .setTitle ("FMU simulations" )
7460graph .setXTitle ("Time" )
7561graph .setYTitle ("Number of infected" )
76- graph .setLegends ([f"{ line [0 ]:.3f} " for line in inputSample [:15 ]] + ["_" ] * 15 )
77- view = otv .View (graph , legend_kw = {"title" : "infection rate" , "loc" : "upper left" })
62+ graph .setLegendFontSize (6. )
63+ graph .setLegends ([f"{ line [0 ]:.2f} " for line in inputSample [:10 ]])
64+ view = otv .View (graph ,
65+ legend_kw = {"title" : "infection rate" , "loc" : "upper left" })
7866
7967# %%
8068# We define a function to visualize the upcoming Karhunen-Loeve modes.
@@ -133,7 +121,9 @@ def drawKL(scaledKL, KLev, mesh, title="Scaled KL modes"):
133121# We metamodel the Karhunen-Loeve coefficients using ordinary Kriging.
134122dim = inputSample .getDimension () # only 1 input dimension
135123univb = ot .ConstantBasisFactory (dim ).build () # univariate basis
136- coll = [ot .AggregatedFunction ([univb .build (i )] * n_mode ) for i in range (univb .getSize ())]
124+ coll = [ot .AggregatedFunction (
125+ [univb .build (i )] * n_mode ) for i in range (univb .getSize ())]
126+
137127basis = ot .Basis (coll ) # multivariate basis
138128covarianceModel = ot .SquaredExponential (dim )
139129covarianceModel = ot .TensorizedCovarianceModel ([covarianceModel ] * n_mode )
@@ -145,8 +135,8 @@ def drawKL(scaledKL, KLev, mesh, title="Scaled KL modes"):
145135metamodel = result .getMetaModel ()
146136
147137# %%
148- # We have created all pieces for a "PointToField" metamodel. Let put these
149- # pieces together:
138+ # We have created all pieces for a "PointToField" metamodel.
139+ # Let put these pieces together:
150140
151141
152142def globalMetamodel (sample ):
@@ -225,12 +215,11 @@ def globalMetamodel(sample):
225215# ----------------------
226216#
227217# The ``globalMetamodel`` (computationnally faster than the FMU) created with
228- # the above script can now be used as a computationnally much cheaper
229- # substitute to the FMU for
218+ # the above script can now be used as a faster substitute to the FMU for
230219#
231- # - `sensitivity analysis <openturns.github.io/openturns/latest/auto_reliability_sensitivity /index.html#sensitivity-analysis >`_,
232- # - `parameter inference <openturns.github.io/openturns/latest/auto_calibration/index.html#bayesian-calibration >`_,
233- # - `estimate a failure probability <openturns.github.io/openturns/latest/auto_reliability_sensitivity /index.html#reliability >`_,
220+ # - `sensitivity analysis <https:// openturns.github.io/openturns/latest/auto_sensitivity_analysis /index.html>`_,
221+ # - `parameter inference <https:// openturns.github.io/openturns/latest/auto_calibration/index.html>`_,
222+ # - `estimate a failure probability <https:// openturns.github.io/openturns/latest/auto_reliability /index.html>`_,
234223#
235224# etc.
236225
0 commit comments