]> SALOME platform Git repositories - modules/adao.git/blob - src/daComposant/daAlgorithms/Blue.py
Salome HOME
af7f44f032eefd0104bee53fa7fa7217b7134993
[modules/adao.git] / src / daComposant / daAlgorithms / Blue.py
1 #-*-coding:iso-8859-1-*-
2 #
3 #  Copyright (C) 2008-2010  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 __doc__ = """
22     Algorithme de Kalman simple (BLUE)
23 """
24 __author__ = "Jean-Philippe ARGAUD - Mars 2008"
25
26 import logging
27 from daCore import BasicObjects, PlatformInfo
28 m = PlatformInfo.SystemUsage()
29
30 # ==============================================================================
31 class ElementaryAlgorithm(BasicObjects.Algorithm):
32     def __init__(self):
33         BasicObjects.Algorithm.__init__(self)
34         self._name = "BLUE"
35         logging.debug("%s Initialisation"%self._name)
36
37     def run(self, Xb=None, Y=None, H=None, M=None, R=None, B=None, Q=None, Par=None):
38         """
39         Calcul de l'estimateur BLUE (ou Kalman simple, ou Interpolation Optimale)
40         """
41         logging.debug("%s Lancement"%self._name)
42         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
43         #
44         Hm = H["Direct"].asMatrix()
45         Ht = H["Adjoint"].asMatrix()
46         #
47         # Utilisation éventuelle d'un vecteur H(Xb) précalculé
48         # ----------------------------------------------------
49         if H["AppliedToX"] is not None and H["AppliedToX"].has_key("HXb"):
50             logging.debug("%s Utilisation de HXb"%self._name)
51             HXb = H["AppliedToX"]["HXb"]
52         else:
53             logging.debug("%s Calcul de Hm * Xb"%self._name)
54             HXb = Hm * Xb
55         
56         # Calcul de la matrice de gain dans l'espace le plus petit
57         if Y.size <= Xb.size:
58             logging.debug("%s Calcul de K dans l'espace des observations"%self._name)
59             K  = B * Ht * (Hm * B * Ht + R).I
60         else:
61             logging.debug("%s Calcul de K dans l'espace d'ébauche"%self._name)
62             K = (Ht * R.I * Hm + B.I).I * Ht * R.I
63         #
64         # Calcul de l'innovation et de l'analyse
65         # --------------------------------------
66         d  = Y - HXb
67         logging.debug("%s Innovation d = %s"%(self._name, d))
68         Xa = Xb + K*d
69         logging.debug("%s Analyse Xa = %s"%(self._name, Xa))
70         #
71         self.StoredVariables["Analysis"].store( Xa.A1 )
72         self.StoredVariables["Innovation"].store( d.A1 )
73         #
74         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("MB")))
75         logging.debug("%s Terminé"%self._name)
76         #
77         return 0
78
79 # ==============================================================================
80 if __name__ == "__main__":
81     print '\n AUTODIAGNOSTIC \n'