From: Jean-Philippe ARGAUD Date: Fri, 17 Apr 2020 19:50:23 +0000 (+0200) Subject: Adding elementary TUI examples to algorithms doc X-Git-Tag: V9_5_0b~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8e4b325b84723f9089b825a36423995f781104a0;p=modules%2Fadao.git Adding elementary TUI examples to algorithms doc --- diff --git a/doc/en/ref_algorithm_3DVAR.rst b/doc/en/ref_algorithm_3DVAR.rst index 8259aae..186766f 100644 --- a/doc/en/ref_algorithm_3DVAR.rst +++ b/doc/en/ref_algorithm_3DVAR.rst @@ -200,6 +200,15 @@ StoreSupplementaryCalculations .. include:: snippets/SimulationQuantiles.rst +.. ------------------------------------ .. +.. include:: snippets/Header2Algo09.rst + +.. literalinclude:: scripts/simple_3DVAR.py + +.. include:: snippets/Header2Algo10.rst + +.. literalinclude:: scripts/simple_3DVAR.res + .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/en/ref_algorithm_Blue.rst b/doc/en/ref_algorithm_Blue.rst index b24932f..e31de7b 100644 --- a/doc/en/ref_algorithm_Blue.rst +++ b/doc/en/ref_algorithm_Blue.rst @@ -164,6 +164,15 @@ StoreSupplementaryCalculations .. include:: snippets/SimulationQuantiles.rst +.. ------------------------------------ .. +.. include:: snippets/Header2Algo09.rst + +.. literalinclude:: scripts/simple_Blue.py + +.. include:: snippets/Header2Algo10.rst + +.. literalinclude:: scripts/simple_Blue.res + .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/en/scripts/simple_3DVAR.py b/doc/en/scripts/simple_3DVAR.py new file mode 100644 index 0000000..9383adb --- /dev/null +++ b/doc/en/scripts/simple_3DVAR.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# +from numpy import array, ravel +def QuadFunction( coefficients ): + """ + Function : y = a x^2 + b x + c + """ + 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 ) + return array(y_points) +# +print("Iterative resolution of the calibration problem") +print("-----------------------.-----------------------") +print("") +from adao import adaoBuilder +case = adaoBuilder.New('') +case.setBackground( Vector = array([1., 1., 1.]), Stored=True ) +case.setBackgroundError( ScalarSparseMatrix = 1.e6 ) +case.setObservation( Vector=array([57, 2, 3, 17, 192]), Stored=True ) +case.setObservationError( ScalarSparseMatrix = 1. ) +case.setObservationOperator( OneFunction = QuadFunction ) +case.setAlgorithmParameters( + Algorithm='3DVAR', + Parameters={ + 'StoreSupplementaryCalculations': [ + 'CurrentState', + ], + }, + ) +case.setObserver( + Info=" Intermediate state at the current iteration:", + Template='ValuePrinter', + Variable='CurrentState', + ) +case.execute() +print("") +# +#------------------------------------------------------------------------------- +# +print("Calibration of %i coefficients in a 1D quadratic function on %i measures"%( + len(case.get('Background')), + len(case.get('Observation')), + )) +print("---------------------------------------------------------------------") +print("") +print("Observation vector.................:", ravel(case.get('Observation'))) +print("A priori background state..........:", ravel(case.get('Background'))) +print("") +print("Expected theoretical coefficients..:", ravel((2,-1,2))) +print("") +print("Calibration resulting coefficients.:", ravel(case.get('Analysis')[-1])) diff --git a/doc/en/scripts/simple_3DVAR.res b/doc/en/scripts/simple_3DVAR.res new file mode 100644 index 0000000..15d1d37 --- /dev/null +++ b/doc/en/scripts/simple_3DVAR.res @@ -0,0 +1,38 @@ +Iterative resolution of the calibration problem +-----------------------.----------------------- + + Intermediate state at the current iteration: [1. 1. 1.] + Intermediate state at the current iteration: [1.99739508 1.07086406 1.01346638] + Intermediate state at the current iteration: [1.83891966 1.04815981 1.01208385] + Intermediate state at the current iteration: [1.8390702 1.03667176 1.01284797] + Intermediate state at the current iteration: [1.83967236 0.99071957 1.01590445] + Intermediate state at the current iteration: [1.84208099 0.8069108 1.02813037] + Intermediate state at the current iteration: [ 1.93711599 -0.56383145 1.12097995] + Intermediate state at the current iteration: [ 1.99838848 -1.00480573 1.1563713 ] + Intermediate state at the current iteration: [ 2.0135905 -1.04815933 1.16155285] + Intermediate state at the current iteration: [ 2.01385679 -1.03874809 1.16129657] + Intermediate state at the current iteration: [ 2.01377856 -1.03700044 1.16157611] + Intermediate state at the current iteration: [ 2.01338902 -1.02943736 1.16528951] + Intermediate state at the current iteration: [ 2.01265633 -1.0170847 1.17793974] + Intermediate state at the current iteration: [ 2.0112487 -0.99745509 1.21485091] + Intermediate state at the current iteration: [ 2.00863696 -0.96943284 1.30917045] + Intermediate state at the current iteration: [ 2.00453385 -0.94011716 1.51021882] + Intermediate state at the current iteration: [ 2.00013539 -0.93313893 1.80539433] + Intermediate state at the current iteration: [ 1.95437244 -0.76890418 2.04566856] + Intermediate state at the current iteration: [ 1.99797362 -0.92538074 1.81674451] + Intermediate state at the current iteration: [ 1.99760514 -0.95929669 2.01402091] + Intermediate state at the current iteration: [ 1.99917565 -0.99152672 2.03171791] + Intermediate state at the current iteration: [ 1.99990376 -0.99963123 2.00671578] + Intermediate state at the current iteration: [ 1.99999841 -1.00005285 2.00039699] + Intermediate state at the current iteration: [ 2.00000014 -1.00000307 2.00000221] + Intermediate state at the current iteration: [ 2. -0.99999992 1.99999987] + +Calibration of 3 coefficients in a 1D quadratic function on 5 measures +--------------------------------------------------------------------- + +Observation vector.................: [ 57. 2. 3. 17. 192.] +A priori background state..........: [1. 1. 1.] + +Expected theoretical coefficients..: [ 2 -1 2] + +Calibration resulting coefficients.: [ 2. -0.99999992 1.99999987] diff --git a/doc/en/scripts/simple_Blue.py b/doc/en/scripts/simple_Blue.py new file mode 100644 index 0000000..58cf086 --- /dev/null +++ b/doc/en/scripts/simple_Blue.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# +from numpy import array, ravel +from adao import adaoBuilder +case = adaoBuilder.New('') +case.setBackground( Vector = array([0., 1., 2.]), Stored=True ) +case.setBackgroundError( ScalarSparseMatrix = 1. ) +case.setObservation( Vector=array([10., 11., 12.]), Stored=True ) +case.setObservationError( ScalarSparseMatrix = 1. ) +case.setObservationOperator( Matrix=array([[1., 0., 0.], + [0., 1., 0.], + [0., 0., 1.]]), ) +case.setAlgorithmParameters( + Algorithm='Blue', + Parameters={ + 'StoreSupplementaryCalculations': [ + 'APosterioriCovariance', + ], + }, + ) +case.execute() +# +#------------------------------------------------------------------------------- +# +print("Interpolation between two vectors, of observation and background") +print("----------------------------------------------------------------") +print("") +print("Observation vector............:", ravel(case.get('Observation'))) +print("A priori background vector....:", ravel(case.get('Background'))) +print("") +print("Expected theoretical state....:", ravel([5., 6., 7.])) +print("") +print("Interpolation result..........:", ravel(case.get('Analysis')[-1])) +print("A posteriori covariance.......:\n", case.get('APosterioriCovariance')[-1]) diff --git a/doc/en/scripts/simple_Blue.res b/doc/en/scripts/simple_Blue.res new file mode 100644 index 0000000..d319ffe --- /dev/null +++ b/doc/en/scripts/simple_Blue.res @@ -0,0 +1,13 @@ +Interpolation between two vectors, of observation and background +---------------------------------------------------------------- + +Observation vector............: [10. 11. 12.] +A priori background vector....: [0. 1. 2.] + +Expected theoretical state....: [5. 6. 7.] + +Interpolation result..........: [5. 6. 7.] +A posteriori covariance.......: + [[0.5 0. 0. ] + [0. 0.5 0. ] + [0. 0. 0.5]] diff --git a/doc/fr/ref_algorithm_3DVAR.rst b/doc/fr/ref_algorithm_3DVAR.rst index 4a85897..10023d3 100644 --- a/doc/fr/ref_algorithm_3DVAR.rst +++ b/doc/fr/ref_algorithm_3DVAR.rst @@ -202,6 +202,15 @@ StoreSupplementaryCalculations .. include:: snippets/SimulationQuantiles.rst +.. ------------------------------------ .. +.. include:: snippets/Header2Algo09.rst + +.. literalinclude:: scripts/simple_3DVAR.py + +.. include:: snippets/Header2Algo10.rst + +.. literalinclude:: scripts/simple_3DVAR.res + .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/fr/ref_algorithm_Blue.rst b/doc/fr/ref_algorithm_Blue.rst index e0d76e9..14af224 100644 --- a/doc/fr/ref_algorithm_Blue.rst +++ b/doc/fr/ref_algorithm_Blue.rst @@ -165,6 +165,15 @@ StoreSupplementaryCalculations .. include:: snippets/SimulationQuantiles.rst +.. ------------------------------------ .. +.. include:: snippets/Header2Algo09.rst + +.. literalinclude:: scripts/simple_Blue.py + +.. include:: snippets/Header2Algo10.rst + +.. literalinclude:: scripts/simple_Blue.res + .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/fr/scripts/simple_3DVAR.py b/doc/fr/scripts/simple_3DVAR.py new file mode 100644 index 0000000..553f9d3 --- /dev/null +++ b/doc/fr/scripts/simple_3DVAR.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# +from numpy import array, ravel +def QuadFunction( coefficients ): + """ + Fonction : y = a x^2 + b x + c + """ + 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 ) + return array(y_points) +# +print("Résolution itérative du problème de calibration") +print("-----------------------.-----------------------") +print("") +from adao import adaoBuilder +case = adaoBuilder.New('') +case.setBackground( Vector = array([1., 1., 1.]), Stored=True ) +case.setBackgroundError( ScalarSparseMatrix = 1.e6 ) +case.setObservation( Vector=array([57, 2, 3, 17, 192]), Stored=True ) +case.setObservationError( ScalarSparseMatrix = 1. ) +case.setObservationOperator( OneFunction = QuadFunction ) +case.setAlgorithmParameters( + Algorithm='3DVAR', + Parameters={ + 'StoreSupplementaryCalculations': [ + 'CurrentState', + ], + }, + ) +case.setObserver( + Info=" État intermédiaire en itération courante :", + Template='ValuePrinter', + Variable='CurrentState', + ) +case.execute() +print("") +# +#------------------------------------------------------------------------------- +# +print("Calibration de %i coefficients pour une forme quadratique 1D sur %i mesures"%( + len(case.get('Background')), + len(case.get('Observation')), + )) +print("------------------------------------------------------------------------") +print("") +print("Vecteur observation.......................:", ravel(case.get('Observation'))) +print("État ébauche a priori.....................:", ravel(case.get('Background'))) +print("") +print("Coefficients théoriques attendus..........:", ravel((2,-1,2))) +print("") +print("Coefficients résultants de la calibration.:", ravel(case.get('Analysis')[-1])) diff --git a/doc/fr/scripts/simple_3DVAR.res b/doc/fr/scripts/simple_3DVAR.res new file mode 100644 index 0000000..3780eb7 --- /dev/null +++ b/doc/fr/scripts/simple_3DVAR.res @@ -0,0 +1,38 @@ +Résolution itérative du problème de calibration +-----------------------.----------------------- + + État intermédiaire en itération courante : [1. 1. 1.] + État intermédiaire en itération courante : [1.99739508 1.07086406 1.01346638] + État intermédiaire en itération courante : [1.83891966 1.04815981 1.01208385] + État intermédiaire en itération courante : [1.8390702 1.03667176 1.01284797] + État intermédiaire en itération courante : [1.83967236 0.99071957 1.01590445] + État intermédiaire en itération courante : [1.84208099 0.8069108 1.02813037] + État intermédiaire en itération courante : [ 1.93711599 -0.56383145 1.12097995] + État intermédiaire en itération courante : [ 1.99838848 -1.00480573 1.1563713 ] + État intermédiaire en itération courante : [ 2.0135905 -1.04815933 1.16155285] + État intermédiaire en itération courante : [ 2.01385679 -1.03874809 1.16129657] + État intermédiaire en itération courante : [ 2.01377856 -1.03700044 1.16157611] + État intermédiaire en itération courante : [ 2.01338902 -1.02943736 1.16528951] + État intermédiaire en itération courante : [ 2.01265633 -1.0170847 1.17793974] + État intermédiaire en itération courante : [ 2.0112487 -0.99745509 1.21485091] + État intermédiaire en itération courante : [ 2.00863696 -0.96943284 1.30917045] + État intermédiaire en itération courante : [ 2.00453385 -0.94011716 1.51021882] + État intermédiaire en itération courante : [ 2.00013539 -0.93313893 1.80539433] + État intermédiaire en itération courante : [ 1.95437244 -0.76890418 2.04566856] + État intermédiaire en itération courante : [ 1.99797362 -0.92538074 1.81674451] + État intermédiaire en itération courante : [ 1.99760514 -0.95929669 2.01402091] + État intermédiaire en itération courante : [ 1.99917565 -0.99152672 2.03171791] + État intermédiaire en itération courante : [ 1.99990376 -0.99963123 2.00671578] + État intermédiaire en itération courante : [ 1.99999841 -1.00005285 2.00039699] + État intermédiaire en itération courante : [ 2.00000014 -1.00000307 2.00000221] + État intermédiaire en itération courante : [ 2. -0.99999992 1.99999987] + +Calibration de 3 coefficients pour une forme quadratique 1D sur 5 mesures +------------------------------------------------------------------------ + +Vecteur observation.......................: [ 57. 2. 3. 17. 192.] +État ébauche a priori.....................: [1. 1. 1.] + +Coefficients théoriques attendus..........: [ 2 -1 2] + +Coefficients résultants de la calibration.: [ 2. -0.99999992 1.99999987] diff --git a/doc/fr/scripts/simple_Blue.py b/doc/fr/scripts/simple_Blue.py new file mode 100644 index 0000000..117b737 --- /dev/null +++ b/doc/fr/scripts/simple_Blue.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# +from numpy import array, ravel +from adao import adaoBuilder +case = adaoBuilder.New('') +case.setBackground( Vector = array([0., 1., 2.]), Stored=True ) +case.setBackgroundError( ScalarSparseMatrix = 1. ) +case.setObservation( Vector=array([10., 11., 12.]), Stored=True ) +case.setObservationError( ScalarSparseMatrix = 1. ) +case.setObservationOperator( Matrix=array([[1., 0., 0.], + [0., 1., 0.], + [0., 0., 1.]]), ) +case.setAlgorithmParameters( + Algorithm='Blue', + Parameters={ + 'StoreSupplementaryCalculations': [ + 'APosterioriCovariance', + ], + }, + ) +case.execute() +# +#------------------------------------------------------------------------------- +# +print("Interpolation entre deux états vectoriels, observation et ébauche") +print("-----------------------------------------------------------------") +print("") +print("Vecteur observation...........:", ravel(case.get('Observation'))) +print("Vecteur ébauche a priori......:", ravel(case.get('Background'))) +print("") +print("État théorique attendu........:", ravel([5., 6., 7.])) +print("") +print("Résultat par interpolation....:", ravel(case.get('Analysis')[-1])) +print("Covariance a posteriori.......:\n", case.get('APosterioriCovariance')[-1]) diff --git a/doc/fr/scripts/simple_Blue.res b/doc/fr/scripts/simple_Blue.res new file mode 100644 index 0000000..e57a93b --- /dev/null +++ b/doc/fr/scripts/simple_Blue.res @@ -0,0 +1,13 @@ +Interpolation entre deux états vectoriels, observation et ébauche +----------------------------------------------------------------- + +Vecteur observation...........: [10. 11. 12.] +Vecteur ébauche a priori......: [0. 1. 2.] + +État théorique attendu........: [5. 6. 7.] + +Résultat par interpolation....: [5. 6. 7.] +Covariance a posteriori.......: + [[0.5 0. 0. ] + [0. 0.5 0. ] + [0. 0. 0.5]]