]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Minor improvements for internal variables initialization (2)
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Sat, 23 Jan 2021 16:20:35 +0000 (17:20 +0100)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Sat, 23 Jan 2021 16:20:35 +0000 (17:20 +0100)
src/daComposant/daAlgorithms/EnsembleKalmanFilter.py
src/daComposant/daCore/NumericObjects.py

index 6b35a9d357c1f86c3def473253e35d7dbdf571cc..122b6e02ff78bd2081acc547b7c24f478aec2d3d 100644 (file)
@@ -167,7 +167,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm):
         #--------------------------
         # Default EnKF = StochasticEnKF
         if self._parameters["Minimizer"] in ["StochasticEnKF", "EnKF"]:
-            NumericObjects.senkf(self, Xb, Y, U, HO, EM, CM, R, B, Q)
+            NumericObjects.senkf(self, Xb, Y, U, HO, EM, CM, R, B, Q, VariantM="KalmanFilterFormula")
         #
         #--------------------------
         # Default ETKF = ETKF-KFF
index fa72bb35acc690e4036c972818fb517a85b549b9..176f329952176f8119b514210d27a8378eeec2e4 100644 (file)
@@ -626,7 +626,7 @@ def CovarianceInflation(
     return OutputCovOrEns
 
 # ==============================================================================
-def senkf(selfA, Xb, Y, U, HO, EM, CM, R, B, Q):
+def senkf(selfA, Xb, Y, U, HO, EM, CM, R, B, Q, VariantM="KalmanFilterFormula"):
     """
     Stochastic EnKF (Envensen 1994, Burgers 1998)
 
@@ -736,20 +736,25 @@ def senkf(selfA, Xb, Y, U, HO, EM, CM, R, B, Q):
         Xfm  = Xn_predicted.mean(axis=1, dtype=mfp).astype('float')
         Hfm  = HX_predicted.mean(axis=1, dtype=mfp).astype('float')
         #
-        PfHT, HPfHT = 0., 0.
-        for i in range(__m):
-            Exfi = Xn_predicted[:,i] - Xfm.reshape((__n,-1))
-            Eyfi = (HX_predicted[:,i] - Hfm).reshape((__p,1))
-            PfHT  += Exfi * Eyfi.T
-            HPfHT += Eyfi * Eyfi.T
-        PfHT  = (1./(__m-1)) * PfHT
-        HPfHT = (1./(__m-1)) * HPfHT
-        K     = PfHT * ( R + HPfHT ).I
-        del PfHT, HPfHT
-        #
-        for i in range(__m):
-            ri = numpy.random.multivariate_normal(numpy.zeros(__p), Rn)
-            Xn[:,i] = Xn_predicted[:,i] + K @ (numpy.ravel(Ynpu) + ri - HX_predicted[:,i]).reshape((__p,1))
+        #--------------------------
+        if VariantM == "KalmanFilterFormula":
+            PfHT, HPfHT = 0., 0.
+            for i in range(__m):
+                Exfi = Xn_predicted[:,i] - Xfm.reshape((__n,-1))
+                Eyfi = (HX_predicted[:,i] - Hfm).reshape((__p,1))
+                PfHT  += Exfi * Eyfi.T
+                HPfHT += Eyfi * Eyfi.T
+            PfHT  = (1./(__m-1)) * PfHT
+            HPfHT = (1./(__m-1)) * HPfHT
+            K     = PfHT * ( R + HPfHT ).I
+            del PfHT, HPfHT
+            #
+            for i in range(__m):
+                ri = numpy.random.multivariate_normal(numpy.zeros(__p), Rn)
+                Xn[:,i] = Xn_predicted[:,i] + K @ (numpy.ravel(Ynpu) + ri - HX_predicted[:,i]).reshape((__p,1))
+        #--------------------------
+        else:
+            raise ValueError("VariantM has to be chosen in the authorized methods list.")
         #
         if selfA._parameters["InflationType"] == "MultiplicativeOnAnalysisAnomalies":
             Xn = CovarianceInflation( Xn,