From 0e864bb6cd5963ab2cdb465dd65edd8e96d6303d Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Sun, 20 Sep 2015 19:09:14 +0200 Subject: [PATCH] Covariance checking improvement --- src/daComposant/daCore/AssimilationStudy.py | 6 ++++++ src/daComposant/daCore/BasicObjects.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/daComposant/daCore/AssimilationStudy.py b/src/daComposant/daCore/AssimilationStudy.py index 3e26d02..5357a6f 100644 --- a/src/daComposant/daCore/AssimilationStudy.py +++ b/src/daComposant/daCore/AssimilationStudy.py @@ -137,6 +137,7 @@ class AssimilationStudy: asEyeByVector = None, asCovObject = None, toBeStored = False, + toBeChecked = False, ): """ Permet de définir la covariance des erreurs d'ébauche : @@ -159,6 +160,7 @@ class AssimilationStudy: asEyeByScalar = asEyeByScalar, asEyeByVector = asEyeByVector, asCovObject = asCovObject, + toBeChecked = toBeChecked, ) if toBeStored: self.__StoredInputs["BackgroundError"] = self.__B @@ -202,6 +204,7 @@ class AssimilationStudy: asEyeByVector = None, asCovObject = None, toBeStored = False, + toBeChecked = False, ): """ Permet de définir la covariance des erreurs d'observations : @@ -224,6 +227,7 @@ class AssimilationStudy: asEyeByScalar = asEyeByScalar, asEyeByVector = asEyeByVector, asCovObject = asCovObject, + toBeChecked = toBeChecked, ) if toBeStored: self.__StoredInputs["ObservationError"] = self.__R @@ -430,6 +434,7 @@ class AssimilationStudy: asEyeByVector = None, asCovObject = None, toBeStored = False, + toBeChecked = False, ): """ Permet de définir la covariance des erreurs de modèle : @@ -452,6 +457,7 @@ class AssimilationStudy: asEyeByScalar = asEyeByScalar, asEyeByVector = asEyeByVector, asCovObject = asCovObject, + toBeChecked = toBeChecked, ) if toBeStored: self.__StoredInputs["EvolutionError"] = self.__Q diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 69aace2..57d4e41 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -510,6 +510,7 @@ class Covariance: asEyeByScalar = None, asEyeByVector = None, asCovObject = None, + toBeChecked = False, ): """ Permet de définir une covariance : @@ -525,8 +526,11 @@ class Covariance: methodes obligatoires "getT", "getI", "diag", "trace", "__add__", "__sub__", "__neg__", "__mul__", "__rmul__" et facultatives "shape", "size", "cholesky", "choleskyI", "asfullmatrix", "__repr__", "__str__" + - toBeChecked : booléen indiquant si le caractère SDP de la matrice + pleine doit être vérifié """ self.__name = str(name) + self.__check = bool(toBeChecked) # self.__C = None self.__is_scalar = False @@ -577,11 +581,16 @@ class Covariance: raise ValueError("The \"%s\" covariance matrix is not positive-definite. Please check your scalar input %s."%(self.__name,self.__C)) if self.isvector() and (self.__C <= 0).any(): raise ValueError("The \"%s\" covariance matrix is not positive-definite. Please check your vector input."%(self.__name,)) - if self.ismatrix() and logging.getLogger().level < logging.WARNING: # La verification n'a lieu qu'en debug + if self.ismatrix() and (self.__check or logging.getLogger().level < logging.WARNING): try: L = numpy.linalg.cholesky( self.__C ) except: raise ValueError("The %s covariance matrix is not symmetric positive-definite. Please check your matrix input."%(self.__name,)) + if self.isobject() and (self.__check or logging.getLogger().level < logging.WARNING): + try: + L = self.__C.cholesky() + except: + raise ValueError("The %s covariance object is not symmetric positive-definite. Please check your matrix input."%(self.__name,)) def isscalar(self): return self.__is_scalar -- 2.39.2