1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2009 EDF R&D
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.
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.
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
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 Algorithme de methode d'ensemble simple
24 __author__ = "Sebastien MASSART, Jean-Philippe ARGAUD - Novembre 2008"
26 import sys ; sys.path.insert(0, "../daCore")
30 from BasicObjects import Algorithm
31 import PlatformInfo ; m = PlatformInfo.SystemUsage()
33 # ==============================================================================
34 class ElementaryAlgorithm(Algorithm):
36 Algorithm.__init__(self)
37 self._name = "ENSEMBLEBLUE"
38 logging.debug("%s Initialisation"%self._name)
40 def run(self, Xb=None, Y=None, H=None, M=None, R=None, B=None, Q=None, Par=None ):
42 Calcul d'une estimation BLUE d'ensemble :
43 - génération d'un ensemble d'observations, de même taille que le
45 - calcul de l'estimateur BLUE pour chaque membre de l'ensemble
47 logging.debug("%s Lancement"%self._name)
48 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
50 # Nombre d'ensemble pour l'ébauche
51 # --------------------------------
52 nb_ens = Xb.stepnumber()
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)
64 # Initialisation des opérateurs d'observation et de la matrice gain
65 # -----------------------------------------------------------------
66 Hm = H["Direct"].asMatrix()
67 Ht = H["Adjoint"].asMatrix()
69 K = B * Ht * (Hm * B * Ht + R).I
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
77 self.StoredVariables["Analysis"].store( Xa.A1 )
78 self.StoredVariables["Innovation"].store( d.A1 )
80 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
81 logging.debug("%s Terminé"%self._name)
84 # ==============================================================================
85 if __name__ == "__main__":
86 print '\n AUTODIAGNOSTIC \n'