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