]> SALOME platform Git repositories - modules/adao.git/blob - src/daComposant/daAlgorithms/EnsembleBlue.py
Salome HOME
- Nouvelle version de Jean-Philippe ARGAUD
[modules/adao.git] / src / daComposant / daAlgorithms / EnsembleBlue.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 methode d'ensemble simple
23 """
24 __author__ = "Sebastien MASSART, Jean-Philippe ARGAUD - Novembre 2008"
25
26 import logging
27 from daCore import BasicObjects, PlatformInfo
28 m = PlatformInfo.SystemUsage()
29
30 import numpy
31
32 # ==============================================================================
33 class ElementaryAlgorithm(BasicObjects.Algorithm):
34     def __init__(self):
35         BasicObjects.Algorithm.__init__(self)
36         self._name = "ENSEMBLEBLUE"
37         logging.debug("%s Initialisation"%self._name)
38
39     def run(self, Xb=None, Y=None, H=None, M=None, R=None, B=None, Q=None, Par=None ):
40         """
41         Calcul d'une estimation BLUE d'ensemble :
42             - génération d'un ensemble d'observations, de même taille que le
43               nombre d'ébauches
44             - calcul de l'estimateur BLUE pour chaque membre de l'ensemble
45         """
46         logging.debug("%s Lancement"%self._name)
47         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
48         #
49         # Nombre d'ensemble pour l'ébauche 
50         # --------------------------------
51         nb_ens = Xb.stepnumber()
52         #
53         # Construction de l'ensemble des observations, par génération a partir
54         # de la diagonale de R
55         # --------------------------------------------------------------------
56         DiagonaleR = numpy.diag(R)
57         EnsembleY = numpy.zeros([len(Y),nb_ens])
58         for npar in range(len(DiagonaleR)) : 
59             bruit = numpy.random.normal(0,DiagonaleR[npar],nb_ens)
60             EnsembleY[npar,:] = Y[npar] + bruit
61         EnsembleY = numpy.matrix(EnsembleY)
62         #
63         # Initialisation des opérateurs d'observation et de la matrice gain
64         # -----------------------------------------------------------------
65         Hm = H["Direct"].asMatrix()
66         Ht = H["Adjoint"].asMatrix()
67         
68         K  = B * Ht * (Hm * B * Ht + R).I
69         
70         # Calcul du BLUE pour chaque membre de l'ensemble
71         # -----------------------------------------------
72         for iens in range(nb_ens):
73             d  = EnsembleY[:,iens] - Hm * Xb.valueserie(iens)
74             Xa = Xb.valueserie(iens) + K*d
75             
76             self.StoredVariables["Analysis"].store( Xa.A1 )
77             self.StoredVariables["Innovation"].store( d.A1 )
78         #
79         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
80         logging.debug("%s Terminé"%self._name)
81         return 0
82
83 # ==============================================================================
84 if __name__ == "__main__":
85     print '\n AUTODIAGNOSTIC \n'
86
87