From: Jean-Philippe ARGAUD Date: Sat, 23 Jan 2021 16:20:35 +0000 (+0100) Subject: Minor improvements for internal variables initialization (2) X-Git-Tag: V9_7_0b1~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8a674ff4a73b5fa03bcc1100f106a7642ca1297d;p=modules%2Fadao.git Minor improvements for internal variables initialization (2) --- diff --git a/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py b/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py index 6b35a9d..122b6e0 100644 --- a/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py +++ b/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py @@ -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 diff --git a/src/daComposant/daCore/NumericObjects.py b/src/daComposant/daCore/NumericObjects.py index fa72bb3..176f329 100644 --- a/src/daComposant/daCore/NumericObjects.py +++ b/src/daComposant/daCore/NumericObjects.py @@ -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,