1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2010 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"
27 from daCore import BasicObjects, PlatformInfo
28 m = PlatformInfo.SystemUsage()
32 # ==============================================================================
33 class ElementaryAlgorithm(BasicObjects.Algorithm):
35 BasicObjects.Algorithm.__init__(self)
36 self._name = "ENSEMBLEBLUE"
37 logging.debug("%s Initialisation"%self._name)
39 def run(self, Xb=None, Y=None, H=None, M=None, R=None, B=None, Q=None, Par=None ):
41 Calcul d'une estimation BLUE d'ensemble :
42 - génération d'un ensemble d'observations, de même taille que le
44 - calcul de l'estimateur BLUE pour chaque membre de l'ensemble
46 logging.debug("%s Lancement"%self._name)
47 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
49 # Nombre d'ensemble pour l'ébauche
50 # --------------------------------
51 nb_ens = Xb.stepnumber()
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)
63 # Initialisation des opérateurs d'observation et de la matrice gain
64 # -----------------------------------------------------------------
65 Hm = H["Direct"].asMatrix()
66 Ht = H["Adjoint"].asMatrix()
68 K = B * Ht * (Hm * B * Ht + R).I
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
76 self.StoredVariables["Analysis"].store( Xa.A1 )
77 self.StoredVariables["Innovation"].store( d.A1 )
79 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
80 logging.debug("%s Terminé"%self._name)
83 # ==============================================================================
84 if __name__ == "__main__":
85 print '\n AUTODIAGNOSTIC \n'