Skip to content

Commit

Permalink
Update MetaModelValidation_doc.i.in. Draft of Python interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaudin47 committed Jul 3, 2023
1 parent 9953dcb commit ef73b16
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 15 deletions.
11 changes: 11 additions & 0 deletions python/src/FunctionalChaosValidation.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SWIG file FunctionalChaosValidation.i

%{
#include "openturns/FunctionalChaosValidation.hxx"
%}

%include FunctionalChaosValidation.i

%include openturns/FunctionalChaosValidation.hxx

namespace OT {%extend FunctionalChaosValidation {FunctionalChaosValidation(const FunctionalChaosValidation & other){return new OT::FunctionalChaosValidation(other);}}}
11 changes: 11 additions & 0 deletions python/src/LinearModelValidation.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SWIG file LinearModelValidation.i

%{
#include "openturns/LinearModelValidation.hxx"
%}

%include LinearModelValidation.i

%include openturns/LinearModelValidation.hxx

namespace OT {%extend LinearModelValidation {LinearModelValidation(const LinearModelValidation & other){return new OT::LinearModelValidation(other);}}}
88 changes: 73 additions & 15 deletions python/src/MetaModelValidation_doc.i.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

Refer to :ref:`cross_validation`.


Available constructors:
MetaModelValidation(*inputValidationSample, outputValidationSample, metaModel*)
MetaModelValidation(*outputValidationSample, outputPredictionSample*)


Parameters
----------
inputValidationSample, outputValidationSample : 2-d sequence of float
Expand All @@ -11,35 +17,38 @@ inputValidationSample, outputValidationSample : 2-d sequence of float
metaModel : :class:`~openturns.Function`
Metamodel to validate.

outputPredictionSample: 2-d sequence of float
The output prediction sample from the metamodel.

Notes
-----
A MetaModelValidation object is used for the validation process of a metamodel.
A `MetaModelValidation` object is used for the validation of a metamodel.
For that purpose, a dataset independent of the learning step, is used to score the surrogate model.
Its main functionalities are :

- To compute the predictivity factor :math:`Q_2`
- To get the residual sample, its non parametric distribution
- To draw a `model vs metamodel` validation graph.


Currently only one dimensional output models are available.
- To compute the coefficient of determination :math:`R^2`
- To get the residual sample and its non parametric distribution
- To draw a validation graph presenting the metamodel predictions against
the model observations.

More details on this topic are presented in :ref:`cross_validation`.

Examples
--------
>>> import openturns as ot
>>> from math import pi
>>> dist = ot.Uniform(-pi/2, pi/2)
>>> dist = ot.Uniform(-pi / 2, pi / 2)
>>> # Model here is sin(x)
>>> model = ot.SymbolicFunction(['x'], ['sin(x)'])
>>> # We can build several types of models (kriging, pc, ...)
>>> # We use a Taylor development (order 5) and compare the metamodel with the model
>>> metaModel = ot.SymbolicFunction(['x'], ['x - x^3/6.0 + x^5/120.0'])
>>> metaModel = ot.SymbolicFunction(['x'], ['x - x^3 / 6.0 + x^5 / 120.0'])
>>> x = dist.getSample(10)
>>> y = model(x)
>>> # Validation of the model
>>> val = ot.MetaModelValidation(x, y, metaModel)
>>> # Compute the first indicator : q2
>>> q2 = val.computeR2Score()
>>> # Compute the R2 score
>>> r2Score = val.computeR2Score()
>>> # Get the residual
>>> residual = val.getResidualSample()
>>> # Get the histogram of residual
Expand Down Expand Up @@ -102,9 +111,9 @@ mean squared error of the metamodel:
The sample :math:`R^2` is:

.. math::
\hat{R}^2 = 1 - \frac{\frac{1}{n} \sum_{j=1}^{n} (y^{(j)} - \tilde{g}(\bdx^{(j)}))^2}{\hat{\sigma}^2_Y}
\hat{R}^2 = 1 - \frac{\frac{1}{n} \sum_{j=1}^{n} \left(y^{(j)} - \tilde{g}\left(\bdx^{(j)}\right)\right)^2}{\hat{\sigma}^2_Y}

where :math:`\tilde{g}` is the metamodel, :math:`n \in \Nset` is the sample size,
where :math:`n \in \Nset` is the sample size, :math:`\tilde{g}` is the metamodel,
:math:`\{\bdx^{(j)} \in \Rset^{n_X}\}_{j = 1, ..., n}` is the input experimental design,
:math:`\{y^{(j)} \in \Rset\}_{j = 1, ..., n}` is the output of the model and
:math:`\hat{\sigma}^2_Y` is the sample variance of the output:
Expand Down Expand Up @@ -132,7 +141,15 @@ Notes
The residual sample is given by :

.. math::
\epsilon_{l} = Y_{l} -\hat{f}(X_l)"

r^{(j)} = y^{(j)} - \tilde{g}\left(\vect{x}^{(j)}\right)

for :math:`j = 1, ..., n` where :math:`n \in \Nset` is the sample size,
:math:`y^{(j)}` is the model observation,
:math:`\tilde{g}` is the metamodel and :math:`\vect{x}^{(j)}` is the :math:`j`-th input observation.

If the output is multi-dimensional, the residual sample has dimension :math:`n_y \in \Nset`,
where :math:`n_y` is the output dimension."


// ---------------------------------------------------------------------
Expand Down Expand Up @@ -164,4 +181,45 @@ The residual distribution is built thanks to :class:`~openturns.KernelSmoothing`
Returns
-------
graph : :class:`~openturns.GridLayout`
The visual validation graph."
The visual validation graph.

Notes
-----
If the output is multi-dimensional, the graph has 1 row and :math:`n_y \in \Nset`
columns, where :math:`n_y` is the output dimension."

// ---------------------------------------------------------------------

%feature("docstring") OT::MetaModelValidation::computeMeanSquaredError
"Accessor to the mean squared error.

Returns
-------
meanSquaredError : :class:`~openturns.Point`
The mean squared error of each marginal output dimension.

Notes
-----
The sample mean squared error is:

.. math::
\widehat{\operatorname{MSE}}
= \frac{1}{n} \sum_{j=1}^{n} \left(y^{(j)} - \tilde{g}\left(\bdx^{(j)}\right)\right)^2

where :math:`n \in \Nset` is the sample size, :math:`\tilde{g}` is the metamodel,
:math:`\{\bdx^{(j)} \in \Rset^{n_X}\}_{j = 1, ..., n}` is the input experimental design and
:math:`\{y^{(j)} \in \Rset\}_{j = 1, ..., n}` is the output of the model.

If the output is multi-dimensional, the same calculations are repeated separately for
each output marginal :math:`k` for :math:`k = 1, ..., n_y` where :math:`n_y \in \Nset`
is the output dimension."

// ---------------------------------------------------------------------

%feature("docstring") OT::MetaModelValidation::getMetamodelPredictions
"Accessor to the output predictions from the metamodel.

Returns
-------
outputMetamodelSample : :class:`~openturns.Sample`
Output sample of the metamodel."

0 comments on commit ef73b16

Please sign in to comment.