1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2014 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
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 from daCore import BasicObjects, PlatformInfo
25 m = PlatformInfo.SystemUsage()
28 # ==============================================================================
29 class ElementaryAlgorithm(BasicObjects.Algorithm):
31 BasicObjects.Algorithm.__init__(self, "ENSEMBLEBLUE")
32 self.defineRequiredParameter(
34 typecast = numpy.random.seed,
35 message = "Graine fixée pour le générateur aléatoire",
38 def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
39 logging.debug("%s Lancement"%self._name)
40 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
42 # Paramètres de pilotage
43 # ----------------------
44 self.setParameters(Parameters)
46 # Précalcul des inversions de B et R
47 # ----------------------------------
51 # Nombre d'ensemble pour l'ébauche
52 # --------------------------------
53 nb_ens = Xb.stepnumber()
55 # Construction de l'ensemble des observations, par génération a partir
56 # de la diagonale de R
57 # --------------------------------------------------------------------
58 DiagonaleR = R.diag(Y.size)
59 EnsembleY = numpy.zeros([Y.size,nb_ens])
60 for npar in range(DiagonaleR.size):
61 bruit = numpy.random.normal(0,DiagonaleR[npar],nb_ens)
62 EnsembleY[npar,:] = Y[npar] + bruit
63 EnsembleY = numpy.matrix(EnsembleY)
65 # Initialisation des opérateurs d'observation et de la matrice gain
66 # -----------------------------------------------------------------
67 Hm = HO["Tangent"].asMatrix(None)
68 Hm = Hm.reshape(Y.size,Xb[0].size) # ADAO & check shape
69 Ha = HO["Adjoint"].asMatrix(None)
70 Ha = Ha.reshape(Xb[0].size,Y.size) # ADAO & check shape
72 # Calcul de la matrice de gain dans l'espace le plus petit et de l'analyse
73 # ------------------------------------------------------------------------
74 if Y.size <= Xb[0].size:
75 K = B * Ha * (R + Hm * B * Ha).I
77 K = (BI + Ha * RI * Hm).I * Ha * RI
79 # Calcul du BLUE pour chaque membre de l'ensemble
80 # -----------------------------------------------
81 for iens in range(nb_ens):
82 d = EnsembleY[:,iens] - Hm * Xb[iens]
84 self.StoredVariables["CurrentState"].store( Xa )
85 self.StoredVariables["Innovation"].store( d.A1 )
87 # Fabrication de l'analyse
88 # ------------------------
89 Members = self.StoredVariables["CurrentState"][-nb_ens:]
90 Xa = numpy.matrix( Members ).mean(axis=0)
91 self.StoredVariables["Analysis"].store( Xa.A1 )
93 logging.debug("%s Nombre d'évaluation(s) de l'opérateur d'observation direct/tangent/adjoint.: %i/%i/%i"%(self._name, HO["Direct"].nbcalls(0),HO["Tangent"].nbcalls(0),HO["Adjoint"].nbcalls(0)))
94 logging.debug("%s Nombre d'appels au cache d'opérateur d'observation direct/tangent/adjoint..: %i/%i/%i"%(self._name, HO["Direct"].nbcalls(3),HO["Tangent"].nbcalls(3),HO["Adjoint"].nbcalls(3)))
95 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
96 logging.debug("%s Terminé"%self._name)
99 # ==============================================================================
100 if __name__ == "__main__":
101 print '\n AUTODIAGNOSTIC \n'