Salome HOME
Correcting treatments of array/matrix sizes
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Fri, 16 Nov 2012 21:22:42 +0000 (22:22 +0100)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Fri, 16 Nov 2012 21:22:42 +0000 (22:22 +0100)
doc/glossary.rst
src/daComposant/daAlgorithms/3DVAR.py
src/daComposant/daAlgorithms/Blue.py
src/daComposant/daAlgorithms/EnsembleBlue.py

index 8a2253a63aa022534fe49b5041b6e9405422a7a3..81f0654c982f372306d61d859d91f63bc8c09ee9 100644 (file)
@@ -44,16 +44,16 @@ Glossary
    SigmaBck2
       Keyword to indicate the Desroziers-Ivanov parameter measuring the
       background part consistency of the data assimilation optimal state
-      estimation.
+      estimation. It can be compared to 1.
 
    SigmaObs2
       Keyword to indicate the Desroziers-Ivanov parameter measuring the
       observation part consistency of the data assimilation optimal state
-      estimation.
+      estimation. It can be compared to 1.
 
    MahalanobisConsistency
       Keyword to indicate the Mahalanobis parameter measuring the consistency of
-      the data assimilation optimal state estimation.
+      the data assimilation optimal state estimation. It can be compared to 1.
 
    analysis
       The optimal state estimation through a data assimilation or optimization
index e288f185fd8303724c72039f25290e27e4858200..7650d80082c8ca8c2ef416f47bca2ee37c233f6b 100644 (file)
@@ -258,11 +258,11 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         # ---------------------------------
         if "APosterioriCovariance" in self._parameters["StoreSupplementaryCalculations"]:
             HtM = H["Tangent"].asMatrix(ValueForMethodForm = Xa)
-            HtM = HtM.reshape(len(Y),len(Xa.A1)) # ADAO & check shape
+            HtM = HtM.reshape(Y.size,Xa.size) # ADAO & check shape
             HaM = H["Adjoint"].asMatrix(ValueForMethodForm = Xa)
-            HaM = HaM.reshape(len(Xa.A1),len(Y)) # ADAO & check shape
+            HaM = HaM.reshape(Xa.size,Y.size) # ADAO & check shape
             HessienneI = []
-            nb = len(Xa.A1)
+            nb = Xa.size
             for i in range(nb):
                 _ee    = numpy.matrix(numpy.zeros(nb)).T
                 _ee[i] = 1.
@@ -272,12 +272,14 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
             HessienneI = numpy.matrix( HessienneI )
             A = HessienneI.I
             if min(A.shape) != max(A.shape):
-                raise ValueError("The 3DVAR a posteriori covariance matrix A is of shape %s, despites it has to be a squared matrix. There is an error in the observation operator."%str(A.shape))
+                raise ValueError("The %s a posteriori covariance matrix A is of shape %s, despites it has to be a squared matrix. There is an error in the observation operator, please check it."%(self._name,str(A.shape)))
+            if (numpy.diag(A) < 0).any():
+                raise ValueError("The %s a posteriori covariance matrix A has at least one negative value on its diagonal. There is an error in the observation operator, please check it."%(self._name,))
             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.")
+                    raise ValueError("The %s a posteriori covariance matrix A is not symmetric positive-definite. Please check your a priori covariances and your observation operator."%(self._name,))
             self.StoredVariables["APosterioriCovariance"].store( A )
         #
         # Calculs et/ou stockages supplémentaires
@@ -291,9 +293,13 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         if "OMB" in self._parameters["StoreSupplementaryCalculations"]:
             self.StoredVariables["OMB"].store( numpy.ravel(d) )
         if "SigmaObs2" in self._parameters["StoreSupplementaryCalculations"]:
-            self.StoredVariables["SigmaObs2"].store( float( (d.T * (Y-Hm(Xa))) / R.trace() ) )
+            if R is not None:
+                TraceR = R.trace()
+            elif self._parameters["R_scalar"] is not None:
+                TraceR =  float(self._parameters["R_scalar"]*Y.size)
+            self.StoredVariables["SigmaObs2"].store( float( (d.T * (numpy.asmatrix(numpy.ravel(Y)).T-numpy.asmatrix(numpy.ravel(Hm(Xa))).T)) ) / TraceR )
         if "MahalanobisConsistency" in self._parameters["StoreSupplementaryCalculations"]:
