Salome HOME
Documentation update with features and review corrections
[modules/adao.git] / src / daComposant / daAlgorithms / ExtendedKalmanFilter.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22
23 from daCore import BasicObjects
24 from daAlgorithms.Atoms import cekf, ceks, exks, exkf
25
26 # ==============================================================================
27 class ElementaryAlgorithm(BasicObjects.Algorithm):
28     def __init__(self):
29         BasicObjects.Algorithm.__init__(self, "EXTENDEDKALMANFILTER")
30         self.defineRequiredParameter(
31             name     = "Variant",
32             default  = "CEKF",
33             typecast = str,
34             message  = "Variant ou formulation de la méthode",
35             listval  = [
36                 "EKF",
37                 "CEKF",
38             ],
39             listadv  = [
40                 "EKS",
41                 "CEKS",
42             ],
43         )
44         self.defineRequiredParameter(
45             name     = "ConstrainedBy",
46             default  = "EstimateProjection",
47             typecast = str,
48             message  = "Prise en compte des contraintes",
49             listval  = ["EstimateProjection"],
50         )
51         self.defineRequiredParameter(
52             name     = "EstimationOf",
53             default  = "State",
54             typecast = str,
55             message  = "Estimation d'état ou de paramètres",
56             listval  = ["State", "Parameters"],
57         )
58         self.defineRequiredParameter(
59             name     = "StoreInternalVariables",
60             default  = False,
61             typecast = bool,
62             message  = "Stockage des variables internes ou intermédiaires du calcul",
63         )
64         self.defineRequiredParameter(
65             name     = "StoreSupplementaryCalculations",
66             default  = [],
67             typecast = tuple,
68             message  = "Liste de calculs supplémentaires à stocker et/ou effectuer",
69             listval  = [
70                 "Analysis",
71                 "APosterioriCorrelations",
72                 "APosterioriCovariance",
73                 "APosterioriStandardDeviations",
74                 "APosterioriVariances",
75                 "BMA",
76                 "CostFunctionJ",
77                 "CostFunctionJAtCurrentOptimum",
78                 "CostFunctionJb",
79                 "CostFunctionJbAtCurrentOptimum",
80                 "CostFunctionJo",
81                 "CostFunctionJoAtCurrentOptimum",
82                 "CurrentIterationNumber",
83                 "CurrentOptimum",
84                 "CurrentState",
85                 "ForecastCovariance",
86                 "ForecastState",
87                 "IndexOfOptimum",
88                 "InnovationAtCurrentAnalysis",
89                 "InnovationAtCurrentState",
90                 "SimulatedObservationAtCurrentAnalysis",
91                 "SimulatedObservationAtCurrentOptimum",
92                 "SimulatedObservationAtCurrentState",
93             ]
94         )
95         self.defineRequiredParameter(  # Pas de type
96             name     = "Bounds",
97             message  = "Liste des valeurs de bornes",
98         )
99         self.requireInputArguments(
100             mandatory= ("Xb", "Y", "HO", "R", "B"),
101             optional = ("U", "EM", "CM", "Q"),
102         )
103         self.setAttributes(
104             tags=(
105                 "DataAssimilation",
106                 "NonLinear",
107                 "Filter",
108                 "Dynamic",
109             ),
110             features=(
111                 "LocalOptimization",
112                 "DerivativeNeeded",
113                 "ParallelDerivativesOnly",
114             ),
115         )
116
117     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
118         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
119         #
120         # --------------------------
121         if self._parameters["Variant"] == "EKF":
122             exkf.exkf(self, Xb, Y, U, HO, EM, CM, R, B, Q)
123         #
124         # --------------------------
125         elif self._parameters["Variant"] == "CEKF":
126             cekf.cekf(self, Xb, Y, U, HO, EM, CM, R, B, Q)
127         #
128         # --------------------------
129         elif self._parameters["Variant"] == "EKS":
130             exks.exks(self, Xb, Y, U, HO, EM, CM, R, B, Q)
131         #
132         # --------------------------
133         elif self._parameters["Variant"] == "CEKS":
134             ceks.ceks(self, Xb, Y, U, HO, EM, CM, R, B, Q)
135         #
136         # --------------------------
137         else:
138             raise ValueError("Error in Variant name: %s"%self._parameters["Variant"])
139         #
140         self._post_run(HO, EM)
141         return 0
142
143 # ==============================================================================
144 if __name__ == "__main__":
145     print("\n AUTODIAGNOSTIC\n")