*Tips for this algorithm:*
As the *"BackgroundError"* command is required for ALL the calculation
- algorithms in the interface, you have to provide a value, even if this
- command is not required for this algorithm, and will not be used. The
- simplest way is to give "1" as a STRING.
+ algorithms in the graphical interface ADAO EFICAS, you have to provide a
+ value, even if this command is not required for this algorithm, and will
+ not be used. The simplest way is to give "1" as a STRING.
.. ------------------------------------ ..
.. include:: snippets/Header2Algo04.rst
.. include:: snippets/SimulatedObservationAtOptimum.rst
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo09.rst
+
+.. literalinclude:: scripts/simple_NonLinearLeastSquares.py
+
+.. include:: snippets/Header2Algo10.rst
+
+.. literalinclude:: scripts/simple_NonLinearLeastSquares.res
+
.. ------------------------------------ ..
.. include:: snippets/Header2Algo06.rst
from numpy import array, ravel
def QuadFunction( coefficients ):
"""
- Function : y = a x^2 + b x + c
+ Simulation : y = a x^2 + b x + c
"""
a, b, c = list(ravel(coefficients))
x_points = (-5, 0, 1, 3, 10)
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+from numpy import array, ravel
+def QuadFunction( coefficients ):
+ """
+ Simulation : 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)
+#
+Xb = array([1., 1., 1.])
+Yobs = array([57, 2, 3, 17, 192])
+#
+print("Iterative resolution of the calibration problem")
+print("-----------------------.-----------------------")
+print("")
+from adao import adaoBuilder
+case = adaoBuilder.New('')
+case.setBackground( Vector = Xb, Stored=True )
+case.setObservation( Vector = Yobs, Stored=True )
+case.setObservationError( ScalarSparseMatrix = 1. )
+case.setObservationOperator( OneFunction = QuadFunction )
+case.setAlgorithmParameters(
+ Algorithm='NonLinearLeastSquares',
+ 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]))
--- /dev/null
+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.56383147 1.12097995]
+ Intermediate state at the current iteration: [ 1.99838848 -1.00480576 1.1563713 ]
+ Intermediate state at the current iteration: [ 2.0135905 -1.04815936 1.16155285]
+ Intermediate state at the current iteration: [ 2.01385679 -1.03874812 1.16129658]
+ Intermediate state at the current iteration: [ 2.01377856 -1.03700048 1.16157611]
+ Intermediate state at the current iteration: [ 2.01338903 -1.02943739 1.16528951]
+ Intermediate state at the current iteration: [ 2.01265633 -1.01708474 1.17793974]
+ Intermediate state at the current iteration: [ 2.01124871 -0.99745512 1.21485092]
+ Intermediate state at the current iteration: [ 2.00863696 -0.96943287 1.30917045]
+ Intermediate state at the current iteration: [ 2.00453385 -0.94011718 1.51021885]
+ Intermediate state at the current iteration: [ 2.00013539 -0.93313894 1.80539445]
+ Intermediate state at the current iteration: [ 1.95437219 -0.76890307 2.04566901]
+ Intermediate state at the current iteration: [ 1.99797363 -0.92538077 1.81674454]
+ Intermediate state at the current iteration: [ 1.99760514 -0.9592967 2.01402117]
+ Intermediate state at the current iteration: [ 1.99917565 -0.99152673 2.03171823]
+ Intermediate state at the current iteration: [ 1.99990376 -0.99963125 2.00671607]
+ Intermediate state at the current iteration: [ 1.99999841 -1.00005288 2.00039727]
+ Intermediate state at the current iteration: [ 2.00000014 -1.00000309 2.00000249]
+ Intermediate state at the current iteration: [ 2. -0.99999995 2.00000015]
+
+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.99999995 2.00000015]
*Astuce pour cet algorithme :*
Comme la commande *"BackgroundError"* est requise pour TOUS les algorithmes
- de calcul dans l'interface graphique, vous devez fournir une valeur, malgré
- le fait que cette commande ne soit pas nécessaire pour cet algorithme, et
- n'est donc pas utilisée. La manière la plus simple est de donner "1" comme
- un STRING.
+ de calcul dans l'interface graphique ADAO EFICAS, vous devez fournir une
+ valeur, malgré le fait que cette commande ne soit pas nécessaire pour cet
+ algorithme, et n'est donc pas utilisée. La manière la plus simple est de
+ donner "1" comme un STRING.
.. ------------------------------------ ..
.. include:: snippets/Header2Algo04.rst
.. include:: snippets/SimulatedObservationAtOptimum.rst
+.. ------------------------------------ ..
+.. include:: snippets/Header2Algo09.rst
+
+.. literalinclude:: scripts/simple_NonLinearLeastSquares.py
+
+.. include:: snippets/Header2Algo10.rst
+
+.. literalinclude:: scripts/simple_NonLinearLeastSquares.res
+
.. ------------------------------------ ..
.. include:: snippets/Header2Algo06.rst
from numpy import array, ravel
def QuadFunction( coefficients ):
"""
- Fonction : y = a x^2 + b x + c
+ Simulation : y = a x^2 + b x + c
"""
a, b, c = list(ravel(coefficients))
x_points = (-5, 0, 1, 3, 10)
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+from numpy import array, ravel
+def QuadFunction( coefficients ):
+ """
+ Simulation : 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)
+#
+Xb = array([1., 1., 1.])
+Yobs = array([57, 2, 3, 17, 192])
+#
+print("Résolution itérative du problème de calibration")
+print("-----------------------.-----------------------")
+print("")
+from adao import adaoBuilder
+case = adaoBuilder.New('')
+case.setBackground( Vector = Xb, Stored=True )
+case.setObservation( Vector = Yobs, Stored=True )
+case.setObservationError( ScalarSparseMatrix = 1. )
+case.setObservationOperator( OneFunction = QuadFunction )
+case.setAlgorithmParameters(
+ Algorithm='NonLinearLeastSquares',
+ 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]))
--- /dev/null
+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.56383147 1.12097995]
+ État intermédiaire en itération courante : [ 1.99838848 -1.00480576 1.1563713 ]
+ État intermédiaire en itération courante : [ 2.0135905 -1.04815936 1.16155285]
+ État intermédiaire en itération courante : [ 2.01385679 -1.03874812 1.16129658]
+ État intermédiaire en itération courante : [ 2.01377856 -1.03700048 1.16157611]
+ État intermédiaire en itération courante : [ 2.01338903 -1.02943739 1.16528951]
+ État intermédiaire en itération courante : [ 2.01265633 -1.01708474 1.17793974]
+ État intermédiaire en itération courante : [ 2.01124871 -0.99745512 1.21485092]
+ État intermédiaire en itération courante : [ 2.00863696 -0.96943287 1.30917045]
+ État intermédiaire en itération courante : [ 2.00453385 -0.94011718 1.51021885]
+ État intermédiaire en itération courante : [ 2.00013539 -0.93313894 1.80539445]
+ État intermédiaire en itération courante : [ 1.95437219 -0.76890307 2.04566901]
+ État intermédiaire en itération courante : [ 1.99797363 -0.92538077 1.81674454]
+ État intermédiaire en itération courante : [ 1.99760514 -0.9592967 2.01402117]
+ État intermédiaire en itération courante : [ 1.99917565 -0.99152673 2.03171823]
+ État intermédiaire en itération courante : [ 1.99990376 -0.99963125 2.00671607]
+ État intermédiaire en itération courante : [ 1.99999841 -1.00005288 2.00039727]
+ État intermédiaire en itération courante : [ 2.00000014 -1.00000309 2.00000249]
+ État intermédiaire en itération courante : [ 2. -0.99999995 2.00000015]
+
+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.99999995 2.00000015]