-            self.StoredVariables["MahalanobisConsistency"].store( float( 2.*MinJ/len(d) ) )
+            self.StoredVariables["MahalanobisConsistency"].store( float( 2.*MinJ/d.size ) )
         #
         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
         logging.debug("%s Terminé"%self._name)
index 7c43874a1c8cb4ad46fdd48717936aed0c61267b..79f4d65df55920861f17258ce61227e65c59f7b3 100644 (file)
@@ -110,12 +110,14 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         if "APosterioriCovariance" in self._parameters["StoreSupplementaryCalculations"]:
             A = B - K * Hm * B
             if min(A.shape) != max(A.shape):
-                raise ValueError("The 3DVAR a posteriori covariance matrix A is of shape %s, despites it has to be a squared matrix. There is an error in the observation operator."%str(A.shape))
+                raise ValueError("The %s a posteriori covariance matrix A is of shape %s, despites it has to be a squared matrix. There is an error in the observation operator, please check it."%(self._name,str(A.shape)))
+            if (numpy.diag(A) < 0).any():
+                raise ValueError("The %s a posteriori covariance matrix A has at least one negative value on its diagonal. There is an error in the observation operator, please check it."%(self._name,))
             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.")
+                    raise ValueError("The %s a posteriori covariance matrix A is not symmetric positive-definite. Please check your a priori covariances and your observation operator."%(self._name,))
             self.StoredVariables["APosterioriCovariance"].store( A )
         #
         # Calculs et/ou stockages supplémentaires
@@ -129,11 +131,15 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         if "OMB" in self._parameters["StoreSupplementaryCalculations"]:
             self.StoredVariables["OMB"].store( numpy.ravel(d) )
         if "SigmaObs2" in self._parameters["StoreSupplementaryCalculations"]:
-            self.StoredVariables["SigmaObs2"].store( float( (d.T * (Y-Hm*Xa)) / R.trace() ) )
+            if R is not None:
+                TraceR = R.trace()
+            elif self._parameters["R_scalar"] is not None:
+                TraceR =  float(self._parameters["R_scalar"]*Y.size)
+            self.StoredVariables["SigmaObs2"].store( float( (d.T * (numpy.asmatrix(numpy.ravel(oma)).T)) ) / TraceR )
         if "SigmaBck2" in self._parameters["StoreSupplementaryCalculations"]:
             self.StoredVariables["SigmaBck2"].store( float( (d.T * Hm * (Xa - Xb))/(Hm * B * Hm.T).trace() ) )
         if "MahalanobisConsistency" in self._parameters["StoreSupplementaryCalculations"]:
-            self.StoredVariables["MahalanobisConsistency"].store( float( 2.*J/len(d) ) )
+            self.StoredVariables["MahalanobisConsistency"].store( float( 2.*J/d.size ) )
         #
         logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
         logging.debug("%s Terminé"%self._name)
index 5b25f6949e60ee1a4ae1b728fe91d6ce42ee8616..9fc1281f3eba2ebbff542b9dd0c8205098299426 100644 (file)
@@ -69,8 +69,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         # de la diagonale de R
         # --------------------------------------------------------------------
         DiagonaleR = numpy.diag(R)
-        EnsembleY = numpy.zeros([len(Y),nb_ens])
-        for npar in range(len(DiagonaleR)) : 
+        EnsembleY = numpy.zeros([Y.size,nb_ens])
+        for npar in range(DiagonaleR.size) : 
             bruit = numpy.random.normal(0,DiagonaleR[npar],nb_ens)
             EnsembleY[npar,:] = Y[npar] + bruit
         EnsembleY = numpy.matrix(EnsembleY)
@@ -84,7 +84,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         # ------------------------------------------------------------------------
         if Y.size <= Xb.valueserie(0).size:
             if self._parameters["R_scalar"] is not None:
-                R = self._parameters["R_scalar"] * numpy.eye(len(Y), dtype=numpy.float)
+                R = self._parameters["R_scalar"] * numpy.eye(Y.size, dtype=numpy.float)
             K  = B * Ha * (Hm * B * Ha + R).I
         else:
             K = (Ha * RI * Hm + BI).I * Ha * RI