------------------------
#. :ref:`Examples with the "AdjointTest" check<section_ref_algorithm_AdjointTest_examples>`
+#. :ref:`Examples with the "ControledFunctionTest"<section_ref_algorithm_ControledFunctionTest_examples>`
#. :ref:`Examples with the "FunctionTest" check<section_ref_algorithm_FunctionTest_examples>`
#. :ref:`Examples with the "ParallelFunctionTest" check<section_ref_algorithm_ParallelFunctionTest_examples>`
--- /dev/null
+..
+ Copyright (C) 2008-2023 EDF R&D
+
+ This file is part of SALOME ADAO module.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
+ Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+
+.. index:: single: ControledFunctionTest
+.. _section_ref_algorithm_ControledFunctionTest:
+
+Checking algorithm "*ControledFunctionTest*"
+--------------------------------------------
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo01.rst
+
+This algorithm allows to verify that a given operator :math:`F`, in particular
+the observation one, is working correctly and that its call is compatible with
+its usage in ADAO algorithms. In practice, it allows to call one or several
+times the operator, activating or not the "debug" mode during execution. The
+:math:`F` operator is considered to depend on a state vector variable
+:math:`\mathbf{x}` and on a control vector variable :math:`\mathbf{u}`, the two
+not necessarily being of the same size.
+
+Statistics on input and output vectors for each execution of operator are
+given, and an another global statistic is given at the end of the checking
+algorithm. The precision of printed outputs can be controlled to facilitate
+automatic tests of operator. It may also be useful to check the entries
+themselves beforehand with the intended test
+:ref:`section_ref_algorithm_InputValuesTest`.
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo02.rst
+
+.. include:: snippets/CheckingPoint.rst
+
+.. include:: snippets/ObservationOperator.rst
+
+.. include:: snippets/ControlInput.rst
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo03Chck.rst
+
+.. include:: snippets/NumberOfPrintedDigits.rst
+
+.. include:: snippets/NumberOfRepetition.rst
+
+.. include:: snippets/SetDebug.rst
+
+.. include:: snippets/ShowElementarySummary.rst
+
+StoreSupplementaryCalculations
+ .. index:: single: StoreSupplementaryCalculations
+
+ *List of names*. This list indicates the names of the supplementary
+ variables, that can be available during or at the end of the algorithm, if
+ they are initially required by the user. Their avalability involves,
+ potentially, costly calculations or memory consumptions. The default is then
+ a void list, none of these variables being calculated and stored by default
+ (excepted the unconditionnal variables). The possible names are in the
+ following list (the detailed description of each named variable is given in
+ the following part of this specific algorithmic documentation, in the
+ sub-section "*Information and variables available at the end of the
+ algorithm*"): [
+ "CurrentState",
+ "SimulatedObservationAtCurrentState",
+ ].
+
+ Example :
+ ``{"StoreSupplementaryCalculations":["CurrentState", "Residu"]}``
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo04.rst
+
+.. include:: snippets/NoUnconditionalOutput.rst
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo05.rst
+
+.. include:: snippets/CurrentState.rst
+
+.. include:: snippets/SimulatedObservationAtCurrentState.rst
+
+.. ------------------------------------ ..
+.. _section_ref_algorithm_ControledFunctionTest_examples:
+
+.. include:: snippets/Header2Algo09.rst
+
+.. --------- ..
+.. include:: scripts/simple_ControledFunctionTest1.rst
+
+.. literalinclude:: scripts/simple_ControledFunctionTest1.py
+
+.. include:: snippets/Header2Algo10.rst
+
+.. literalinclude:: scripts/simple_ControledFunctionTest1.res
+ :language: none
+
+.. --------- ..
+.. include:: scripts/simple_ControledFunctionTest2.rst
+
+.. literalinclude:: scripts/simple_ControledFunctionTest2.py
+
+.. include:: snippets/Header2Algo10.rst
+
+.. literalinclude:: scripts/simple_ControledFunctionTest2.res
+ :language: none
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo06.rst
+
+- :ref:`section_ref_algorithm_InputValuesTest`
+- :ref:`section_ref_algorithm_LinearityTest`
+- :ref:`section_ref_algorithm_FunctionTest`
+- :ref:`section_ref_algorithm_ParallelFunctionTest`
- :ref:`section_ref_algorithm_InputValuesTest`
- :ref:`section_ref_algorithm_LinearityTest`
+- :ref:`section_ref_algorithm_ControledFunctionTest`
- :ref:`section_ref_algorithm_ParallelFunctionTest`
- :ref:`section_ref_algorithm_EnsembleOfSimulationGenerationTask`
.. include:: snippets/Header2Algo06.rst
+- :ref:`section_ref_algorithm_ControledFunctionTest`
- :ref:`section_ref_algorithm_FunctionTest`
- :ref:`section_ref_algorithm_ParallelFunctionTest`
.. ------------------------------------ ..
.. include:: snippets/Header2Algo06.rst
-- :ref:`section_ref_algorithm_FunctionTest`
- :ref:`section_ref_algorithm_InputValuesTest`
- :ref:`section_ref_algorithm_LinearityTest`
+- :ref:`section_ref_algorithm_FunctionTest`
+- :ref:`section_ref_algorithm_ControledFunctionTest`
- :ref:`section_ref_algorithm_EnsembleOfSimulationGenerationTask`
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+from numpy import array, eye
+from adao import adaoBuilder
+case = adaoBuilder.New()
+case.setCheckingPoint( Vector = array([0., 1., 2.]), Stored=True )
+case.setObservationOperator( Matrix = eye(3) )
+case.setAlgorithmParameters(
+ Algorithm='ControledFunctionTest',
+ Parameters={
+ 'NumberOfRepetition' : 5,
+ 'NumberOfPrintedDigits' : 2,
+ 'ShowElementarySummary':False,
+ },
+ )
+case.setControlInput( Vector = 1. )
+case.execute()
--- /dev/null
+
+ CONTROLEDFUNCTIONTEST
+ =====================
+
+ This test allows to analyze the (repetition of the) launch of some
+ given simulation operator F, applied to one single vector x and to
+ one control vector u as arguments, in a sequential way.
+ The output shows simple statistics related to its successful execution,
+ or related to the similarities of repetition of its execution.
+
+===> Information before launching:
+ -----------------------------
+
+ Characteristics of input vector X, internally converted:
+ Type...............: <class 'numpy.ndarray'>
+ Length of vector...: 3
+ Minimum value......: 0.00e+00
+ Maximum value......: 2.00e+00
+ Mean of vector.....: 1.00e+00
+ Standard error.....: 8.16e-01
+ L2 norm of vector..: 2.24e+00
+
+ Characteristics of control parameter U, internally converted:
+ Type...............: <class 'numpy.ndarray'>
+ Length of vector...: 1
+ Minimum value......: 1.00e+00
+ Maximum value......: 1.00e+00
+ Mean of vector.....: 1.00e+00
+ Standard error.....: 0.00e+00
+ L2 norm of vector..: 1.00e+00
+
+ ---------------------------------------------------------------------------
+
+===> Beginning of repeated evaluation, without activating debug
+
+ ---------------------------------------------------------------------------
+
+===> End of repeated evaluation, without deactivating debug
+
+ ---------------------------------------------------------------------------
+
+===> Launching statistical summary calculation for 5 states
+
+ ---------------------------------------------------------------------------
+
+===> Statistical analysis of the outputs obtained through sequential repeated evaluations
+
+ (Remark: numbers that are (about) under 2e-16 represent 0 to machine precision)
+
+ Number of evaluations...........................: 5
+
+ Characteristics of the whole set of outputs Y:
+ Size of each of the outputs...................: 3
+ Minimum value of the whole set of outputs.....: 0.00e+00
+ Maximum value of the whole set of outputs.....: 2.00e+00
+ Mean of vector of the whole set of outputs....: 1.00e+00
+ Standard error of the whole set of outputs....: 8.16e-01
+
+ Characteristics of the vector Ym, mean of the outputs Y:
+ Size of the mean of the outputs...............: 3
+ Minimum value of the mean of the outputs......: 0.00e+00
+ Maximum value of the mean of the outputs......: 2.00e+00
+ Mean of the mean of the outputs...............: 1.00e+00
+ Standard error of the mean of the outputs.....: 8.16e-01
+
+ Characteristics of the mean of the differences between the outputs Y and their mean Ym:
+ Size of the mean of the differences...........: 3
+ Minimum value of the mean of the differences..: 0.00e+00
+ Maximum value of the mean of the differences..: 0.00e+00
+ Mean of the mean of the differences...........: 0.00e+00
+ Standard error of the mean of the differences.: 0.00e+00
+
+ ---------------------------------------------------------------------------
+
--- /dev/null
+.. index:: single: ControledFunctionTest (example)
+
+First example
+.............
+
+This example describes the test that the given operator works properly, and
+that its call proceeds in a way compatible with its common use in the ADAO
+algorithms. The required information are minimal, namely here an operator
+:math:`F` (described for the test by the command "*ObservationOperator*"), a
+particular state :math:`\mathbf{x}` to test it on (described for the test by
+the command "*CheckingPoint*") and a control :math:`\mathbf{u}` (described for
+the test by the command "*ControlInput*"), both being not necessarily of the
+same size.
+
+The test is repeated a configurable number of times, and a final statistic
+makes it possible to quickly verify the operator's good behavior. The simplest
+diagnostic consists in checking, at the very end of the display, the order of
+magnitude of variations in the values indicated as the mean of the differences between the
+repeated outputs and their mean, under the part entitled "*Characteristics of
+the mean of the differences between the outputs Y and their mean Ym*". For a
+satisfactory operator, these values should be close to the numerical zero.
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+from numpy import array, ravel
+def ControledQuadFunction( pair ):
+ """
+ Controlled quadratic simulation
+ """
+ coefficients, control = pair
+ #
+ u, v = list(ravel(control))
+ a, b, c = list(ravel(coefficients))
+ x_points = (-5, 0, 1, 3, 10)
+ y_points = []
+ for x in x_points:
+ y_points.append( (a*x*x + b*x + c + v) * u )
+ return array(y_points)
+#
+from adao import adaoBuilder
+case = adaoBuilder.New()
+case.set( 'CheckingPoint', Vector = array([1., 1., 1.]), Stored=True )
+case.set( 'ObservationOperator', ThreeFunctions = {
+ "Direct" :ControledQuadFunction,
+ "Tangent":0, # Empty operator (not None) as not used
+ "Adjoint":0, # Empty operator (not None) as not used
+ } )
+case.set( "ControlInput", Vector = (1, 0) )
+case.setAlgorithmParameters(
+ Algorithm='ControledFunctionTest',
+ Parameters={
+ 'NumberOfRepetition' : 15,
+ 'NumberOfPrintedDigits' : 3,
+ 'ShowElementarySummary':False,
+ },
+ )
+case.execute()
--- /dev/null
+
+ CONTROLEDFUNCTIONTEST
+ =====================
+
+ This test allows to analyze the (repetition of the) launch of some
+ given simulation operator F, applied to one single vector x and to
+ one control vector u as arguments, in a sequential way.
+ The output shows simple statistics related to its successful execution,
+ or related to the similarities of repetition of its execution.
+
+===> Information before launching:
+ -----------------------------
+
+ Characteristics of input vector X, internally converted:
+ Type...............: <class 'numpy.ndarray'>
+ Length of vector...: 3
+ Minimum value......: 1.000e+00
+ Maximum value......: 1.000e+00
+ Mean of vector.....: 1.000e+00
+ Standard error.....: 0.000e+00
+ L2 norm of vector..: 1.732e+00
+
+ Characteristics of control parameter U, internally converted:
+ Type...............: <class 'numpy.ndarray'>
+ Length of vector...: 2
+ Minimum value......: 0.000e+00
+ Maximum value......: 1.000e+00
+ Mean of vector.....: 5.000e-01
+ Standard error.....: 5.000e-01
+ L2 norm of vector..: 1.000e+00
+
+ ---------------------------------------------------------------------------
+
+===> Beginning of repeated evaluation, without activating debug
+
+ ---------------------------------------------------------------------------
+
+===> End of repeated evaluation, without deactivating debug
+
+ ---------------------------------------------------------------------------
+
+===> Launching statistical summary calculation for 15 states
+
+ ---------------------------------------------------------------------------
+
+===> Statistical analysis of the outputs obtained through sequential repeated evaluations
+
+ (Remark: numbers that are (about) under 2e-16 represent 0 to machine precision)
+
+ Number of evaluations...........................: 15
+
+ Characteristics of the whole set of outputs Y:
+ Size of each of the outputs...................: 5
+ Minimum value of the whole set of outputs.....: 1.000e+00
+ Maximum value of the whole set of outputs.....: 1.110e+02
+ Mean of vector of the whole set of outputs....: 2.980e+01
+ Standard error of the whole set of outputs....: 4.123e+01
+
+ Characteristics of the vector Ym, mean of the outputs Y:
+ Size of the mean of the outputs...............: 5
+ Minimum value of the mean of the outputs......: 1.000e+00
+ Maximum value of the mean of the outputs......: 1.110e+02
+ Mean of the mean of the outputs...............: 2.980e+01
+ Standard error of the mean of the outputs.....: 4.123e+01
+
+ Characteristics of the mean of the differences between the outputs Y and their mean Ym:
+ Size of the mean of the differences...........: 5
+ Minimum value of the mean of the differences..: 0.000e+00
+ Maximum value of the mean of the differences..: 0.000e+00
+ Mean of the mean of the differences...........: 0.000e+00
+ Standard error of the mean of the differences.: 0.000e+00
+
+ ---------------------------------------------------------------------------
+
--- /dev/null
+Second example
+..............
+
+This new example describes the test of the correct operation of a given
+operator named ``ControledQuadFunction``, available under its functional form.
+It is defined by the command "*ObservationOperator*" as
+:ref:`section_ref_operator_funcs` (here, even with this functional form, one
+can exceptionally not define the tangent and adjoint forms of the operator
+because they are not useful in this test). Using the command "*CheckingPoint*",
+one add also a particular state :math:`\mathbf{x}` to test the operator on, and
+using the command "*ControlInput*", one add a fixed control :math:`\mathbf{u}`.
+
+The test is repeated here 15 times, and a final statistic makes it possible to
+quickly verify the operator's good behavior. The simplest diagnostic consists
+in checking, at the very end of the display, the order of magnitude of
+variations in the values indicated as the mean of the differences between the
+repeated outputs and their mean, under the part entitled "*Characteristics of
+the mean of the differences between the outputs Y and their mean Ym*". For a
+satisfactory operator, these values should be close to the numerical zero.
--- /dev/null
+..
+ Copyright (C) 2008-2023 EDF R&D
+
+ This file is part of SALOME ADAO module.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
+ Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+
+.. index:: single: ControledFunctionTest
+.. _section_ref_algorithm_ControledFunctionTest:
+
+Algorithme de vérification "*ControledFunctionTest*"
+----------------------------------------------------
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo01.rst
+
+Cet algorithme permet de vérifier qu'un opérateur :math:`F` quelconque, dont en
+particulier celui d'observation, fonctionne correctement et que son appel se
+déroule de manière compatible avec son usage dans les algorithmes d'ADAO. De
+manière pratique, il permet d'appeler une ou plusieurs fois l'opérateur, en
+activant ou non le mode "debug" lors de l'exécution. L'opérateur :math:`F` est
+considéré comme dépendant d'une variable vectorielle :math:`\mathbf{x}` et d'un
+contrôle :math:`\mathbf{u}`, les deux n'étant pas nécessairement de la même
+taille.
+
+Une statistique sur les vecteurs en entrée et en sortie de chaque exécution de
+l'opérateur est indiquée, et une autre globale est fournie de manière
+récapitulative à la fin de l'algorithme de vérification. La précision
+d'affichage est contrôlable pour permettre l'automatisation des tests
+d'opérateur. Il peut être aussi utile de vérifier préalablement les entrées
+elles-mêmes avec le test prévu :ref:`section_ref_algorithm_InputValuesTest`.
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo02.rst
+
+.. include:: snippets/CheckingPoint.rst
+
+.. include:: snippets/ObservationOperator.rst
+
+.. include:: snippets/ControlInput.rst
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo03Chck.rst
+
+.. include:: snippets/NumberOfPrintedDigits.rst
+
+.. include:: snippets/NumberOfRepetition.rst
+
+.. include:: snippets/SetDebug.rst
+
+.. include:: snippets/ShowElementarySummary.rst
+
+StoreSupplementaryCalculations
+ .. index:: single: StoreSupplementaryCalculations
+
+ *Liste de noms*. Cette liste indique les noms des variables supplémentaires,
+ qui peuvent être disponibles au cours du déroulement ou à la fin de
+ l'algorithme, si elles sont initialement demandées par l'utilisateur. Leur
+ disponibilité implique, potentiellement, des calculs ou du stockage coûteux.
+ La valeur par défaut est donc une liste vide, aucune de ces variables n'étant
+ calculée et stockée par défaut (sauf les variables inconditionnelles). Les
+ noms possibles pour les variables supplémentaires sont dans la liste suivante
+ (la description détaillée de chaque variable nommée est donnée dans la suite
+ de cette documentation par algorithme spécifique, dans la sous-partie
+ "*Informations et variables disponibles à la fin de l'algorithme*") : [
+ "CurrentState",
+ "SimulatedObservationAtCurrentState",
+ ].
+
+ Exemple :
+ ``{"StoreSupplementaryCalculations":["CurrentState", "Residu"]}``
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo04.rst
+
+.. include:: snippets/NoUnconditionalOutput.rst
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo05.rst
+
+.. include:: snippets/CurrentState.rst
+
+.. include:: snippets/SimulatedObservationAtCurrentState.rst
+
+.. ------------------------------------ ..
+.. _section_ref_algorithm_ControledFunctionTest_examples:
+
+.. include:: snippets/Header2Algo09.rst
+
+.. --------- ..
+.. include:: scripts/simple_ControledFunctionTest1.rst
+
+.. literalinclude:: scripts/simple_ControledFunctionTest1.py
+
+.. include:: snippets/Header2Algo10.rst
+
+.. literalinclude:: scripts/simple_ControledFunctionTest1.res
+ :language: none
+
+.. --------- ..
+.. include:: scripts/simple_ControledFunctionTest2.rst
+
+.. literalinclude:: scripts/simple_ControledFunctionTest2.py
+
+.. include:: snippets/Header2Algo10.rst
+
+.. literalinclude:: scripts/simple_ControledFunctionTest2.res
+ :language: none
+
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo06.rst
+
+- :ref:`section_ref_algorithm_InputValuesTest`
+- :ref:`section_ref_algorithm_LinearityTest`
+- :ref:`section_ref_algorithm_FunctionTest`
+- :ref:`section_ref_algorithm_ParallelFunctionTest`
- :ref:`section_ref_algorithm_InputValuesTest`
- :ref:`section_ref_algorithm_LinearityTest`
+- :ref:`section_ref_algorithm_ControledFunctionTest`
- :ref:`section_ref_algorithm_ParallelFunctionTest`
- :ref:`section_ref_algorithm_EnsembleOfSimulationGenerationTask`
.. ------------------------------------ ..
.. include:: snippets/Header2Algo06.rst
-- :ref:`section_ref_algorithm_FunctionTest`
- :ref:`section_ref_algorithm_InputValuesTest`
- :ref:`section_ref_algorithm_LinearityTest`
+- :ref:`section_ref_algorithm_FunctionTest`
+- :ref:`section_ref_algorithm_ControledFunctionTest`
- :ref:`section_ref_algorithm_EnsembleOfSimulationGenerationTask`
:maxdepth: 1
ref_algorithm_AdjointTest
+ ref_algorithm_ControledFunctionTest
ref_algorithm_FunctionTest
ref_algorithm_GradientTest
ref_algorithm_InputValuesTest
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+from numpy import array, eye
+from adao import adaoBuilder
+case = adaoBuilder.New()
+case.setCheckingPoint( Vector = array([0., 1., 2.]), Stored=True )
+case.setObservationOperator( Matrix = eye(3) )
+case.setAlgorithmParameters(
+ Algorithm='ControledFunctionTest',
+ Parameters={
+ 'NumberOfRepetition' : 5,
+ 'NumberOfPrintedDigits' : 2,
+ 'ShowElementarySummary':False,
+ },
+ )
+case.setControlInput( Vector = 1. )
+case.execute()
--- /dev/null
+
+ CONTROLEDFUNCTIONTEST
+ =====================
+
+ This test allows to analyze the (repetition of the) launch of some
+ given simulation operator F, applied to one single vector x and to
+ one control vector u as arguments, in a sequential way.
+ The output shows simple statistics related to its successful execution,
+ or related to the similarities of repetition of its execution.
+
+===> Information before launching:
+ -----------------------------
+
+ Characteristics of input vector X, internally converted:
+ Type...............: <class 'numpy.ndarray'>
+ Length of vector...: 3
+ Minimum value......: 0.00e+00
+ Maximum value......: 2.00e+00
+ Mean of vector.....: 1.00e+00
+ Standard error.....: 8.16e-01
+ L2 norm of vector..: 2.24e+00
+
+ Characteristics of control parameter U, internally converted:
+ Type...............: <class 'numpy.ndarray'>
+ Length of vector...: 1
+ Minimum value......: 1.00e+00
+ Maximum value......: 1.00e+00
+ Mean of vector.....: 1.00e+00
+ Standard error.....: 0.00e+00
+ L2 norm of vector..: 1.00e+00
+
+ ---------------------------------------------------------------------------
+
+===> Beginning of repeated evaluation, without activating debug
+
+ ---------------------------------------------------------------------------
+
+===> End of repeated evaluation, without deactivating debug
+
+ ---------------------------------------------------------------------------
+
+===> Launching statistical summary calculation for 5 states
+
+ ---------------------------------------------------------------------------
+
+===> Statistical analysis of the outputs obtained through sequential repeated evaluations
+
+ (Remark: numbers that are (about) under 2e-16 represent 0 to machine precision)
+
+ Number of evaluations...........................: 5
+
+ Characteristics of the whole set of outputs Y:
+ Size of each of the outputs...................: 3
+ Minimum value of the whole set of outputs.....: 0.00e+00
+ Maximum value of the whole set of outputs.....: 2.00e+00
+ Mean of vector of the whole set of outputs....: 1.00e+00
+ Standard error of the whole set of outputs....: 8.16e-01
+
+ Characteristics of the vector Ym, mean of the outputs Y:
+ Size of the mean of the outputs...............: 3
+ Minimum value of the mean of the outputs......: 0.00e+00
+ Maximum value of the mean of the outputs......: 2.00e+00
+ Mean of the mean of the outputs...............: 1.00e+00
+ Standard error of the mean of the outputs.....: 8.16e-01
+
+ Characteristics of the mean of the differences between the outputs Y and their mean Ym:
+ Size of the mean of the differences...........: 3
+ Minimum value of the mean of the differences..: 0.00e+00
+ Maximum value of the mean of the differences..: 0.00e+00
+ Mean of the mean of the differences...........: 0.00e+00
+ Standard error of the mean of the differences.: 0.00e+00
+
+ ---------------------------------------------------------------------------
+
--- /dev/null
+.. index:: single: ControledFunctionTest (exemple)
+
+Premier exemple
+...............
+
+Cet exemple décrit le test du bon fonctionnement d'un opérateur quelconque, et
+que son appel se déroule de manière compatible avec son usage courant dans les
+algorithmes d'ADAO. Les informations nécessaires sont minimales, à savoir ici
+un opérateur (décrit pour le test par la commande d'observation
+"*ObservationOperator*"), un état particulier :math:`\mathbf{x}` sur lequel le
+tester (décrit pour le test par la commande "*CheckingPoint*") et un contrôle
+:math:`\mathbf{u}` (décrit pour le test par la commande "*ControlInput*"), les
+deux n'étant pas nécessairement de la même taille.
+
+Le test est répété un nombre paramétrable de fois, et une statistique finale
+permet de vérifier rapidement le bon comportement de l'opérateur. Le diagnostic
+le plus simple consiste à vérifier, à la toute fin de l'affichage, l'ordre de
+grandeur des variations des valeurs indiquées comme la moyenne des différences
+entre les sorties répétées et leur moyenne, sous la partie titrée
+"*Characteristics of the mean of the differences between the outputs Y and
+their mean Ym*". Pour un opérateur satisfaisant, ces valeurs doivent être
+proches du zéro numérique.
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+from numpy import array, ravel
+def ControledQuadFunction( paire ):
+ """
+ Simulation quadratique contrôlée
+ """
+ coefficients, controle = paire
+ #
+ u, v = list(ravel(controle))
+ a, b, c = list(ravel(coefficients))
+ x_points = (-5, 0, 1, 3, 10)
+ y_points = []
+ for x in x_points:
+ y_points.append( (a*x*x + b*x + c + v) * u )
+ return array(y_points)
+#
+from adao import adaoBuilder
+case = adaoBuilder.New()
+case.set( 'CheckingPoint', Vector = array([1., 1., 1.]), Stored=True )
+case.set( 'ObservationOperator', ThreeFunctions = {
+ "Direct" :ControledQuadFunction,
+ "Tangent":0, # Opérateur vide (et pas None) car non utilisé
+ "Adjoint":0, # Opérateur vide (et pas None) car non utilisé
+ } )
+case.set( "ControlInput", Vector = (1, 0) )
+case.setAlgorithmParameters(
+ Algorithm='ControledFunctionTest',
+ Parameters={
+ 'NumberOfRepetition' : 15,
+ 'NumberOfPrintedDigits' : 3,
+ 'ShowElementarySummary':False,
+ },
+ )
+case.execute()
--- /dev/null
+
+ CONTROLEDFUNCTIONTEST
+ =====================
+
+ This test allows to analyze the (repetition of the) launch of some
+ given simulation operator F, applied to one single vector x and to
+ one control vector u as arguments, in a sequential way.
+ The output shows simple statistics related to its successful execution,
+ or related to the similarities of repetition of its execution.
+
+===> Information before launching:
+ -----------------------------
+
+ Characteristics of input vector X, internally converted:
+ Type...............: <class 'numpy.ndarray'>
+ Length of vector...: 3
+ Minimum value......: 1.000e+00
+ Maximum value......: 1.000e+00
+ Mean of vector.....: 1.000e+00
+ Standard error.....: 0.000e+00
+ L2 norm of vector..: 1.732e+00
+
+ Characteristics of control parameter U, internally converted:
+ Type...............: <class 'numpy.ndarray'>
+ Length of vector...: 2
+ Minimum value......: 0.000e+00
+ Maximum value......: 1.000e+00
+ Mean of vector.....: 5.000e-01
+ Standard error.....: 5.000e-01
+ L2 norm of vector..: 1.000e+00
+
+ ---------------------------------------------------------------------------
+
+===> Beginning of repeated evaluation, without activating debug
+
+ ---------------------------------------------------------------------------
+
+===> End of repeated evaluation, without deactivating debug
+
+ ---------------------------------------------------------------------------
+
+===> Launching statistical summary calculation for 15 states
+
+ ---------------------------------------------------------------------------
+
+===> Statistical analysis of the outputs obtained through sequential repeated evaluations
+
+ (Remark: numbers that are (about) under 2e-16 represent 0 to machine precision)
+
+ Number of evaluations...........................: 15
+
+ Characteristics of the whole set of outputs Y:
+ Size of each of the outputs...................: 5
+ Minimum value of the whole set of outputs.....: 1.000e+00
+ Maximum value of the whole set of outputs.....: 1.110e+02
+ Mean of vector of the whole set of outputs....: 2.980e+01
+ Standard error of the whole set of outputs....: 4.123e+01
+
+ Characteristics of the vector Ym, mean of the outputs Y:
+ Size of the mean of the outputs...............: 5
+ Minimum value of the mean of the outputs......: 1.000e+00
+ Maximum value of the mean of the outputs......: 1.110e+02
+ Mean of the mean of the outputs...............: 2.980e+01
+ Standard error of the mean of the outputs.....: 4.123e+01
+
+ Characteristics of the mean of the differences between the outputs Y and their mean Ym:
+ Size of the mean of the differences...........: 5
+ Minimum value of the mean of the differences..: 0.000e+00
+ Maximum value of the mean of the differences..: 0.000e+00
+ Mean of the mean of the differences...........: 0.000e+00
+ Standard error of the mean of the differences.: 0.000e+00
+
+ ---------------------------------------------------------------------------
+
--- /dev/null
+Deuxième exemple
+................
+
+Ce nouvel exemple décrit le test du bon fonctionnement d'un opérateur
+quelconque nommé ``ControledQuadFunction``, disponible sous forme
+fonctionnelle. Il est définit par la commande "*ObservationOperator*" selon la
+:ref:`section_ref_operator_funcs` (ici, même avec cette forme fonctionnelle, on
+peut exceptionnellement ne pas définir les formes tangente et adjointe de
+l'opérateur car elles ne sont pas utiles dans ce test). Par la commande
+"*CheckingPoint*", on ajoute aussi un état particulier :math:`\mathbf{x}` sur
+lequel tester l'opérateur, et par la commande "*ControlInput*" on ajoute un
+contrôle fixe :math:`\mathbf{u}`.
+
+Ce test est répété ici 15 fois, et une statistique finale permet de vérifier
+rapidement le bon comportement de l'opérateur. Le diagnostic le plus simple
+consiste à vérifier, à la toute fin de l'affichage, l'ordre de grandeur des
+variations des valeurs indiquées comme la moyenne des différences entre les
+sorties répétées et leur moyenne, sous la partie titrée "*Characteristics of
+the mean of the differences between the outputs Y and their mean Ym*". Pour
+qu'un opérateur soit satisfaisant, ces valeurs doivent être proches du zéro
+numérique.
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2008-2023 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+
+import numpy, copy, logging
+from daCore import BasicObjects, PlatformInfo
+mpr = PlatformInfo.PlatformInfo().MachinePrecision()
+mfp = PlatformInfo.PlatformInfo().MaximumPrecision()
+
+# ==============================================================================
+class ElementaryAlgorithm(BasicObjects.Algorithm):
+ def __init__(self):
+ BasicObjects.Algorithm.__init__(self, "CONTROLEDFUNCTIONTEST")
+ self.defineRequiredParameter(
+ name = "ShowElementarySummary",
+ default = True,
+ typecast = bool,
+ message = "Calcule et affiche un résumé à chaque évaluation élémentaire",
+ )
+ self.defineRequiredParameter(
+ name = "NumberOfPrintedDigits",
+ default = 5,
+ typecast = int,
+ message = "Nombre de chiffres affichés pour les impressions de réels",
+ minval = 0,
+ )
+ self.defineRequiredParameter(
+ name = "NumberOfRepetition",
+ default = 1,
+ typecast = int,
+ message = "Nombre de fois où l'exécution de la fonction est répétée",
+ minval = 1,
+ )
+ self.defineRequiredParameter(
+ name = "ResultTitle",
+ default = "",
+ typecast = str,
+ message = "Titre du tableau et de la figure",
+ )
+ self.defineRequiredParameter(
+ name = "SetDebug",
+ default = False,
+ typecast = bool,
+ message = "Activation du mode debug lors de l'exécution",
+ )
+ self.defineRequiredParameter(
+ name = "StoreSupplementaryCalculations",
+ default = [],
+ typecast = tuple,
+ message = "Liste de calculs supplémentaires à stocker et/ou effectuer",
+ listval = [
+ "CurrentState",
+ "SimulatedObservationAtCurrentState",
+ ]
+ )
+ self.requireInputArguments(
+ mandatory= ("Xb", "HO"),
+ optional = ("U"),
+ )
+ self.setAttributes(tags=(
+ "Checking",
+ ))
+
+ def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
+ self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
+ #
+ Hm = HO["Direct"].appliedControledFormTo
+ #
+ X0 = copy.copy( Xb )
+ if U is not None:
+ if hasattr(U,"store") and len(U)>1:
+ Un = numpy.ravel( U[step] ).reshape((-1,1))
+ elif hasattr(U,"store") and len(U)==1:
+ Un = numpy.ravel( U[0] ).reshape((-1,1))
+ else:
+ Un = numpy.ravel( U ).reshape((-1,1))
+ else:
+ Un = None
+ #
+ # ----------
+ __s = self._parameters["ShowElementarySummary"]
+ __p = self._parameters["NumberOfPrintedDigits"]
+ __r = self._parameters["NumberOfRepetition"]
+ #
+ __marge = 5*u" "
+ __flech = 3*"="+"> "
+ msgs = ("\n") # 1
+ if len(self._parameters["ResultTitle"]) > 0:
+ __rt = str(self._parameters["ResultTitle"])
+ msgs += (__marge + "====" + "="*len(__rt) + "====\n")
+ msgs += (__marge + " " + __rt + "\n")
+ msgs += (__marge + "====" + "="*len(__rt) + "====\n")
+ else:
+ msgs += (__marge + "%s\n"%self._name)
+ msgs += (__marge + "%s\n"%("="*len(self._name),))
+ #
+ msgs += ("\n")
+ msgs += (__marge + "This test allows to analyze the (repetition of the) launch of some\n")
+ msgs += (__marge + "given simulation operator F, applied to one single vector x and to\n")
+ msgs += (__marge + "one control vector u as arguments, in a sequential way.\n")
+ msgs += (__marge + "The output shows simple statistics related to its successful execution,\n")
+ msgs += (__marge + "or related to the similarities of repetition of its execution.\n")
+ msgs += ("\n")
+ msgs += (__flech + "Information before launching:\n")
+ msgs += (__marge + "-----------------------------\n")
+ msgs += ("\n")
+ msgs += (__marge + "Characteristics of input vector X, internally converted:\n")
+ msgs += (__marge + " Type...............: %s\n")%type( X0 )
+ msgs += (__marge + " Length of vector...: %i\n")%max(numpy.ravel( X0 ).shape)
+ msgs += (__marge + " Minimum value......: %."+str(__p)+"e\n")%numpy.min( X0 )
+ msgs += (__marge + " Maximum value......: %."+str(__p)+"e\n")%numpy.max( X0 )
+ msgs += (__marge + " Mean of vector.....: %."+str(__p)+"e\n")%numpy.mean( X0, dtype=mfp )
+ msgs += (__marge + " Standard error.....: %."+str(__p)+"e\n")%numpy.std( X0, dtype=mfp )
+ msgs += (__marge + " L2 norm of vector..: %."+str(__p)+"e\n")%numpy.linalg.norm( X0 )
+ msgs += ("\n")
+ if Un is None:
+ msgs += (__marge + "Characteristics of control parameter U, internally converted: None\n")
+ else:
+ msgs += (__marge + "Characteristics of control parameter U, internally converted:\n")
+ msgs += (__marge + " Type...............: %s\n")%type( Un )
+ msgs += (__marge + " Length of vector...: %i\n")%max(numpy.ravel( Un ).shape)
+ msgs += (__marge + " Minimum value......: %."+str(__p)+"e\n")%numpy.min( Un )
+ msgs += (__marge + " Maximum value......: %."+str(__p)+"e\n")%numpy.max( Un )
+ msgs += (__marge + " Mean of vector.....: %."+str(__p)+"e\n")%numpy.mean( Un, dtype=mfp )
+ msgs += (__marge + " Standard error.....: %."+str(__p)+"e\n")%numpy.std( Un, dtype=mfp )
+ msgs += (__marge + " L2 norm of vector..: %."+str(__p)+"e\n")%numpy.linalg.norm( Un )
+ msgs += ("\n")
+ msgs += (__marge + "%s\n\n"%("-"*75,))
+ #
+ if self._parameters["SetDebug"]:
+ CUR_LEVEL = logging.getLogger().getEffectiveLevel()
+ logging.getLogger().setLevel(logging.DEBUG)
+ if __r > 1:
+ msgs += (__flech + "Beginning of repeated evaluation, activating debug\n")
+ else:
+ msgs += (__flech + "Beginning of evaluation, activating debug\n")
+ else:
+ if __r > 1:
+ msgs += (__flech + "Beginning of repeated evaluation, without activating debug\n")
+ else:
+ msgs += (__flech + "Beginning of evaluation, without activating debug\n")
+ print(msgs) # 1
+ #
+ # ----------
+ HO["Direct"].disableAvoidingRedundancy()
+ # ----------
+ Ys = []
+ for i in range(__r):
+ if self._toStore("CurrentState"):
+ self.StoredVariables["CurrentState"].store( X0 )
+ if __s:
+ msgs = (__marge + "%s\n"%("-"*75,)) # 2-1
+ if __r > 1:
+ msgs += ("\n")
+ msgs += (__flech + "Repetition step number %i on a total of %i\n"%(i+1,__r))
+ msgs += ("\n")
+ msgs += (__flech + "Launching operator sequential evaluation\n")
+ print(msgs) # 2-1
+ #
+ Yn = Hm( (X0, Un) )
+ #
+ if __s:
+ msgs = ("\n") # 2-2
+ msgs += (__flech + "End of operator sequential evaluation\n")
+ msgs += ("\n")
+ msgs += (__flech + "Information after evaluation:\n")
+ msgs += ("\n")
+ msgs += (__marge + "Characteristics of simulated output vector Y=F((X,U)), to compare to others:\n")
+ msgs += (__marge + " Type...............: %s\n")%type( Yn )
+ msgs += (__marge + " Length of vector...: %i\n")%max(numpy.ravel( Yn ).shape)
+ msgs += (__marge + " Minimum value......: %."+str(__p)+"e\n")%numpy.min( Yn )
+ msgs += (__marge + " Maximum value......: %."+str(__p)+"e\n")%numpy.max( Yn )
+ msgs += (__marge + " Mean of vector.....: %."+str(__p)+"e\n")%numpy.mean( Yn, dtype=mfp )
+ msgs += (__marge + " Standard error.....: %."+str(__p)+"e\n")%numpy.std( Yn, dtype=mfp )
+ msgs += (__marge + " L2 norm of vector..: %."+str(__p)+"e\n")%numpy.linalg.norm( Yn )
+ print(msgs) # 2-2
+ if self._toStore("SimulatedObservationAtCurrentState"):
+ self.StoredVariables["SimulatedObservationAtCurrentState"].store( numpy.ravel(Yn) )
+ #
+ Ys.append( copy.copy( numpy.ravel(
+ Yn
+ ) ) )
+ # ----------
+ HO["Direct"].enableAvoidingRedundancy()
+ # ----------
+ #
+ msgs = (__marge + "%s\n\n"%("-"*75,)) # 3
+ if self._parameters["SetDebug"]:
+ if __r > 1:
+ msgs += (__flech + "End of repeated evaluation, deactivating debug if necessary\n")
+ else:
+ msgs += (__flech + "End of evaluation, deactivating debug if necessary\n")
+ logging.getLogger().setLevel(CUR_LEVEL)
+ else:
+ if __r > 1:
+ msgs += (__flech + "End of repeated evaluation, without deactivating debug\n")
+ else:
+ msgs += (__flech + "End of evaluation, without deactivating debug\n")
+ msgs += ("\n")
+ msgs += (__marge + "%s\n"%("-"*75,))
+ #
+ if __r > 1:
+ msgs += ("\n")
+ msgs += (__flech + "Launching statistical summary calculation for %i states\n"%__r)
+ msgs += ("\n")
+ msgs += (__marge + "%s\n"%("-"*75,))
+ msgs += ("\n")
+ msgs += (__flech + "Statistical analysis of the outputs obtained through sequential repeated evaluations\n")
+ msgs += ("\n")
+ msgs += (__marge + "(Remark: numbers that are (about) under %.0e represent 0 to machine precision)\n"%mpr)
+ msgs += ("\n")
+ Yy = numpy.array( Ys )
+ msgs += (__marge + "Number of evaluations...........................: %i\n")%len( Ys )
+ msgs += ("\n")
+ msgs += (__marge + "Characteristics of the whole set of outputs Y:\n")
+ msgs += (__marge + " Size of each of the outputs...................: %i\n")%Ys[0].size
+ msgs += (__marge + " Minimum value of the whole set of outputs.....: %."+str(__p)+"e\n")%numpy.min( Yy )
+ msgs += (__marge + " Maximum value of the whole set of outputs.....: %."+str(__p)+"e\n")%numpy.max( Yy )
+ msgs += (__marge + " Mean of vector of the whole set of outputs....: %."+str(__p)+"e\n")%numpy.mean( Yy, dtype=mfp )
+ msgs += (__marge + " Standard error of the whole set of outputs....: %."+str(__p)+"e\n")%numpy.std( Yy, dtype=mfp )
+ msgs += ("\n")
+ Ym = numpy.mean( numpy.array( Ys ), axis=0, dtype=mfp )
+ msgs += (__marge + "Characteristics of the vector Ym, mean of the outputs Y:\n")
+ msgs += (__marge + " Size of the mean of the outputs...............: %i\n")%Ym.size
+ msgs += (__marge + " Minimum value of the mean of the outputs......: %."+str(__p)+"e\n")%numpy.min( Ym )
+ msgs += (__marge + " Maximum value of the mean of the outputs......: %."+str(__p)+"e\n")%numpy.max( Ym )
+ msgs += (__marge + " Mean of the mean of the outputs...............: %."+str(__p)+"e\n")%numpy.mean( Ym, dtype=mfp )
+ msgs += (__marge + " Standard error of the mean of the outputs.....: %."+str(__p)+"e\n")%numpy.std( Ym, dtype=mfp )
+ msgs += ("\n")
+ Ye = numpy.mean( numpy.array( Ys ) - Ym, axis=0, dtype=mfp )
+ msgs += (__marge + "Characteristics of the mean of the differences between the outputs Y and their mean Ym:\n")
+ msgs += (__marge + " Size of the mean of the differences...........: %i\n")%Ye.size
+ msgs += (__marge + " Minimum value of the mean of the differences..: %."+str(__p)+"e\n")%numpy.min( Ye )
+ msgs += (__marge + " Maximum value of the mean of the differences..: %."+str(__p)+"e\n")%numpy.max( Ye )
+ msgs += (__marge + " Mean of the mean of the differences...........: %."+str(__p)+"e\n")%numpy.mean( Ye, dtype=mfp )
+ msgs += (__marge + " Standard error of the mean of the differences.: %."+str(__p)+"e\n")%numpy.std( Ye, dtype=mfp )
+ msgs += ("\n")
+ msgs += (__marge + "%s\n"%("-"*75,))
+ #
+ msgs += ("\n")
+ msgs += (__marge + "End of the \"%s\" verification\n\n"%self._name)
+ msgs += (__marge + "%s\n"%("-"*75,))
+ print(msgs) # 3
+ #
+ self._post_run(HO)
+ return 0
+
+# ==============================================================================
+if __name__ == "__main__":
+ print('\n AUTODIAGNOSTIC\n')