Salome HOME
Improvement of EnKF algorithm and multifonction
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 6 Jan 2021 16:52:31 +0000 (17:52 +0100)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 6 Jan 2021 16:52:31 +0000 (17:52 +0100)
src/daComposant/daAlgorithms/EnsembleKalmanFilter.py
src/daComposant/daCore/BasicObjects.py
src/daComposant/daCore/NumericObjects.py

index 917134076003a8b934b1fa5bc626e45875b034fe..0da6ba867fca04b346f6f0f7c74d39601e5dc8d2 100644 (file)
@@ -35,7 +35,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
             message  = "Minimiseur utilisé",
             listval  = [
                 "StochasticEnKF",
-                "ETKF",
+                "ETKF",     # Default ETKF
                 "ETKF-KFF",
                 "ETKF-VAR",
                 ],
@@ -45,7 +45,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
             default  = 100,
             typecast = int,
             message  = "Nombre de membres dans l'ensemble",
-            minval   = -1,
+            minval   = 2,
             )
         self.defineRequiredParameter(
             name     = "EstimationOf",
@@ -157,8 +157,10 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         #
         if self._parameters["Minimizer"] == "StochasticEnKF":
             NumericObjects.senkf(self, Xb, Y, U, HO, EM, CM, R, B, Q)
-        elif self._parameters["Minimizer"] in ["ETKF", "ETKF-KFF"]:
+        #
+        elif self._parameters["Minimizer"] in ["ETKF-KFF", "ETKF"]:
             NumericObjects.etkf(self, Xb, Y, U, HO, EM, CM, R, B, Q, KorV="KalmanFilterFormula")
+        #
         elif self._parameters["Minimizer"] == "ETKF-VAR":
             NumericObjects.etkf(self, Xb, Y, U, HO, EM, CM, R, B, Q, KorV="Variational")
         else:
index 7a97326c1abce786782074a87b19ca50eaff9f61..74f9bfb07172c3108cbb21b833dbfdf91e0b391c 100644 (file)
@@ -266,28 +266,28 @@ class Operator(object):
         PlatformInfo.isIterable( _xuValue, True, " in Operator.appliedControledFormTo" )
         #
         if self.__Matrix is not None:
-            HxValue = []
+            _HxValue = []
             for paire in _xuValue:
                 _xValue, _uValue = paire
                 self.__addOneMatrixCall()
-                HxValue.append( self.__Matrix * _xValue )
+                _HxValue.append( self.__Matrix * _xValue )
         else:
-            HxValue = []
+            _HxValue = []
+            _xuArgs = []
             for paire in _xuValue:
-                _xuValue = []
                 _xValue, _uValue = paire
                 if _uValue is not None:
-                    _xuValue.append( paire )
+                    _xuArgs.append( paire )
                 else:
-                    _xuValue.append( _xValue )
-            self.__addOneMethodCall( len(_xuValue) )
+                    _xuArgs.append( _xValue )
+            self.__addOneMethodCall( len(_xuArgs) )
             if self.__extraArgs is None:
-                HxValue = self.__Method( _xuValue ) # Calcul MF
+                _HxValue = self.__Method( _xuArgs ) # Calcul MF
             else:
-                HxValue = self.__Method( _xuValue, self.__extraArgs ) # Calcul MF
+                _HxValue = self.__Method( _xuArgs, self.__extraArgs ) # Calcul MF
         #
-        if argsAsSerie: return HxValue
-        else:           return HxValue[-1]
+        if argsAsSerie: return _HxValue
+        else:           return _HxValue[-1]
 
     def appliedInXTo(self, paires, argsAsSerie = False):
         """
index 208e736149269847378afdacd37c20a30bd865aa..5f59d11bc3cc2fe000e1716efbf839bfc34327f1 100644 (file)
@@ -880,18 +880,22 @@ def etkf(selfA, Xb, Y, U, HO, EM, CM, R, B, Q, KorV="KalmanFilterFormula"):
                 )
         #
         if selfA._parameters["EstimationOf"] == "State": # Forecast + Q and observation of forecast
+            EMX = M( [(Xn[:,i], Un) for i in range(__m)], argsAsSerie = True )
             for i in range(__m):
                 qi = numpy.asmatrix(numpy.random.multivariate_normal(numpy.zeros(__n), Qn, (1,1,1))).T
-                Xn_predicted[:,i] = numpy.asmatrix(numpy.ravel( M((Xn[:,i], Un)) )).T + qi
-                HX_predicted[:,i] = numpy.asmatrix(numpy.ravel( H((Xn_predicted[:,i], Un)) )).T
+                Xn_predicted[:,i] = numpy.asmatrix(numpy.ravel( EMX[i] )).T + qi
+            EHX = H( [(Xn_predicted[:,i], Un) for i in range(__m)], argsAsSerie = True )
+            for i in range(__m):
+                HX_predicted[:,i] = numpy.asmatrix(numpy.ravel( EHX[i] )).T
             if Cm is not None and Un is not None: # Attention : si Cm est aussi dans M, doublon !
                 Cm = Cm.reshape(__n,Un.size) # ADAO & check shape
                 Xn_predicted = Xn_predicted + Cm * Un
         elif selfA._parameters["EstimationOf"] == "Parameters": # Observation of forecast
             # --- > Par principe, M = Id, Q = 0
             Xn_predicted = Xn
+            EHX = H( [(Xn_predicted[:,i], Un) for i in range(__m)], argsAsSerie = True )
             for i in range(__m):
-                HX_predicted[:,i] = numpy.asmatrix(numpy.ravel( H((Xn_predicted[:,i], Un)) )).T
+                HX_predicted[:,i] = numpy.asmatrix(numpy.ravel( EHX[i] )).T
         #
         # Mean of forecast and observation of forecast
         Xfm  = Xn_predicted.mean(axis=1, dtype=mfp).astype('float')