#-*-coding:iso-8859-1-*-
#
-# Copyright (C) 2008-2011 EDF R&D
+# Copyright (C) 2008-2012 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
#
# Paramètres de pilotage
# ----------------------
- # Potentiels : "Bounds", "Minimizer", "MaximumNumberOfSteps", "ProjectedGradientTolerance", "GradientNormTolerance", "InnerMinimizer"
+ # Potentiels : "Bounds", "Minimizer", "MaximumNumberOfSteps", "ProjectedGradientTolerance", "GradientNormTolerance", "InnerMinimizer", "CalculateAPosterioriCovariance"
if Parameters.has_key("Bounds") and (type(Parameters["Bounds"]) is type([]) or type(Parameters["Bounds"]) is type(())) and (len(Parameters["Bounds"]) > 0):
Bounds = Parameters["Bounds"]
else:
else:
InnerMinimizer = "BFGS"
logging.debug("%s Minimiseur interne utilisé = %s"%(self._name, InnerMinimizer))
+ if Parameters.has_key("CalculateAPosterioriCovariance"):
+ CalculateAPosterioriCovariance = bool(Parameters["CalculateAPosterioriCovariance"])
+ else:
+ CalculateAPosterioriCovariance = False
+ logging.debug("%s Calcul de la covariance a posteriori = %s"%(self._name, CalculateAPosterioriCovariance))
#
# Minimisation de la fonctionnelle
# --------------------------------
self.StoredVariables["Analysis"].store( Xa.A1 )
self.StoredVariables["Innovation"].store( d.A1 )
#
+ # Calcul de la covariance d'analyse
+ # ---------------------------------
+ if CalculateAPosterioriCovariance:
+ Hessienne = []
+ nb = len(Xini)
+ for i in range(nb):
+ ee = numpy.matrix(numpy.zeros(nb)).T
+ ee[i] = 1.
+ Hessienne.append( ( BI*ee + Ht((Xa,RI*Hm(ee))) ).A1 )
+ Hessienne = numpy.matrix( Hessienne )
+ A = Hessienne.I
+ self.StoredVariables["APosterioriCovariance"].store( A )
+ #
logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("MB")))
logging.debug("%s Terminé"%self._name)
#
#-*-coding:iso-8859-1-*-
#
-# Copyright (C) 2008-2011 EDF R&D
+# Copyright (C) 2008-2012 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
d = Y - HXb
logging.debug("%s Innovation d = %s"%(self._name, d))
#
+ # Paramètres de pilotage
+ # ----------------------
+ # Potentiels : "CalculateAPosterioriCovariance"
+ if Parameters.has_key("CalculateAPosterioriCovariance"):
+ CalculateAPosterioriCovariance = bool(Parameters["CalculateAPosterioriCovariance"])
+ else:
+ CalculateAPosterioriCovariance = False
+ logging.debug("%s Calcul de la covariance a posteriori = %s"%(self._name, CalculateAPosterioriCovariance))
+ #
# Calcul de la matrice de gain dans l'espace le plus petit et de l'analyse
# ------------------------------------------------------------------------
if Y.size <= Xb.size:
self.StoredVariables["CostFunctionJo"].store( Jo )
self.StoredVariables["CostFunctionJ" ].store( J )
#
+ # Calcul de la covariance d'analyse
+ # ---------------------------------
+ if CalculateAPosterioriCovariance:
+ A = ( 1.0 - K * Hm ) * B
+ self.StoredVariables["APosterioriCovariance"].store( A )
+ #
logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("MB")))
logging.debug("%s Terminé"%self._name)
#
#-*-coding:iso-8859-1-*-
#
-# Copyright (C) 2008-2011 EDF R&D
+# Copyright (C) 2008-2012 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# -----------------------------------------------------------------
Hm = H["Direct"].asMatrix()
Ht = H["Adjoint"].asMatrix()
-
+ #
K = B * Ht * (Hm * B * Ht + R).I
-
+ #
# Calcul du BLUE pour chaque membre de l'ensemble
# -----------------------------------------------
for iens in range(nb_ens):
#-*-coding:iso-8859-1-*-
#
-# Copyright (C) 2008-2011 EDF R&D
+# Copyright (C) 2008-2012 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Mm = M["Direct"].asMatrix()
Mt = M["Adjoint"].asMatrix()
#
+ # Paramètres de pilotage
+ # ----------------------
+ if Parameters.has_key("CalculateAPosterioriCovariance"):
+ CalculateAPosterioriCovariance = bool(Parameters["CalculateAPosterioriCovariance"])
+ else:
+ CalculateAPosterioriCovariance = False
+ logging.debug("%s Calcul de la covariance a posteriori = %s"%(self._name, CalculateAPosterioriCovariance))
+ #
+ # Nombre de pas du Kalman identique au nombre de pas d'observations
+ # -----------------------------------------------------------------
duration = Y.stepnumber()
#
# Initialisation
Xn = Xb
Pn = B
self.StoredVariables["Analysis"].store( Xn.A1 )
- self.StoredVariables["CovarianceAPosteriori"].store( Pn )
+ if CalculateAPosterioriCovariance:
+ self.StoredVariables["APosterioriCovariance"].store( Pn )
#
for step in range(duration-1):
logging.debug("%s Etape de Kalman %i (i.e. %i->%i) sur un total de %i"%(self._name, step+1, step,step+1, duration-1))
Pn = Pn_predicted - K * Hm * Pn_predicted
#
self.StoredVariables["Analysis"].store( Xn.A1 )
- self.StoredVariables["CovarianceAPosteriori"].store( Pn )
self.StoredVariables["Innovation"].store( d.A1 )
+ if CalculateAPosterioriCovariance:
+ self.StoredVariables["APosterioriCovariance"].store( Pn )
#
logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo")))
logging.debug("%s Terminé"%self._name)
#-*-coding:iso-8859-1-*-
#
-# Copyright (C) 2008-2011 EDF R&D
+# Copyright (C) 2008-2012 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
- OMA : Observation moins Analysis : Y - Xa
- OMB : Observation moins Background : Y - Xb
- AMB : Analysis moins Background : Xa - Xb
- - CovarianceAPosteriori : matrice A
+ - APosterioriCovariance : matrice A
On peut rajouter des variables à stocker dans l'initialisation de
l'algorithme élémentaire qui va hériter de cette classe
"""
self.StoredVariables["OMA"] = Persistence.OneVector(name = "OMA")
self.StoredVariables["OMB"] = Persistence.OneVector(name = "OMB")
self.StoredVariables["BMA"] = Persistence.OneVector(name = "BMA")
- self.StoredVariables["CovarianceAPosteriori"] = Persistence.OneMatrix(name = "CovarianceAPosteriori")
+ self.StoredVariables["APosterioriCovariance"] = Persistence.OneMatrix(name = "APosterioriCovariance")
def get(self, key=None):
"""