From: Jean-Philippe ARGAUD Date: Sat, 5 Mar 2022 21:54:35 +0000 (+0100) Subject: Documentation improvements and review X-Git-Tag: V9_9_0a2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ce554104f9f4de7e886553384fd1bbafa7d988b9;p=modules%2Fadao.git Documentation improvements and review --- diff --git a/doc/en/scripts/tui_example_01.py b/doc/en/scripts/tui_example_01.py new file mode 100644 index 0000000..ecec69c --- /dev/null +++ b/doc/en/scripts/tui_example_01.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# +from numpy import array +from adao import adaoBuilder +case = adaoBuilder.New() +case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) +case.set( 'Background', Vector=[0, 1, 2] ) +case.set( 'BackgroundError', ScalarSparseMatrix=1.0 ) +case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) +case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) +case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' ) +case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" ) +case.execute() diff --git a/doc/en/scripts/tui_example_01.res b/doc/en/scripts/tui_example_01.res new file mode 100644 index 0000000..bf97f75 --- /dev/null +++ b/doc/en/scripts/tui_example_01.res @@ -0,0 +1 @@ +Analysis [0.25000264 0.79999797 0.94999939] diff --git a/doc/en/scripts/tui_example_07.py b/doc/en/scripts/tui_example_07.py new file mode 100644 index 0000000..77554d7 --- /dev/null +++ b/doc/en/scripts/tui_example_07.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# +from numpy import array +from adao import adaoBuilder +case = adaoBuilder.New() +case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) +case.set( 'Background', Vector=[0, 1, 2] ) +# +print(case) diff --git a/doc/en/scripts/tui_example_07.res b/doc/en/scripts/tui_example_07.res new file mode 100644 index 0000000..a39599b --- /dev/null +++ b/doc/en/scripts/tui_example_07.res @@ -0,0 +1,11 @@ +================================================================================ +ADAO Study report +================================================================================ + + - AlgorithmParameters command has been set with values: + Algorithm = '3DVAR' + + - Background command has been set with values: + Vector = [0, 1, 2] + + diff --git a/doc/en/scripts/tui_example_11.py b/doc/en/scripts/tui_example_11.py new file mode 100644 index 0000000..c0cbc76 --- /dev/null +++ b/doc/en/scripts/tui_example_11.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +# +import numpy +from adao import adaoBuilder +# +# ============================================================= +# PROBLEM SETTINGS +# +# Artificial building of an example of user data +# ---------------------------------------------- +alpha = 5. +beta = 7 +gamma = 9.0 +# +alphamin, alphamax = 0., 10. +betamin, betamax = 3, 13 +gammamin, gammamax = 1.5, 15.5 +# +def simulation(x): + "Simulation function H to perform Y=H(X)" + __x = numpy.ravel(x) + __H = numpy.array([[1,0,0],[0,2,0],[0,0,3],[1,2,3]]) + return numpy.dot(__H, __x) +# +# Observations obtained by simulation +# ----------------------------------- +Xtrue = (2, 3, 4) +observations = simulation(Xtrue) +# +# ============================================================= +# SOLVING THE PROBLEM +# +# Formatting entries +# ------------------ +Xb = (alpha, beta, gamma) +Bounds = ( + (alphamin, alphamax), + (betamin, betamax ), + (gammamin, gammamax)) +# +# ADAO TUI +# -------- +case = adaoBuilder.New() +case.set( + 'AlgorithmParameters', + Algorithm = '3DVAR', + Parameters = { + "Bounds":Bounds, + "MaximumNumberOfSteps":100, + "StoreSupplementaryCalculations":[ + "CostFunctionJ", + "CurrentState", + "SimulatedObservationAtOptimum", + ], + } + ) +case.set( 'Background', Vector = numpy.array(Xb), Stored = True ) +case.set( 'Observation', Vector = numpy.array(observations) ) +case.set( 'BackgroundError', ScalarSparseMatrix = 1.0e10 ) +case.set( 'ObservationError', ScalarSparseMatrix = 1.0 ) +case.set( + 'ObservationOperator', + OneFunction = simulation, + Parameters = {"DifferentialIncrement":0.0001}, + ) +case.set( 'Observer', Variable="CurrentState", Template="ValuePrinter" ) +case.execute() +# +# Getting variables of interest +# ----------------------------- +Xbackground = case.get("Background") +Xoptimum = case.get("Analysis")[-1] +FX_at_optimum = case.get("SimulatedObservationAtOptimum")[-1] +J_values = case.get("CostFunctionJ")[:] +# +# ============================================================= +# INDEPENDENT HOLDING OF RESULTS +# +print("") +print("Number of internal iterations...: %i"%len(J_values)) +print("Initial state...................: %s"%(numpy.ravel(Xbackground),)) +print("Idealized state.................: %s"%(numpy.ravel(Xtrue)*1.,)) +print("Optimal state...................: %s"%(numpy.ravel(Xoptimum),)) +print("Simulation at optimal state.....: %s"%(numpy.ravel(FX_at_optimum),)) +print("") diff --git a/doc/en/scripts/tui_example_11.res b/doc/en/scripts/tui_example_11.res new file mode 100644 index 0000000..82f6d18 --- /dev/null +++ b/doc/en/scripts/tui_example_11.res @@ -0,0 +1,17 @@ +CurrentState [5. 7. 9.] +CurrentState [0. 3. 1.5] +CurrentState [1.40006418 3.86705307 3.7061137 ] +CurrentState [1.42580231 3.68474804 3.81008738] +CurrentState [1.60220353 3.0677108 4.06146069] +CurrentState [1.72517855 3.03296953 4.04915706] +CurrentState [2.00010755 3. 4.00055409] +CurrentState [1.99995528 3. 3.99996367] +CurrentState [2.00000007 3. 4.00000011] +CurrentState [2. 3. 4.] + +Number of internal iterations...: 10 +Initial state...................: [5. 7. 9.] +Idealized state.................: [2. 3. 4.] +Optimal state...................: [2. 3. 4.] +Simulation at optimal state.....: [ 2. 6. 12. 20.] + diff --git a/doc/en/tui.rst b/doc/en/tui.rst index 6fbe494..e8c8e7c 100644 --- a/doc/en/tui.rst +++ b/doc/en/tui.rst @@ -61,25 +61,16 @@ A simple setup example of an ADAO TUI calculation case To introduce the TUI interface, lets begin by a simple but complete example of ADAO calculation case. All the data are explicitly defined inside the script in order to make the reading easier. The whole set of commands is the following -one:: +one: - from numpy import array - from adao import adaoBuilder - case = adaoBuilder.New() - case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) - case.set( 'Background', Vector=[0, 1, 2] ) - case.set( 'BackgroundError', ScalarSparseMatrix=1.0 ) - case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) - case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) - case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' ) - case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" ) - case.execute() +.. literalinclude:: scripts/tui_example_01.py + :language: python The result of running these commands in SALOME (either as a SALOME "*shell*" -command, in the Python command window of the interface, or by the script -execution entry of the menu) is the following:: +command, in the SALOME Python command window of the interface, or by the script +execution entry of the menu) is the following: - Analysis [ 0.25000264 0.79999797 0.94999939] +.. literalinclude:: scripts/tui_example_01.res Detailed setup of an ADAO TUI calculation case +++++++++++++++++++++++++++++++++++++++++++++++ @@ -149,7 +140,7 @@ case:: import numpy __x = numpy.ravel(x) __H = numpy.diag([1.,2.,3.]) - return __H @ __x + return numpy.dot(__H, __x) # case.set( 'ObservationOperator', OneFunction = simulation, @@ -645,26 +636,14 @@ with these Python external case operations. In addition, simple information about the case study as defined by the user can be obtained by using the Python "*print*" command directly on the case, at any -stage during its design. For example:: +stage during its design. For example: - from numpy import array - from adao import adaoBuilder - case = adaoBuilder.New() - case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) - case.set( 'Background', Vector=[0, 1, 2] ) - print(case) - -which result is here:: +.. literalinclude:: scripts/tui_example_07.py + :language: python - ================================================================================ - ADAO Study report - ================================================================================ +which result is here: - - AlgorithmParameters command has been set with values: - Algorithm='3DVAR' - - - Background command has been set with values: - Vector=[0, 1, 2] +.. literalinclude:: scripts/tui_example_07.res .. _subsection_tui_advanced: @@ -689,104 +668,19 @@ The hypothesis of the user case are the following ones. It is assumed: #. that the user have a Python function of physical simulation named ``simulation``, previously (well) tested, which transforms the 3 parameters in results similar to the observations, #. that the independent holding, that the user want to elaborate, is represented here by the simple printing of the initial state, of the optimal state, of the simulation in that point, of the intermediate state and of the number of optimization iteration. -In order to try in a simple way this example of TUI calculation case, we choose -for example the following entries, perfectly arbitrary, by building the -observations by simulation in order to set a twin experiments case (for -information, see the approach :ref:`section_methodology_twin`):: - - # - # Artificial building of an example of user data - # ---------------------------------------------- - alpha = 5. - beta = 7 - gamma = 9.0 - # - alphamin, alphamax = 0., 10. - betamin, betamax = 3, 13 - gammamin, gammamax = 1.5, 15.5 - # - def simulation(x): - "Simulation function H to perform Y=H(X)" - import numpy - __x = numpy.ravel(x) - __H = numpy.diag([1.,2.,3.]) - return __H @ __x - # - # Observations obtained by simulation - # ----------------------------------- - observations = simulation((2, 3, 4)) +In order to try in a simple way this example of TUI calculation case, we set +ourselves in a twin experiments case (for information, see the approach +:ref:`section_methodology_twin`). For that, we choose for example the following +entries, perfectly arbitrary, by building the observations by simulation. Then +we solve the adjustment problem through the command set execution that follows. +Finally, the whole problem is set and solved by the following script: -The set of commands that can be used is the following:: +.. literalinclude:: scripts/tui_example_11.py + :language: python - import numpy - from adao import adaoBuilder - # - # Formatting entries - # ------------------ - Xb = (alpha, beta, gamma) - Bounds = ( - (alphamin, alphamax), - (betamin, betamax ), - (gammamin, gammamax)) - # - # TUI ADAO - # -------- - case = adaoBuilder.New() - case.set( - 'AlgorithmParameters', - Algorithm = '3DVAR', - Parameters = { - "Bounds":Bounds, - "MaximumNumberOfSteps":100, - "StoreSupplementaryCalculations":[ - "CostFunctionJ", - "CurrentState", - "SimulatedObservationAtOptimum", - ], - } - ) - case.set( 'Background', Vector = numpy.array(Xb), Stored = True ) - case.set( 'Observation', Vector = numpy.array(observations) ) - case.set( 'BackgroundError', ScalarSparseMatrix = 1.0e10 ) - case.set( 'ObservationError', ScalarSparseMatrix = 1.0 ) - case.set( - 'ObservationOperator', - OneFunction = simulation, - Parameters = {"DifferentialIncrement":0.0001}, - ) - case.set( 'Observer', Variable="CurrentState", Template="ValuePrinter" ) - case.execute() - # - # Independent holding - # ------------------- - Xbackground = case.get("Background") - Xoptimum = case.get("Analysis")[-1] - FX_at_optimum = case.get("SimulatedObservationAtOptimum")[-1] - J_values = case.get("CostFunctionJ")[:] - print("") - print("Number of internal iterations...: %i"%len(J_values)) - print("Initial state...................: %s"%(numpy.ravel(Xbackground),)) - print("Optimal state...................: %s"%(numpy.ravel(Xoptimum),)) - print("Simulation at optimal state.....: %s"%(numpy.ravel(FX_at_optimum),)) - print("") +The command set execution gives the following results: -The command set execution gives the following result:: - - CurrentState [ 5. 7. 9.] - CurrentState [ 0. 3. 1.5] - CurrentState [ 1.40006418 3.86705307 3.7061137 ] - CurrentState [ 1.42580231 3.68474804 3.81008738] - CurrentState [ 1.60220353 3.0677108 4.06146069] - CurrentState [ 1.72517855 3.03296953 4.04915706] - CurrentState [ 2.00010755 3. 4.00055409] - CurrentState [ 1.99995528 3. 3.99996367] - CurrentState [ 2.00000007 3. 4.00000011] - CurrentState [ 2. 3. 4.] - - Number of internal iterations...: 10 - Initial state...................: [ 5. 7. 9.] - Optimal state...................: [ 2. 3. 4.] - Simulation at optimal state.....: [ 2. 6. 12. 20.] +.. literalinclude:: scripts/tui_example_11.res As it should be in twin experiments, when we trust mainly in observations, it is found that we get correctly the parameters that were used to artificially diff --git a/doc/fr/scripts/tui_example_01.py b/doc/fr/scripts/tui_example_01.py new file mode 100644 index 0000000..ecec69c --- /dev/null +++ b/doc/fr/scripts/tui_example_01.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# +from numpy import array +from adao import adaoBuilder +case = adaoBuilder.New() +case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) +case.set( 'Background', Vector=[0, 1, 2] ) +case.set( 'BackgroundError', ScalarSparseMatrix=1.0 ) +case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) +case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) +case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' ) +case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" ) +case.execute() diff --git a/doc/fr/scripts/tui_example_01.res b/doc/fr/scripts/tui_example_01.res new file mode 100644 index 0000000..bf97f75 --- /dev/null +++ b/doc/fr/scripts/tui_example_01.res @@ -0,0 +1 @@ +Analysis [0.25000264 0.79999797 0.94999939] diff --git a/doc/fr/scripts/tui_example_07.py b/doc/fr/scripts/tui_example_07.py new file mode 100644 index 0000000..77554d7 --- /dev/null +++ b/doc/fr/scripts/tui_example_07.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# +from numpy import array +from adao import adaoBuilder +case = adaoBuilder.New() +case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) +case.set( 'Background', Vector=[0, 1, 2] ) +# +print(case) diff --git a/doc/fr/scripts/tui_example_07.res b/doc/fr/scripts/tui_example_07.res new file mode 100644 index 0000000..a39599b --- /dev/null +++ b/doc/fr/scripts/tui_example_07.res @@ -0,0 +1,11 @@ +================================================================================ +ADAO Study report +================================================================================ + + - AlgorithmParameters command has been set with values: + Algorithm = '3DVAR' + + - Background command has been set with values: + Vector = [0, 1, 2] + + diff --git a/doc/fr/scripts/tui_example_11.py b/doc/fr/scripts/tui_example_11.py new file mode 100644 index 0000000..e0f8839 --- /dev/null +++ b/doc/fr/scripts/tui_example_11.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +# +import numpy +from adao import adaoBuilder +# +# ============================================================= +# POSITION DU PROBLÈME +# +# Construction artificielle d'un exemple de données utilisateur +# ------------------------------------------------------------- +alpha = 5. +beta = 7 +gamma = 9.0 +# +alphamin, alphamax = 0., 10. +betamin, betamax = 3, 13 +gammamin, gammamax = 1.5, 15.5 +# +def simulation(x): + "Fonction de simulation H pour effectuer Y=H(X)" + __x = numpy.ravel(x) + __H = numpy.array([[1,0,0],[0,2,0],[0,0,3],[1,2,3]]) + return numpy.dot(__H, __x) +# +# Observations obtenues par simulation +# ------------------------------------ +Xtrue = (2, 3, 4) +observations = simulation(Xtrue) +# +# ============================================================= +# RÉSOLUTION DU PROBLÈME +# +# Mise en forme des entrées +# ------------------------- +Xb = (alpha, beta, gamma) +Bounds = ( + (alphamin, alphamax), + (betamin, betamax ), + (gammamin, gammamax)) +# +# ADAO TUI +# -------- +case = adaoBuilder.New() +case.set( + 'AlgorithmParameters', + Algorithm = '3DVAR', + Parameters = { + "Bounds":Bounds, + "MaximumNumberOfSteps":100, + "StoreSupplementaryCalculations":[ + "CostFunctionJ", + "CurrentState", + "SimulatedObservationAtOptimum", + ], + } + ) +case.set( 'Background', Vector = numpy.array(Xb), Stored = True ) +case.set( 'Observation', Vector = numpy.array(observations) ) +case.set( 'BackgroundError', ScalarSparseMatrix = 1.0e10 ) +case.set( 'ObservationError', ScalarSparseMatrix = 1.0 ) +case.set( + 'ObservationOperator', + OneFunction = simulation, + Parameters = {"DifferentialIncrement":0.0001}, + ) +case.set( 'Observer', Variable="CurrentState", Template="ValuePrinter" ) +case.execute() +# +# Récupération des variables d'intérêt +# ------------------------------------ +Xbackground = case.get("Background") +Xoptimum = case.get("Analysis")[-1] +FX_at_optimum = case.get("SimulatedObservationAtOptimum")[-1] +J_values = case.get("CostFunctionJ")[:] +# +# ============================================================= +# EXPLOITATION DES RÉSULTATS INDÉPENDANTE +# +print("") +print("Nombre d'itérations internes...: %i"%len(J_values)) +print("État initial...................: %s"%(numpy.ravel(Xbackground),)) +print("État idéalisé..................: %s"%(numpy.ravel(Xtrue)*1.,)) +print("État optimal...................: %s"%(numpy.ravel(Xoptimum),)) +print("Simulation à l'état optimal....: %s"%(numpy.ravel(FX_at_optimum),)) +print("") diff --git a/doc/fr/scripts/tui_example_11.res b/doc/fr/scripts/tui_example_11.res new file mode 100644 index 0000000..ef3cc32 --- /dev/null +++ b/doc/fr/scripts/tui_example_11.res @@ -0,0 +1,17 @@ +CurrentState [5. 7. 9.] +CurrentState [0. 3. 1.5] +CurrentState [1.40006418 3.86705307 3.7061137 ] +CurrentState [1.42580231 3.68474804 3.81008738] +CurrentState [1.60220353 3.0677108 4.06146069] +CurrentState [1.72517855 3.03296953 4.04915706] +CurrentState [2.00010755 3. 4.00055409] +CurrentState [1.99995528 3. 3.99996367] +CurrentState [2.00000007 3. 4.00000011] +CurrentState [2. 3. 4.] + +Nombre d'itérations internes...: 10 +État initial...................: [5. 7. 9.] +État idéalisé..................: [2. 3. 4.] +État optimal...................: [2. 3. 4.] +Simulation à l'état optimal....: [ 2. 6. 12. 20.] + diff --git a/doc/fr/tui.rst b/doc/fr/tui.rst index 1a83e62..a4b2d53 100644 --- a/doc/fr/tui.rst +++ b/doc/fr/tui.rst @@ -62,25 +62,16 @@ Un exemple simple de création d'un cas de calcul TUI ADAO Pour introduire l'interface TUI, on commence par un exemple simple mais complet de cas de calcul ADAO. Toutes les données sont explicitement définies dans le corps du script pour faciliter la lecture. L'ensemble des commandes est le -suivant:: +suivant : - from numpy import array - from adao import adaoBuilder - case = adaoBuilder.New() - case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) - case.set( 'Background', Vector=[0, 1, 2] ) - case.set( 'BackgroundError', ScalarSparseMatrix=1.0 ) - case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) - case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) - case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' ) - case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" ) - case.execute() +.. literalinclude:: scripts/tui_example_01.py + :language: python Le résultat de l'exécution de ces commandes dans SALOME (que ce soit par la -commande "*shell*" de SALOME, dans la console Python de l'interface, ou par le -menu d'exécution d'un script) est le suivant:: +commande "*shell*" de SALOME, dans une console Python SALOME de l'interface, ou +par le menu d'exécution d'un script) est le suivant : - Analysis [ 0.25000264 0.79999797 0.94999939] +.. literalinclude:: scripts/tui_example_01.res Création détaillée d'un cas de calcul TUI ADAO ++++++++++++++++++++++++++++++++++++++++++++++ @@ -152,7 +143,7 @@ ci-dessus) et l'enregistre dans le cas ADAO:: import numpy __x = numpy.ravel(x) __H = numpy.diag([1.,2.,3.]) - return __H @ __x + return numpy.dot(__H, __x) # case.set( 'ObservationOperator', OneFunction = simulation, @@ -673,26 +664,14 @@ externes au cas. De plus, on peut obtenir une information simple sur le cas d'étude tel que défini par l'utilisateur en utilisant directement la commande "*print*" de Python -sur le cas, à toute étape lors de sa construction. Par exemple:: +sur le cas, à toute étape lors de sa construction. Par exemple : - from numpy import array - from adao import adaoBuilder - case = adaoBuilder.New() - case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) - case.set( 'Background', Vector=[0, 1, 2] ) - print(case) - -dont le résultat est ici:: +.. literalinclude:: scripts/tui_example_07.py + :language: python - ================================================================================ - ADAO Study report - ================================================================================ +dont le résultat est ici : - - AlgorithmParameters command has been set with values: - Algorithm='3DVAR' - - - Background command has been set with values: - Vector=[0, 1, 2] +.. literalinclude:: scripts/tui_example_07.res .. _subsection_tui_advanced: @@ -718,104 +697,20 @@ Les hypothèses du cas utilisateur sont les suivantes. On suppose : #. que l'utilisateur dispose en Python d'une fonction de simulation physique appelée ``simulation``, préalablement (bien) testée, qui transforme les 3 paramètres en résultats similaires aux observations, #. que l'exploitation indépendante, que l'utilisateur veut faire, est représentée ici par l'affichage simple de l'état initial, de l'état optimal, de la simulation en ce point, des états intermédiaires et du nombre d'itérations d'optimisation. -Pour effectuer de manière simple cet essai de cas de calcul TUI, on se donne -par exemple les entrées suivantes, parfaitement arbitraires, en construisant -les observations par simulation pour se placer dans un cas d'expériences -jumelles (pour mémoire, voir la démarche :ref:`section_methodology_twin`):: - - # - # Construction artificielle d'un exemple de données utilisateur - # ------------------------------------------------------------- - alpha = 5. - beta = 7 - gamma = 9.0 - # - alphamin, alphamax = 0., 10. - betamin, betamax = 3, 13 - gammamin, gammamax = 1.5, 15.5 - # - def simulation(x): - "Fonction de simulation H pour effectuer Y=H(X)" - import numpy - __x = numpy.ravel(x) - __H = numpy.diag([1.,2.,3.]) - return __H @ __x - # - # Observations obtenues par simulation - # ------------------------------------ - observations = simulation((2, 3, 4)) +Pour effectuer de manière simple cet essai de cas de calcul TUI, on se place +dans un cas d'expériences jumelles (pour mémoire, voir la démarche +:ref:`section_methodology_twin`). Pour cela, on se donne par exemple les +entrées suivantes, parfaitement arbitraires, en construisant les observations +par simulation. Puis on résout le problème de recalage par le jeu de commandes +qui vient ensuite. Au final, l'ensemble du problème est posé et résolu par le +script suivant : -Le jeu de commandes que l'on peut utiliser est le suivant:: +.. literalinclude:: scripts/tui_example_11.py + :language: python - import numpy - from adao import adaoBuilder - # - # Mise en forme des entrées - # ------------------------- - Xb = (alpha, beta, gamma) - Bounds = ( - (alphamin, alphamax), - (betamin, betamax ), - (gammamin, gammamax)) - # - # TUI ADAO - # -------- - case = adaoBuilder.New() - case.set( - 'AlgorithmParameters', - Algorithm = '3DVAR', - Parameters = { - "Bounds":Bounds, - "MaximumNumberOfSteps":100, - "StoreSupplementaryCalculations":[ - "CostFunctionJ", - "CurrentState", - "SimulatedObservationAtOptimum", - ], - } - ) - case.set( 'Background', Vector = numpy.array(Xb), Stored = True ) - case.set( 'Observation', Vector = numpy.array(observations) ) - case.set( 'BackgroundError', ScalarSparseMatrix = 1.0e10 ) - case.set( 'ObservationError', ScalarSparseMatrix = 1.0 ) - case.set( - 'ObservationOperator', - OneFunction = simulation, - Parameters = {"DifferentialIncrement":0.0001}, - ) - case.set( 'Observer', Variable="CurrentState", Template="ValuePrinter" ) - case.execute() - # - # Exploitation indépendante - # ------------------------- - Xbackground = case.get("Background") - Xoptimum = case.get("Analysis")[-1] - FX_at_optimum = case.get("SimulatedObservationAtOptimum")[-1] - J_values = case.get("CostFunctionJ")[:] - print("") - print("Nombre d'itérations internes...: %i"%len(J_values)) - print("Etat initial...................: %s"%(numpy.ravel(Xbackground),)) - print("Etat optimal...................: %s"%(numpy.ravel(Xoptimum),)) - print("Simulation à l'état optimal....: %s"%(numpy.ravel(FX_at_optimum),)) - print("") +L'exécution de jeu de commandes donne les résultats suivants : -L'exécution de jeu de commandes donne le résultat suivant:: - - CurrentState [ 5. 7. 9.] - CurrentState [ 0. 3. 1.5] - CurrentState [ 1.40006418 3.86705307 3.7061137 ] - CurrentState [ 1.42580231 3.68474804 3.81008738] - CurrentState [ 1.60220353 3.0677108 4.06146069] - CurrentState [ 1.72517855 3.03296953 4.04915706] - CurrentState [ 2.00010755 3. 4.00055409] - CurrentState [ 1.99995528 3. 3.99996367] - CurrentState [ 2.00000007 3. 4.00000011] - CurrentState [ 2. 3. 4.] - - Nombre d'itérations internes...: 10 - Etat initial...................: [ 5. 7. 9.] - Etat optimal...................: [ 2. 3. 4.] - Simulation à l'état optimal....: [ 2. 6. 12. 20.] +.. literalinclude:: scripts/tui_example_11.res Comme il se doit en expériences jumelles, avec une confiance majoritairement placée dans les observations, on constate que l'on retrouve bien les paramètres diff --git a/test/test6703/Doc_TUI_Exemple_03.py b/test/test6703/Doc_TUI_Exemple_03.py index 976145a..8097064 100644 --- a/test/test6703/Doc_TUI_Exemple_03.py +++ b/test/test6703/Doc_TUI_Exemple_03.py @@ -40,7 +40,7 @@ def simulation(x): "Fonction de simulation H pour effectuer Y=H(X)" import numpy __x = numpy.ravel(x) - __H = numpy.diag([1.,2.,3.]) + __H = numpy.array([[1,0,0],[0,2,0],[0,0,3],[1,2,3]]) return __H @ __x # # Observations obtenues par simulation diff --git a/test/test6704/Doc_TUI_Exemple_03_en_multifonction.py b/test/test6704/Doc_TUI_Exemple_03_en_multifonction.py index 184a7b7..ec47a55 100644 --- a/test/test6704/Doc_TUI_Exemple_03_en_multifonction.py +++ b/test/test6704/Doc_TUI_Exemple_03_en_multifonction.py @@ -40,7 +40,7 @@ def simulation(x): "Fonction de simulation H pour effectuer Y=H(X)" import numpy __x = numpy.ravel(x) - __H = numpy.diag([1.,2.,3.]) + __H = numpy.array([[1,0,0],[0,2,0],[0,0,3],[1,2,3]]) return __H @ __x # def multisimulation( xserie ):