From 7231679b2f7d1792c83643cb184a1e70d4dcc7e2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Sun, 29 Nov 2020 16:06:50 +0100 Subject: [PATCH] Documentation example improvement --- doc/en/ref_algorithm_KalmanFilter.rst | 6 +++ doc/en/scripts/simple_KalmanFilter1.py | 47 ++++++++++++++++++++ doc/en/scripts/simple_KalmanFilter1.res | 58 +++++++++++++++++++++++++ doc/fr/ref_algorithm_KalmanFilter.rst | 6 +++ doc/fr/scripts/simple_KalmanFilter1.py | 47 ++++++++++++++++++++ doc/fr/scripts/simple_KalmanFilter1.res | 58 +++++++++++++++++++++++++ 6 files changed, 222 insertions(+) create mode 100644 doc/en/scripts/simple_KalmanFilter1.py create mode 100644 doc/en/scripts/simple_KalmanFilter1.res create mode 100644 doc/fr/scripts/simple_KalmanFilter1.py create mode 100644 doc/fr/scripts/simple_KalmanFilter1.res diff --git a/doc/en/ref_algorithm_KalmanFilter.rst b/doc/en/ref_algorithm_KalmanFilter.rst index f852cfb..83050e1 100644 --- a/doc/en/ref_algorithm_KalmanFilter.rst +++ b/doc/en/ref_algorithm_KalmanFilter.rst @@ -178,6 +178,12 @@ StoreSupplementaryCalculations .. include:: scripts/simple_KalmanFilter1.rst +.. literalinclude:: scripts/simple_KalmanFilter1.py + +.. include:: snippets/Header2Algo10.rst + +.. literalinclude:: scripts/simple_KalmanFilter1.res + .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/en/scripts/simple_KalmanFilter1.py b/doc/en/scripts/simple_KalmanFilter1.py new file mode 100644 index 0000000..fa5322a --- /dev/null +++ b/doc/en/scripts/simple_KalmanFilter1.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.setBackground (Vector = [0.]) +case.setBackgroundError (ScalarSparseMatrix = 1.) +# +case.setObservationOperator(Matrix = [1.]) +case.setObservation (VectorSerie = Yobs) +case.setObservationError (ScalarSparseMatrix = 0.1**2) +# +case.setEvolutionModel (Matrix = [1.]) +case.setEvolutionError (ScalarSparseMatrix = 1e-5) +# +case.setAlgorithmParameters( + Algorithm="KalmanFilter", + Parameters={ + "StoreSupplementaryCalculations":[ + "Analysis", + "APosterioriCovariance", + ], + }, + ) +case.setObserver( + Info=" Analyzed state at current observation:", + Template='ValuePrinter', + Variable='Analysis', + ) +case.execute() +Xa = case.get("Analysis") +Pa = case.get("APosterioriCovariance") +# +print("") +print(" Final a posteriori variance:",Pa[-1]) +print("") diff --git a/doc/en/scripts/simple_KalmanFilter1.res b/doc/en/scripts/simple_KalmanFilter1.res new file mode 100644 index 0000000..b9aaf66 --- /dev/null +++ b/doc/en/scripts/simple_KalmanFilter1.res @@ -0,0 +1,58 @@ +Estimation of a constant variable by filtering +---------------------------------------------- + Noisy measurements acquired on 50 time steps + + Analyzed state at current observation: [0.] + Analyzed state at current observation: [-0.41804504] + Analyzed state at current observation: [-0.3114053] + Analyzed state at current observation: [-0.31191336] + Analyzed state at current observation: [-0.32761493] + Analyzed state at current observation: [-0.33597167] + Analyzed state at current observation: [-0.35629573] + Analyzed state at current observation: [-0.36840289] + Analyzed state at current observation: [-0.37392713] + Analyzed state at current observation: [-0.36331937] + Analyzed state at current observation: [-0.35750362] + Analyzed state at current observation: [-0.37963052] + Analyzed state at current observation: [-0.37117993] + Analyzed state at current observation: [-0.36732985] + Analyzed state at current observation: [-0.37148382] + Analyzed state at current observation: [-0.36798059] + Analyzed state at current observation: [-0.37371077] + Analyzed state at current observation: [-0.3661228] + Analyzed state at current observation: [-0.36777529] + Analyzed state at current observation: [-0.37681677] + Analyzed state at current observation: [-0.37007654] + Analyzed state at current observation: [-0.37974517] + Analyzed state at current observation: [-0.37964703] + Analyzed state at current observation: [-0.37514278] + Analyzed state at current observation: [-0.38143128] + Analyzed state at current observation: [-0.38790654] + Analyzed state at current observation: [-0.38880008] + Analyzed state at current observation: [-0.38393577] + Analyzed state at current observation: [-0.3831028] + Analyzed state at current observation: [-0.37680097] + Analyzed state at current observation: [-0.37891813] + Analyzed state at current observation: [-0.38147782] + Analyzed state at current observation: [-0.37981569] + Analyzed state at current observation: [-0.38274266] + Analyzed state at current observation: [-0.38418507] + Analyzed state at current observation: [-0.38923054] + Analyzed state at current observation: [-0.38400006] + Analyzed state at current observation: [-0.38562502] + Analyzed state at current observation: [-0.3840503] + Analyzed state at current observation: [-0.38775222] + Analyzed state at current observation: [-0.37700787] + Analyzed state at current observation: [-0.37328191] + Analyzed state at current observation: [-0.38024181] + Analyzed state at current observation: [-0.3815806] + Analyzed state at current observation: [-0.38392063] + Analyzed state at current observation: [-0.38539266] + Analyzed state at current observation: [-0.37856929] + Analyzed state at current observation: [-0.37744505] + Analyzed state at current observation: [-0.37154554] + Analyzed state at current observation: [-0.37405773] + Analyzed state at current observation: [-0.37725236] + + Final a posteriori variance: [[0.00033921]] + diff --git a/doc/fr/ref_algorithm_KalmanFilter.rst b/doc/fr/ref_algorithm_KalmanFilter.rst index a7d69b8..656c85a 100644 --- a/doc/fr/ref_algorithm_KalmanFilter.rst +++ b/doc/fr/ref_algorithm_KalmanFilter.rst @@ -179,6 +179,12 @@ StoreSupplementaryCalculations .. include:: scripts/simple_KalmanFilter1.rst +.. literalinclude:: scripts/simple_KalmanFilter1.py + +.. include:: snippets/Header2Algo10.rst + +.. literalinclude:: scripts/simple_KalmanFilter1.res + .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/fr/scripts/simple_KalmanFilter1.py b/doc/fr/scripts/simple_KalmanFilter1.py new file mode 100644 index 0000000..71f6c70 --- /dev/null +++ b/doc/fr/scripts/simple_KalmanFilter1.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.setBackground (Vector = [0.]) +case.setBackgroundError (ScalarSparseMatrix = 1.) +# +case.setObservationOperator(Matrix = [1.]) +case.setObservation (VectorSerie = Yobs) +case.setObservationError (ScalarSparseMatrix = 0.1**2) +# +case.setEvolutionModel (Matrix = [1.]) +case.setEvolutionError (ScalarSparseMatrix = 1e-5) +# +case.setAlgorithmParameters( + Algorithm="KalmanFilter", + Parameters={ + "StoreSupplementaryCalculations":[ + "Analysis", + "APosterioriCovariance", + ], + }, + ) +case.setObserver( + Info=" État analysé à l'observation courante :", + Template='ValuePrinter', + Variable='Analysis', + ) +case.execute() +Xa = case.get("Analysis") +Pa = case.get("APosterioriCovariance") +# +print("") +print(" Variance a posteriori finale :",Pa[-1]) +print("") diff --git a/doc/fr/scripts/simple_KalmanFilter1.res b/doc/fr/scripts/simple_KalmanFilter1.res new file mode 100644 index 0000000..ab3621b --- /dev/null +++ b/doc/fr/scripts/simple_KalmanFilter1.res @@ -0,0 +1,58 @@ +Estimation par filtrage d'une variable constante +------------------------------------------------ + Observations bruitées acquises sur 50 pas de temps + + État analysé à l'observation courante : [0.] + État analysé à l'observation courante : [-0.41804504] + État analysé à l'observation courante : [-0.3114053] + État analysé à l'observation courante : [-0.31191336] + État analysé à l'observation courante : [-0.32761493] + État analysé à l'observation courante : [-0.33597167] + État analysé à l'observation courante : [-0.35629573] + État analysé à l'observation courante : [-0.36840289] + État analysé à l'observation courante : [-0.37392713] + État analysé à l'observation courante : [-0.36331937] + État analysé à l'observation courante : [-0.35750362] + État analysé à l'observation courante : [-0.37963052] + État analysé à l'observation courante : [-0.37117993] + État analysé à l'observation courante : [-0.36732985] + État analysé à l'observation courante : [-0.37148382] + État analysé à l'observation courante : [-0.36798059] + État analysé à l'observation courante : [-0.37371077] + État analysé à l'observation courante : [-0.3661228] + État analysé à l'observation courante : [-0.36777529] + État analysé à l'observation courante : [-0.37681677] + État analysé à l'observation courante : [-0.37007654] + État analysé à l'observation courante : [-0.37974517] + État analysé à l'observation courante : [-0.37964703] + État analysé à l'observation courante : [-0.37514278] + État analysé à l'observation courante : [-0.38143128] + État analysé à l'observation courante : [-0.38790654] + État analysé à l'observation courante : [-0.38880008] + État analysé à l'observation courante : [-0.38393577] + État analysé à l'observation courante : [-0.3831028] + État analysé à l'observation courante : [-0.37680097] + État analysé à l'observation courante : [-0.37891813] + État analysé à l'observation courante : [-0.38147782] + État analysé à l'observation courante : [-0.37981569] + État analysé à l'observation courante : [-0.38274266] + État analysé à l'observation courante : [-0.38418507] + État analysé à l'observation courante : [-0.38923054] + État analysé à l'observation courante : [-0.38400006] + État analysé à l'observation courante : [-0.38562502] + État analysé à l'observation courante : [-0.3840503] + État analysé à l'observation courante : [-0.38775222] + État analysé à l'observation courante : [-0.37700787] + État analysé à l'observation courante : [-0.37328191] + État analysé à l'observation courante : [-0.38024181] + État analysé à l'observation courante : [-0.3815806] + État analysé à l'observation courante : [-0.38392063] + État analysé à l'observation courante : [-0.38539266] + État analysé à l'observation courante : [-0.37856929] + État analysé à l'observation courante : [-0.37744505] + État analysé à l'observation courante : [-0.37154554] + État analysé à l'observation courante : [-0.37405773] + État analysé à l'observation courante : [-0.37725236] + + Variance a posteriori finale : [[0.00033921]] + -- 2.39.2