]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Improve multisteps KF-like analysis by avoiding dual storage
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 15 May 2019 19:18:32 +0000 (21:18 +0200)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 15 May 2019 19:18:32 +0000 (21:18 +0200)
src/daComposant/daAlgorithms/EnsembleKalmanFilter.py
src/daComposant/daAlgorithms/ExtendedKalmanFilter.py
src/daComposant/daAlgorithms/KalmanFilter.py
src/daComposant/daAlgorithms/UnscentedKalmanFilter.py
src/daComposant/daCore/Aidsm.py
src/daComposant/daCore/BasicObjects.py
src/daComposant/daCore/Interfaces.py

index 9448ec4dc47ae3c819f8b304b0acbdbdd6835a17..3ec8099623ffe03a00d5e4a56a0eaad80ba4c756 100644 (file)
@@ -140,11 +140,14 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         if hasattr(Q,"asfullmatrix"): Qn = Q.asfullmatrix(__n)
         else:                         Qn = Q
         #
-        self.StoredVariables["Analysis"].store( Xb.A1 )
-        if self._toStore("APosterioriCovariance"):
-            self.StoredVariables["APosterioriCovariance"].store( Pn )
-            covarianceXa = Pn
-        Xa = XaMin       = Xb
+        if len(self.StoredVariables["Analysis"])==0 or not self._parameters["nextStep"]:
+            self.StoredVariables["Analysis"].store( numpy.ravel(Xb) )
+            if self._toStore("APosterioriCovariance"):
+                self.StoredVariables["APosterioriCovariance"].store( Pn )
+                covarianceXa = Pn
+        #
+        Xa               = Xb
+        XaMin            = Xb
         previousJMinimum = numpy.finfo(float).max
         #
         # Predimensionnement
index bf3a83056a35f59020ff25eb207852045d995a38..dfcb3c5c3cbae5d5f728b3c3a7880a6c2e0d3013 100644 (file)
@@ -127,11 +127,14 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         Xn = Xb
         Pn = B
         #
-        self.StoredVariables["Analysis"].store( Xn.A1 )
-        if self._toStore("APosterioriCovariance"):
-            self.StoredVariables["APosterioriCovariance"].store( Pn.asfullmatrix(Xn.size) )
-            covarianceXa = Pn
-        Xa = XaMin       = Xn
+        if len(self.StoredVariables["Analysis"])==0 or not self._parameters["nextStep"]:
+            self.StoredVariables["Analysis"].store( numpy.ravel(Xn) )
+            if self._toStore("APosterioriCovariance"):
+                self.StoredVariables["APosterioriCovariance"].store( Pn.asfullmatrix(Xn.size) )
+                covarianceXa = Pn
+        #
+        Xa               = Xn
+        XaMin            = Xn
         previousJMinimum = numpy.finfo(float).max
         #
         for step in range(duration-1):
index 08210fd4f20a85187fa6f9be9aec91c969a89ec3..411427014917ab2790e6e0e36b40da724a1b10ca 100644 (file)
@@ -118,10 +118,12 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         Xn = Xb
         Pn = B
         #
-        self.StoredVariables["Analysis"].store( Xn.A1 )
-        if self._toStore("APosterioriCovariance"):
-            self.StoredVariables["APosterioriCovariance"].store( Pn.asfullmatrix(Xn.size) )
-            covarianceXa = Pn
+        if len(self.StoredVariables["Analysis"])==0 or not self._parameters["nextStep"]:
+            self.StoredVariables["Analysis"].store( numpy.ravel(Xn) )
+            if self._toStore("APosterioriCovariance"):
+                self.StoredVariables["APosterioriCovariance"].store( Pn.asfullmatrix(Xn.size) )
+                covarianceXa = Pn
+        #
         Xa               = Xn
         previousJMinimum = numpy.finfo(float).max
         #
index 43c873069d4a1c1c165af2932bee03a23a11f993..e282caeba03226d2bfc4bfda96803dba3fa0dfb9 100644 (file)
@@ -164,15 +164,19 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         #
         # Initialisation
         # --------------
+        __n = Xb.size
         Xn = Xb
-        if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(Xn.size)
+        if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(__n)
         else:                         Pn = B
         #
-        self.StoredVariables["Analysis"].store( Xn.A1 )
-        if self._toStore("APosterioriCovariance"):
-            self.StoredVariables["APosterioriCovariance"].store( Pn )
-            covarianceXa = Pn
-        Xa = XaMin       = Xb
+        if len(self.StoredVariables["Analysis"])==0 or not self._parameters["nextStep"]:
+            self.StoredVariables["Analysis"].store( numpy.ravel(Xb) )
+            if self._toStore("APosterioriCovariance"):
+                self.StoredVariables["APosterioriCovariance"].store( Pn )
+                covarianceXa = Pn
+        #
+        Xa               = Xb
+        XaMin            = Xb
         previousJMinimum = numpy.finfo(float).max
         #
         for step in range(duration-1):
index 190b40cd62789eab3198580a9da07d964b904301..e753bc418a920d2e74544d18b72c74778e024512 100644 (file)
@@ -666,10 +666,11 @@ class Aidsm(object):
 
     # -----------------------------------------------------------
 
