From: Jean-Philippe ARGAUD Date: Sun, 6 Dec 2020 07:20:43 +0000 (+0100) Subject: Documentation example improvement with dynamic X-Git-Tag: V9_7_0b1~64 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3d58dead21d2fd0d8ed79ba4f6af5f633984bab7;p=modules%2Fadao.git Documentation example improvement with dynamic --- diff --git a/doc/en/ref_algorithm_KalmanFilter.rst b/doc/en/ref_algorithm_KalmanFilter.rst index 24de1ca..eb958fb 100644 --- a/doc/en/ref_algorithm_KalmanFilter.rst +++ b/doc/en/ref_algorithm_KalmanFilter.rst @@ -196,6 +196,10 @@ StoreSupplementaryCalculations :align: center :width: 90% +.. include:: scripts/simple_KalmanFilter2.rst + +.. literalinclude:: scripts/simple_KalmanFilter2.py + .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/en/scripts/simple_KalmanFilter2.py b/doc/en/scripts/simple_KalmanFilter2.py new file mode 100644 index 0000000..d0acc80 --- /dev/null +++ b/doc/en/scripts/simple_KalmanFilter2.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# +from numpy import array, random +random.seed(1234567) +Xtrue = -0.37727 +Yobs = [] +for i in range(51): + Yobs.append([random.normal(Xtrue, 0.1, size=(1,)),]) +# +print("Estimation of a constant variable by filtering") +print("----------------------------------------------") +print(" Noisy measurements acquired on %i time steps"%(len(Yobs)-1,)) +print("") +from adao import adaoBuilder +case = adaoBuilder.New('') +# +case.setObservationOperator(Matrix = [1.]) +case.setObservationError (ScalarSparseMatrix = 0.1**2) +# +case.setEvolutionModel (Matrix = [1.]) +case.setEvolutionError (ScalarSparseMatrix = 1e-5) +# +case.setAlgorithmParameters( + Algorithm="KalmanFilter", + Parameters={ + "StoreSupplementaryCalculations":[ + "Analysis", + "APosterioriCovariance", + ], + }, + ) +# +XaStep, VaStep = 0., 1. +for i in range(1,len(Yobs)): + case.setBackground (Vector = "%s"%float(XaStep)) + case.setBackgroundError (ScalarSparseMatrix = "%s"%float(VaStep)) + case.setObservation (Vector = Yobs[i]) + case.execute( nextStep = True ) + XaStep = case.get("Analysis")[-1] + VaStep = case.get("APosterioriCovariance")[-1] +# +Xa = case.get("Analysis") +Pa = case.get("APosterioriCovariance") +# +print("") +print(" Final a posteriori variance:",Pa[-1]) +print("") diff --git a/doc/en/scripts/simple_KalmanFilter2.rst b/doc/en/scripts/simple_KalmanFilter2.rst new file mode 100644 index 0000000..bdd55ae --- /dev/null +++ b/doc/en/scripts/simple_KalmanFilter2.rst @@ -0,0 +1,10 @@ +The Kalman filter can also be used for a **running analysis of the observations +of a given dynamic model**. In this case, the analysis is conducted +iteratively, at the arrival of each observation. + +The following example deals with the same simple dynamic system from the +reference [Welch06]_. The essential difference consists in carrying out the +execution of a Kalman step at the arrival of each observation provided +iteratively. The keyword "*nextStep*", included in the execution order, allows +to not store the background in duplicate of the previous analysis. + diff --git a/doc/fr/ref_algorithm_KalmanFilter.rst b/doc/fr/ref_algorithm_KalmanFilter.rst index 6153115..c84f906 100644 --- a/doc/fr/ref_algorithm_KalmanFilter.rst +++ b/doc/fr/ref_algorithm_KalmanFilter.rst @@ -197,6 +197,10 @@ StoreSupplementaryCalculations :align: center :width: 90% +.. include:: scripts/simple_KalmanFilter2.rst + +.. literalinclude:: scripts/simple_KalmanFilter2.py + .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/fr/scripts/simple_KalmanFilter2.py b/doc/fr/scripts/simple_KalmanFilter2.py new file mode 100644 index 0000000..3b2135c --- /dev/null +++ b/doc/fr/scripts/simple_KalmanFilter2.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# +from numpy import array, random +random.seed(1234567) +Xtrue = -0.37727 +Yobs = [] +for i in range(51): + Yobs.append([random.normal(Xtrue, 0.1, size=(1,)),]) +# +print("Estimation par filtrage d'une variable constante") +print("------------------------------------------------") +print(" Observations bruitées acquises sur %i pas de temps"%(len(Yobs)-1,)) +print("") +from adao import adaoBuilder +case = adaoBuilder.New('') +# +case.setObservationOperator(Matrix = [1.]) +case.setObservationError (ScalarSparseMatrix = 0.1**2) +# +case.setEvolutionModel (Matrix = [1.]) +case.setEvolutionError (ScalarSparseMatrix = 1e-5) +# +case.setAlgorithmParameters( + Algorithm="KalmanFilter", + Parameters={ + "StoreSupplementaryCalculations":[ + "Analysis", + "APosterioriCovariance", + ], + }, + ) +# +XaStep, VaStep = 0., 1. +for i in range(1,len(Yobs)): + case.setBackground (Vector = "%s"%float(XaStep)) + case.setBackgroundError (ScalarSparseMatrix = "%s"%float(VaStep)) + case.setObservation (Vector = Yobs[i]) + case.execute( nextStep = True ) + XaStep = case.get("Analysis")[-1] + VaStep = case.get("APosterioriCovariance")[-1] +# +Xa = case.get("Analysis") +Pa = case.get("APosterioriCovariance") +# +print("") +print(" Variance a posteriori finale :",Pa[-1]) +print("") diff --git a/doc/fr/scripts/simple_KalmanFilter2.rst b/doc/fr/scripts/simple_KalmanFilter2.rst new file mode 100644 index 0000000..21cc5a6 --- /dev/null +++ b/doc/fr/scripts/simple_KalmanFilter2.rst @@ -0,0 +1,10 @@ +Le filtre de Kalman peut aussi être utilisé pour une **analyse courante des +observations d'un modèle dynamique donné**. Dans ce cas, l'analyse est conduite +de manière itérative, lors de l'arrivée de chaque observation. + +L'exemple suivant porte sur le même système dynamique simple issu de la +référence [Welch06]_. La différence essentielle consiste à effectuer +l'exécution d'une étape de Kalman à l'arrivée de chaque observation fournie +itérativement. Le mot-clé "*nextStep*", inclut dans l'ordre d'exécution, permet +de ne pas stocker l'ébauche en double de l'analyse précédente. +