From e3a7a588c292927b2d6a5f25b38b861edea6b01d Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Thu, 9 Aug 2012 14:27:53 +0200 Subject: [PATCH] Improve checking of a posteriori covariance calculations --- src/daComposant/daAlgorithms/3DVAR.py | 15 ++++++++++----- src/daComposant/daAlgorithms/Blue.py | 7 ++++++- .../daAlgorithms/NonLinearLeastSquares.py | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/daComposant/daAlgorithms/3DVAR.py b/src/daComposant/daAlgorithms/3DVAR.py index 9cdced7..dbb710b 100644 --- a/src/daComposant/daAlgorithms/3DVAR.py +++ b/src/daComposant/daAlgorithms/3DVAR.py @@ -26,7 +26,7 @@ m = PlatformInfo.SystemUsage() import numpy import scipy.optimize -if logging.getLogger().level < 30: +if logging.getLogger().level < logging.WARNING: iprint = 1 message = scipy.optimize.tnc.MSG_ALL disp = 1 @@ -276,16 +276,21 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # Calcul de la covariance d'analyse # --------------------------------- if self._parameters["CalculateAPosterioriCovariance"]: - Hessienne = [] + HessienneI = [] nb = len(Xini) for i in range(nb): _ee = numpy.matrix(numpy.zeros(nb)).T _ee[i] = 1. _HmEE = Hm(_ee) _HmEE = numpy.asmatrix(_HmEE).flatten().T - Hessienne.append( ( BI*_ee + Ha((Xa,RI*_HmEE)) ).A1 ) - Hessienne = numpy.matrix( Hessienne ) - A = Hessienne.I + HessienneI.append( ( BI*_ee + Ha((Xa,RI*_HmEE)) ).A1 ) + HessienneI = numpy.matrix( HessienneI ) + A = HessienneI.I + if logging.getLogger().level < logging.WARNING: # La verification n'a lieu qu'en debug + try: + L = numpy.linalg.cholesky( A ) + except: + raise ValueError("The 3DVAR a posteriori covariance matrix A is not symmetric positive-definite. Check your B and R a priori covariances.") self.StoredVariables["APosterioriCovariance"].store( A ) # logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("MB"))) diff --git a/src/daComposant/daAlgorithms/Blue.py b/src/daComposant/daAlgorithms/Blue.py index 98995d5..b155611 100644 --- a/src/daComposant/daAlgorithms/Blue.py +++ b/src/daComposant/daAlgorithms/Blue.py @@ -119,7 +119,12 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # Calcul de la covariance d'analyse # --------------------------------- if self._parameters["CalculateAPosterioriCovariance"]: - A = ( 1.0 - K * Hm ) * B + A = B - K * Hm * B + if logging.getLogger().level < logging.WARNING: # La verification n'a lieu qu'en debug + try: + L = numpy.linalg.cholesky( A ) + except: + raise ValueError("The BLUE a posteriori covariance matrix A is not symmetric positive-definite. Check your B and R a priori covariances.") self.StoredVariables["APosterioriCovariance"].store( A ) # logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo"))) diff --git a/src/daComposant/daAlgorithms/NonLinearLeastSquares.py b/src/daComposant/daAlgorithms/NonLinearLeastSquares.py index 3709224..f77ab01 100644 --- a/src/daComposant/daAlgorithms/NonLinearLeastSquares.py +++ b/src/daComposant/daAlgorithms/NonLinearLeastSquares.py @@ -26,7 +26,7 @@ m = PlatformInfo.SystemUsage() import numpy import scipy.optimize -if logging.getLogger().level < 30: +if logging.getLogger().level < logging.WARNING: iprint = 1 message = scipy.optimize.tnc.MSG_ALL disp = 1 -- 2.39.2