-    def execute(self, Executor=None, SaveCaseInFile=None):
+    def execute(self, Executor=None, SaveCaseInFile=None, nextStep=False):
         "Lancement du calcul"
         self.__case.register("execute",dir(),locals(),None,True)
-        Operator.CM.clearCache()
+        self.updateAlgorithmParameters(Parameters={"nextStep":bool(nextStep)})
+        if not nextStep: Operator.CM.clearCache()
         try:
             if   Executor == "YACS": self.__executeYACSScheme( SaveCaseInFile )
             else:                    self.__executePythonScheme( SaveCaseInFile )
@@ -751,7 +752,7 @@ class Aidsm(object):
             for k in self.__adaoObject['AlgorithmParameters'].keys():
                 if k == "Algorithm": continue
                 if k in self.__StoredInputs:
-                    raise ValueError("the key \"%s\s to be transfered for pickling will overwrite an existing one.")
+                    raise ValueError("The key \"%s\" to be transfered for pickling will overwrite an existing one."%(k,))
                 if self.__adaoObject['AlgorithmParameters'].hasObserver( k ):
                     self.__adaoObject['AlgorithmParameters'].removeObserver( k, "", True )
                 self.__StoredInputs[k] = self.__adaoObject['AlgorithmParameters'].pop(k, None)
index 59a1b2b78068e5658b213d40cca0f841c936ce0f..c9f72028f075387bf3886ed3f9b2af76dd9d3d19 100644 (file)
@@ -607,6 +607,7 @@ class Algorithm(object):
         self._parameters = {"StoreSupplementaryCalculations":[]}
         self.__required_parameters = {}
         self.__required_inputs = {"RequiredInputValues":{"mandatory":(), "optional":()}}
+        self.__variable_names_not_public = {"nextStep":False} # Duplication dans AlgorithmAndParameters
         #
         self.StoredVariables = {}
         self.StoredVariables["APosterioriCorrelations"]              = Persistence.OneMatrix(name = "APosterioriCorrelations")
@@ -656,6 +657,9 @@ class Algorithm(object):
         # Mise a jour de self._parameters avec Parameters
         self.__setParameters(Parameters)
         #
+        for k, v in self.__variable_names_not_public.items():
+            if k not in self._parameters:  self.__setParameters( {k:v} )
+        #
         # Corrections et complements
         def __test_vvalue(argument, variable, argname):
             if argument is None:
@@ -890,6 +894,8 @@ class AlgorithmAndParameters(object):
             self.__P.update( {"Algorithm":self.__A} )
         #
         self.__setAlgorithm( self.__A )
+        #
+        self.__variable_names_not_public = {"nextStep":False} # Duplication dans Algorithm
 
     def updateParameters(self,
                  asDict     = None,
@@ -1005,7 +1011,9 @@ class AlgorithmAndParameters(object):
         elif key in self.__P:
             return self.__P[key]
         else:
-            return self.__P
+            allvariables = self.__P
+            for k in self.__variable_names_not_public: allvariables.pop(k, None)
+            return allvariables
 
     def pop(self, k, d):
         "Necessaire pour le pickling"
@@ -1052,7 +1060,10 @@ class AlgorithmAndParameters(object):
         return self.__algorithm.StoredVariables[ __V ].hasDataObserver()
 
     def keys(self):
-        return list(self.__algorithm.keys()) + list(self.__P.keys())
+        __allvariables = list(self.__algorithm.keys()) + list(self.__P.keys())
+        for k in self.__variable_names_not_public:
+            if k in __allvariables: __allvariables.remove(k)
+        return __allvariables
 
     def __contains__(self, key=None):
         "D.__contains__(k) -> True if D has a key k, else False"
index 8dfc2b83d2e941cb4d2fe989610df48a37c0cd76..e7313469823b1865499b06c9fb0b47561d648154 100644 (file)
@@ -122,8 +122,9 @@ class _TUIViewer(GenericCaseViewer):
                 if   k == "Stored"               and not __v: continue
                 if   k == "ColMajor"             and not __v: continue
                 if   k == "InputFunctionAsMulti" and not __v: continue
+                if   k == "nextStep"          and not __v: continue
                 if   k == "AvoidRC"              and     __v: continue
-                if   k == "noDetails":             continue
+                if   k == "noDetails":                        continue
                 if isinstance(__v,Persistence.Persistence): __v = __v.values()
                 if callable(__v): __text = self._missing%__v.__name__+__text
                 if isinstance(__v,dict):
@@ -393,7 +394,7 @@ class _SCDViewer(GenericCaseViewer):
                     __text += "%s_config['From'] = '%s'\n"%(__command,__f)
                     __text += "%s_config['Data'] = %s\n"%(__command,__v)
                     __text = __text.replace("''","'")
-                elif __k in ('Stored', 'Checked', 'ColMajor', 'InputFunctionAsMulti'):
+                elif __k in ('Stored', 'Checked', 'ColMajor', 'InputFunctionAsMulti', 'nextStep'):
                     if bool(__v):
                         __text += "%s_config['%s'] = '%s'\n"%(__command,__k,int(bool(__v)))
                 elif __k in ('AvoidRC', 'noDetails'):