1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2011 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
23 from daCore import BasicObjects, PlatformInfo
24 m = PlatformInfo.SystemUsage()
28 # ==============================================================================
29 class ElementaryAlgorithm(BasicObjects.Algorithm):
31 BasicObjects.Algorithm.__init__(self)
32 self._name = "ENSEMBLEBLUE"
33 logging.debug("%s Initialisation"%self._name)
35 def run(self, Xb=None, Y=None, H=None, M=None, R=None, B=None, Q=None, Parameters=None ):
37 Calcul d'une estimation BLUE d'ensemble :
38 - génération d'un ensemble d'observations, de même taille que le
40 - calcul de l'estimateur BLUE pour chaque membre de l'ensemble
42 logging.debug("%s Lancement"%self._name)
43 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
45 # Nombre d'ensemble pour l'ébauche
46 # --------------------------------
47 nb_ens = Xb.stepnumber()
49 # Construction de l'ensemble des observations, par génération a partir
50 # de la diagonale de R
51 # --------------------------------------------------------------------
52 DiagonaleR = numpy.diag(R)
53 EnsembleY = numpy.zeros([len(Y),nb_ens])
54 for npar in range(len(DiagonaleR)) :
55 bruit = numpy.random.normal(0,DiagonaleR[npar],nb_ens)
56 EnsembleY[npar,:] = Y[npar] + bruit
57 EnsembleY = numpy.matrix(EnsembleY)
59 # Initialisation des opérateurs d'observation et de la matrice gain
60 # -----------------------------------------------------------------
61 Hm = H["Direct"].asMatrix()
62 Ht = H["Adjoint"].asMatrix()
64 K = B * Ht * (Hm * B * Ht + R).I
66 # Calcul du BLUE pour chaque membre de l'ensemble
67 # -----------------------------------------------
68 for iens in range(nb_ens):
69 d = EnsembleY[:,iens] - Hm * Xb.valueserie(iens)
70 Xa = Xb.valueserie(iens) + K*d
72 self.StoredVariables["Analysis"].store( Xa.A1 )
73 self.StoredVariables["Innovation"].store( d.A1 )
75 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
76 logging.debug("%s Terminé"%self._name)
79 # ==============================================================================
80 if __name__ == "__main__":
81 print '\n AUTODIAGNOSTIC \n'