]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Avoiding unnecessary calculations
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 5 Jun 2013 13:49:58 +0000 (15:49 +0200)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 5 Jun 2013 13:49:58 +0000 (15:49 +0200)
src/daComposant/daAlgorithms/Blue.py
src/daComposant/daAlgorithms/LinearLeastSquares.py

index 99619a219a3d2aa10c5e1de716ad6eb20ed41c80..915c51f4912704a785bfcc2cbc5cde3fab9123f3 100644 (file)
@@ -30,6 +30,12 @@ import numpy
 class ElementaryAlgorithm(BasicObjects.Algorithm):
     def __init__(self):
         BasicObjects.Algorithm.__init__(self, "BLUE")
+        self.defineRequiredParameter(
+            name     = "StoreInternalVariables",
+            default  = False,
+            typecast = bool,
+            message  = "Stockage des variables internes ou intermédiaires du calcul",
+            )
         self.defineRequiredParameter(
             name     = "StoreSupplementaryCalculations",
             default  = [],
@@ -49,7 +55,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         # Opérateur d'observation
         # -----------------------
         Hm = HO["Tangent"].asMatrix(Xb)
+        Hm = Hm.reshape(Y.size,Xb.size) # ADAO & check shape
         Ha = HO["Adjoint"].asMatrix(Xb)
+        Ha = Ha.reshape(Xb.size,Y.size) # ADAO & check shape
         #
         # Utilisation éventuelle d'un vecteur H(Xb) précalculé
         # ----------------------------------------------------
@@ -93,17 +101,19 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         else:
             K = (Ha * RI * Hm + BI).I * Ha * RI
         Xa = Xb + K*d
+        self.StoredVariables["Analysis"].store( Xa.A1 )
         #
         # Calcul de la fonction coût
         # --------------------------
-        oma = Y - Hm * Xa
-        Jb  = 0.5 * (Xa - Xb).T * BI * (Xa - Xb)
-        Jo  = 0.5 * oma.T * RI * oma
-        J   = float( Jb ) + float( Jo )
-        self.StoredVariables["Analysis"].store( Xa.A1 )
-        self.StoredVariables["CostFunctionJb"].store( Jb )
-        self.StoredVariables["CostFunctionJo"].store( Jo )
-        self.StoredVariables["CostFunctionJ" ].store( J )
+        if self._parameters["StoreInternalVariables"] or "OMA" in self._parameters["StoreSupplementaryCalculations"] or "SigmaObs2" in self._parameters["StoreSupplementaryCalculations"] or "MahalanobisConsistency" in self._parameters["StoreSupplementaryCalculations"]:
+            oma = Y - Hm * Xa
+        if self._parameters["StoreInternalVariables"] or "MahalanobisConsistency" in self._parameters["StoreSupplementaryCalculations"]:
+            Jb  = 0.5 * (Xa - Xb).T * BI * (Xa - Xb)
+            Jo  = 0.5 * oma.T * RI * oma
+            J   = float( Jb ) + float( Jo )
+            self.StoredVariables["CostFunctionJb"].store( Jb )
+            self.StoredVariables["CostFunctionJo"].store( Jo )
+            self.StoredVariables["CostFunctionJ" ].store( J )
         #
         # Calcul de la covariance d'analyse
         # ---------------------------------
index 5ef5e6812f371e4a8bf6f8b3390b40e32757db26..cd0496b2ee999e060c5b125c0121de36dc50c0c2 100644 (file)
@@ -30,6 +30,12 @@ import numpy
 class ElementaryAlgorithm(BasicObjects.Algorithm):
     def __init__(self):
         BasicObjects.Algorithm.__init__(self, "LINEARLEASTSQUARES")
+        self.defineRequiredParameter(
+            name     = "StoreInternalVariables",
+            default  = False,
+            typecast = bool,
+            message  = "Stockage des variables internes ou intermédiaires du calcul",
+            )
         self.defineRequiredParameter(
             name     = "StoreSupplementaryCalculations",
             default  = [],
@@ -49,7 +55,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         # Opérateur d'observation
         # -----------------------
         Hm = HO["Tangent"].asMatrix(None)
+        Hm = Hm.reshape(Y.size,-1) # ADAO & check shape
         Ha = HO["Adjoint"].asMatrix(None)
+        Ha = Ha.reshape(-1,Y.size) # ADAO & check shape
         #
         if R is not None:
             RI = R.I
@@ -62,17 +70,19 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         # --------------------------------------------
         K =  (Ha * RI * Hm ).I * Ha * RI
         Xa =  K * Y
+        self.StoredVariables["Analysis"].store( Xa.A1 )
         #
         # Calcul de la fonction coût
         # --------------------------
-        oma = Y - Hm * Xa
-        Jb  = 0.
-        Jo  = 0.5 * oma.T * RI * oma
-        J   = float( Jb ) + float( Jo )
-        self.StoredVariables["Analysis"].store( Xa.A1 )
-        self.StoredVariables["CostFunctionJb"].store( Jb )
-        self.StoredVariables["CostFunctionJo"].store( Jo )
-        self.StoredVariables["CostFunctionJ" ].store( J )
+        if self._parameters["StoreInternalVariables"] or "OMA" in self._parameters["StoreSupplementaryCalculations"]:
+            oma = Y - Hm * Xa
+        if self._parameters["StoreInternalVariables"]:
+            Jb  = 0.
+            Jo  = 0.5 * oma.T * RI * oma
+            J   = float( Jb ) + float( Jo )
+            self.StoredVariables["CostFunctionJb"].store( Jb )
+            self.StoredVariables["CostFunctionJo"].store( Jo )
+            self.StoredVariables["CostFunctionJ" ].store( J )
         #
         # Calculs et/ou stockages supplémentaires
         # ---------------------------------------