From 7a8cfbbec24848ede9bca76958887e6dcf9a8d28 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Sun, 24 Mar 2019 14:57:44 +0100 Subject: [PATCH] Improvement of conditional variables output for filters --- .../daAlgorithms/EnsembleKalmanFilter.py | 109 ++++++++++++------ .../daAlgorithms/ExtendedKalmanFilter.py | 97 +++++++++++----- src/daComposant/daAlgorithms/KalmanFilter.py | 97 +++++++++++----- .../daAlgorithms/UnscentedKalmanFilter.py | 21 ++-- 4 files changed, 216 insertions(+), 108 deletions(-) diff --git a/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py b/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py index 8563d69..4a84493 100644 --- a/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py +++ b/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py @@ -60,16 +60,25 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", listval = [ + "Analysis", "APosterioriCorrelations", "APosterioriCovariance", "APosterioriStandardDeviations", "APosterioriVariances", "BMA", "CostFunctionJ", + "CostFunctionJAtCurrentOptimum", "CostFunctionJb", + "CostFunctionJbAtCurrentOptimum", "CostFunctionJo", + "CostFunctionJoAtCurrentOptimum", + "CurrentOptimum", "CurrentState", - "Innovation", + "IndexOfOptimum", + "InnovationAtCurrentState", + "PredictedState", + "SimulatedObservationAtCurrentOptimum", + "SimulatedObservationAtCurrentState", ] ) self.requireInputArguments( @@ -106,11 +115,11 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # # Précalcul des inversions de B et R # ---------------------------------- - if self._parameters["StoreInternalVariables"] or \ - self._toStore("CostFunctionJ") or \ - self._toStore("CostFunctionJb") or \ - self._toStore("CostFunctionJo") or \ - self._toStore("APosterioriCovariance"): + if self._parameters["StoreInternalVariables"] \ + or self._toStore("CostFunctionJ") \ + or self._toStore("CostFunctionJb") \ + or self._toStore("CostFunctionJo") \ + or self._toStore("APosterioriCovariance"): BI = B.getI() RI = R.getI() BIdemi = B.choleskyI() @@ -188,33 +197,65 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # for i in range(__m): Xn[:,i] = Xn_predicted[:,i] + K * (Yo[:,i] - HX_predicted[:,i]) + del Yo, PfHT, HPfHT # Xa = Xn.mean(axis=1, dtype=mfp) - self.StoredVariables["Analysis"].store( Xa ) # - del Yo, PfHT, HPfHT - if self._parameters["StoreInternalVariables"] or \ - self._toStore("CostFunctionJ") or \ - self._toStore("CostFunctionJb") or \ - self._toStore("CostFunctionJo") or \ - self._toStore("APosterioriCovariance") or \ - self._toStore("Innovation"): - d = Ynpu - numpy.asmatrix(numpy.ravel( H((Xa, Un)) )).T - self.StoredVariables["Innovation"].store( d ) if self._parameters["StoreInternalVariables"] \ - or self._toStore("CurrentState"): - self.StoredVariables["CurrentState"].store( Xn ) - if self._parameters["StoreInternalVariables"] or \ - self._toStore("CostFunctionJ") or \ - self._toStore("CostFunctionJb") or \ - self._toStore("CostFunctionJo") or \ - self._toStore("APosterioriCovariance"): - Jb = 0.5 * (Xa - Xb).T * BI * (Xa - Xb) - Jo = 0.5 * d.T * RI * d - J = float( Jb ) + float( Jo ) + or self._toStore("CostFunctionJ") \ + or self._toStore("CostFunctionJb") \ + or self._toStore("CostFunctionJo") \ + or self._toStore("APosterioriCovariance") \ + or self._toStore("InnovationAtCurrentState") \ + or self._toStore("SimulatedObservationAtCurrentState") \ + or self._toStore("SimulatedObservationAtCurrentOptimum"): + _HX = numpy.asmatrix(numpy.ravel( H((Xa, Un)) )).T + _Innovation = Ynpu - _HX + # + self.StoredVariables["Analysis"].store( Xa ) + if self._parameters["StoreInternalVariables"] \ + or self._toStore("CurrentState") \ + or self._toStore("CurrentOptimum"): + self.StoredVariables["CurrentState"].store( Xa ) + if self._toStore("BMA"): + self.StoredVariables["BMA"].store( Xn_predicted - Xa ) + if self._toStore("InnovationAtCurrentState"): + self.StoredVariables["InnovationAtCurrentState"].store( _Innovation ) + if self._toStore("SimulatedObservationAtCurrentState") \ + or self._toStore("SimulatedObservationAtCurrentOptimum"): + self.StoredVariables["SimulatedObservationAtCurrentState"].store( _HX ) + if self._parameters["StoreInternalVariables"] \ + or self._toStore("CostFunctionJ") \ + or self._toStore("CostFunctionJb") \ + or self._toStore("CostFunctionJo") \ + or self._toStore("CurrentOptimum") \ + or self._toStore("APosterioriCovariance"): + Jb = float( 0.5 * (Xa - Xb).T * BI * (Xa - Xb) ) + Jo = float( 0.5 * _Innovation.T * RI * _Innovation ) + J = Jb + Jo self.StoredVariables["CostFunctionJb"].store( Jb ) self.StoredVariables["CostFunctionJo"].store( Jo ) self.StoredVariables["CostFunctionJ" ].store( J ) + # + if self._toStore("IndexOfOptimum") \ + or self._toStore("CurrentOptimum") \ + or self._toStore("CostFunctionJAtCurrentOptimum") \ + or self._toStore("CostFunctionJbAtCurrentOptimum") \ + or self._toStore("CostFunctionJoAtCurrentOptimum") \ + or self._toStore("SimulatedObservationAtCurrentOptimum"): + IndexMin = numpy.argmin( self.StoredVariables["CostFunctionJ"][nbPreviousSteps:] ) + nbPreviousSteps + if self._toStore("IndexOfOptimum"): + self.StoredVariables["IndexOfOptimum"].store( IndexMin ) + if self._toStore("CurrentOptimum"): + self.StoredVariables["CurrentOptimum"].store( self.StoredVariables["CurrentState"][IndexMin] ) + if self._toStore("SimulatedObservationAtCurrentOptimum"): + self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( self.StoredVariables["SimulatedObservationAtCurrentState"][IndexMin] ) + if self._toStore("CostFunctionJbAtCurrentOptimum"): + self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJb"][IndexMin] ) + if self._toStore("CostFunctionJoAtCurrentOptimum"): + self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJo"][IndexMin] ) + if self._toStore("CostFunctionJAtCurrentOptimum"): + self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) if self._toStore("APosterioriCovariance"): Ht = HO["Tangent"].asMatrix(ValueForMethodForm = Xa) Ht = Ht.reshape(__p,__n) # ADAO & check shape @@ -224,20 +265,20 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): Pf = (1./(__m-1)) * Pf Pn = (1. - K * Ht) * Pf self.StoredVariables["APosterioriCovariance"].store( Pn ) - if J < previousJMinimum: + if self._parameters["EstimationOf"] == "Parameters" \ + and J < previousJMinimum: previousJMinimum = J - Xa = Xn - covarianceXa = Pn + # Inutile ici : Xa = Xa + covarianceXa = Pn # - # Stockage supplementaire de l'optimum en estimation de parametres - # ---------------------------------------------------------------- + # Stockage final supplémentaire de l'optimum en estimation de paramètres + # ---------------------------------------------------------------------- if self._parameters["EstimationOf"] == "Parameters": self.StoredVariables["Analysis"].store( Xa.A1 ) if self._toStore("APosterioriCovariance"): self.StoredVariables["APosterioriCovariance"].store( covarianceXa ) - # - if self._toStore("BMA"): - self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) + if self._toStore("BMA"): + self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) # self._post_run(HO) return 0 diff --git a/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py b/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py index 6454610..5670a6b 100644 --- a/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py +++ b/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py @@ -54,17 +54,25 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", listval = [ + "Analysis", "APosterioriCorrelations", "APosterioriCovariance", "APosterioriStandardDeviations", "APosterioriVariances", "BMA", - "CurrentState", "CostFunctionJ", + "CostFunctionJAtCurrentOptimum", "CostFunctionJb", + "CostFunctionJbAtCurrentOptimum", "CostFunctionJo", - "Innovation", + "CostFunctionJoAtCurrentOptimum", + "CurrentOptimum", + "CurrentState", + "IndexOfOptimum", + "InnovationAtCurrentState", "PredictedState", + "SimulatedObservationAtCurrentOptimum", + "SimulatedObservationAtCurrentState", ] ) self.defineRequiredParameter( # Pas de type @@ -72,7 +80,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): message = "Liste des valeurs de bornes", ) self.requireInputArguments( - mandatory= ("Xb", "Y", "HO", "R", "B" ), + mandatory= ("Xb", "Y", "HO", "R", "B"), optional = ("U", "EM", "CM", "Q"), ) @@ -106,7 +114,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if self._parameters["StoreInternalVariables"] \ or self._toStore("CostFunctionJ") \ or self._toStore("CostFunctionJb") \ - or self._toStore("CostFunctionJo"): + or self._toStore("CostFunctionJo") \ + or self._toStore("CurrentOptimum") \ + or self._toStore("APosterioriCovariance"): BI = B.getI() RI = R.getI() # @@ -165,57 +175,82 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): Xn_predicted = numpy.min(numpy.hstack((Xn_predicted,numpy.asmatrix(self._parameters["Bounds"])[:,1])),axis=1) # if self._parameters["EstimationOf"] == "State": - d = Ynpu - numpy.asmatrix(numpy.ravel( Hm( (Xn_predicted, None) ) )).T + _HX = numpy.asmatrix(numpy.ravel( Hm( (Xn_predicted, None) ) )).T + _Innovation = Ynpu - _HX elif self._parameters["EstimationOf"] == "Parameters": - d = Ynpu - numpy.asmatrix(numpy.ravel( Hm( (Xn_predicted, Un) ) )).T + _HX = numpy.asmatrix(numpy.ravel( Hm( (Xn_predicted, Un) ) )).T + _Innovation = Ynpu - _HX if Cm is not None and Un is not None: # Attention : si Cm est aussi dans H, doublon ! - d = d - Cm * Un + _Innovation = _Innovation - Cm * Un # _A = R + numpy.dot(Ht, Pn_predicted * Ha) - _u = numpy.linalg.solve( _A , d ) + _u = numpy.linalg.solve( _A , _Innovation ) Xn = Xn_predicted + Pn_predicted * Ha * _u Kn = Pn_predicted * Ha * (R + numpy.dot(Ht, Pn_predicted * Ha)).I Pn = Pn_predicted - Kn * Ht * Pn_predicted # - self.StoredVariables["Analysis"].store( Xn.A1 ) - if self._toStore("APosterioriCovariance"): - self.StoredVariables["APosterioriCovariance"].store( Pn ) - if self._toStore("Innovation"): - self.StoredVariables["Innovation"].store( numpy.ravel( d.A1 ) ) + self.StoredVariables["Analysis"].store( Xn ) if self._parameters["StoreInternalVariables"] \ - or self._toStore("CurrentState"): + or self._toStore("CurrentState") \ + or self._toStore("CurrentOptimum"): self.StoredVariables["CurrentState"].store( Xn ) - if self._parameters["StoreInternalVariables"] \ - or self._toStore("PredictedState"): + if self._toStore("PredictedState"): self.StoredVariables["PredictedState"].store( Xn_predicted ) + if self._toStore("BMA"): + self.StoredVariables["BMA"].store( Xn_predicted - Xn ) + if self._toStore("InnovationAtCurrentState"): + self.StoredVariables["InnovationAtCurrentState"].store( _Innovation ) + if self._toStore("SimulatedObservationAtCurrentState") \ + or self._toStore("SimulatedObservationAtCurrentOptimum"): + self.StoredVariables["SimulatedObservationAtCurrentState"].store( _HX ) if self._parameters["StoreInternalVariables"] \ or self._toStore("CostFunctionJ") \ or self._toStore("CostFunctionJb") \ - or self._toStore("CostFunctionJo"): - Jb = 0.5 * (Xn - Xb).T * BI * (Xn - Xb) - Jo = 0.5 * d.T * RI * d - J = float( Jb ) + float( Jo ) + or self._toStore("CostFunctionJo") \ + or self._toStore("CurrentOptimum") \ + or self._toStore("APosterioriCovariance"): + Jb = float( 0.5 * (Xn - Xb).T * BI * (Xn - Xb) ) + Jo = float( 0.5 * _Innovation.T * RI * _Innovation ) + J = Jb + Jo self.StoredVariables["CostFunctionJb"].store( Jb ) self.StoredVariables["CostFunctionJo"].store( Jo ) self.StoredVariables["CostFunctionJ" ].store( J ) - if J < previousJMinimum: + if self._parameters["EstimationOf"] == "Parameters" \ + and J < previousJMinimum: previousJMinimum = J Xa = Xn - if self._toStore("APosterioriCovariance"): - covarianceXa = Pn - else: - Xa = Xn - # + if self._toStore("APosterioriCovariance"): covarianceXa = Pn + # + if self._toStore("IndexOfOptimum") \ + or self._toStore("CurrentOptimum") \ + or self._toStore("CostFunctionJAtCurrentOptimum") \ + or self._toStore("CostFunctionJbAtCurrentOptimum") \ + or self._toStore("CostFunctionJoAtCurrentOptimum") \ + or self._toStore("SimulatedObservationAtCurrentOptimum"): + IndexMin = numpy.argmin( self.StoredVariables["CostFunctionJ"][nbPreviousSteps:] ) + nbPreviousSteps + if self._toStore("IndexOfOptimum"): + self.StoredVariables["IndexOfOptimum"].store( IndexMin ) + if self._toStore("CurrentOptimum"): + self.StoredVariables["CurrentOptimum"].store( self.StoredVariables["CurrentState"][IndexMin] ) + if self._toStore("SimulatedObservationAtCurrentOptimum"): + self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( self.StoredVariables["SimulatedObservationAtCurrentState"][IndexMin] ) + if self._toStore("CostFunctionJbAtCurrentOptimum"): + self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJb"][IndexMin] ) + if self._toStore("CostFunctionJoAtCurrentOptimum"): + self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJo"][IndexMin] ) + if self._toStore("CostFunctionJAtCurrentOptimum"): + self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) + if self._toStore("APosterioriCovariance"): + self.StoredVariables["APosterioriCovariance"].store( Pn ) # - # Stockage supplementaire de l'optimum en estimation de parametres - # ---------------------------------------------------------------- + # Stockage final supplémentaire de l'optimum en estimation de paramètres + # ---------------------------------------------------------------------- if self._parameters["EstimationOf"] == "Parameters": self.StoredVariables["Analysis"].store( Xa.A1 ) if self._toStore("APosterioriCovariance"): self.StoredVariables["APosterioriCovariance"].store( covarianceXa ) - # - if self._toStore("BMA"): - self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) + if self._toStore("BMA"): + self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) # self._post_run(HO) return 0 diff --git a/src/daComposant/daAlgorithms/KalmanFilter.py b/src/daComposant/daAlgorithms/KalmanFilter.py index bfb5205..e8115b4 100644 --- a/src/daComposant/daAlgorithms/KalmanFilter.py +++ b/src/daComposant/daAlgorithms/KalmanFilter.py @@ -47,21 +47,29 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", listval = [ + "Analysis", "APosterioriCorrelations", "APosterioriCovariance", "APosterioriStandardDeviations", "APosterioriVariances", "BMA", - "CurrentState", "CostFunctionJ", + "CostFunctionJAtCurrentOptimum", "CostFunctionJb", + "CostFunctionJbAtCurrentOptimum", "CostFunctionJo", - "Innovation", + "CostFunctionJoAtCurrentOptimum", + "CurrentOptimum", + "CurrentState", + "IndexOfOptimum", + "InnovationAtCurrentState", "PredictedState", + "SimulatedObservationAtCurrentOptimum", + "SimulatedObservationAtCurrentState", ] ) self.requireInputArguments( - mandatory= ("Xb", "Y", "HO", "R", "B" ), + mandatory= ("Xb", "Y", "HO", "R", "B"), optional = ("U", "EM", "CM", "Q"), ) @@ -97,7 +105,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if self._parameters["StoreInternalVariables"] \ or self._toStore("CostFunctionJ") \ or self._toStore("CostFunctionJb") \ - or self._toStore("CostFunctionJo"): + or self._toStore("CostFunctionJo") \ + or self._toStore("CurrentOptimum") \ + or self._toStore("APosterioriCovariance"): BI = B.getI() RI = R.getI() # @@ -141,57 +151,82 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): Pn_predicted = Pn # if self._parameters["EstimationOf"] == "State": - d = Ynpu - Ht * Xn_predicted + _HX = Ht * Xn_predicted + _Innovation = Ynpu - _HX elif self._parameters["EstimationOf"] == "Parameters": - d = Ynpu - Ht * Xn_predicted + _HX = Ht * Xn_predicted + _Innovation = Ynpu - _HX if Cm is not None and Un is not None: # Attention : si Cm est aussi dans H, doublon ! - d = d - Cm * Un + _Innovation = _Innovation - Cm * Un # _A = R + numpy.dot(Ht, Pn_predicted * Ha) - _u = numpy.linalg.solve( _A , d ) + _u = numpy.linalg.solve( _A , _Innovation ) Xn = Xn_predicted + Pn_predicted * Ha * _u Kn = Pn_predicted * Ha * (R + numpy.dot(Ht, Pn_predicted * Ha)).I Pn = Pn_predicted - Kn * Ht * Pn_predicted # - self.StoredVariables["Analysis"].store( Xn.A1 ) - if self._toStore("APosterioriCovariance"): - self.StoredVariables["APosterioriCovariance"].store( Pn ) - if self._toStore("Innovation"): - self.StoredVariables["Innovation"].store( numpy.ravel( d.A1 ) ) + self.StoredVariables["Analysis"].store( Xn ) if self._parameters["StoreInternalVariables"] \ - or self._toStore("CurrentState"): + or self._toStore("CurrentState") \ + or self._toStore("CurrentOptimum"): self.StoredVariables["CurrentState"].store( Xn ) - if self._parameters["StoreInternalVariables"] \ - or self._toStore("PredictedState"): + if self._toStore("PredictedState"): self.StoredVariables["PredictedState"].store( Xn_predicted ) + if self._toStore("BMA"): + self.StoredVariables["BMA"].store( Xn_predicted - Xn ) + if self._toStore("InnovationAtCurrentState"): + self.StoredVariables["InnovationAtCurrentState"].store( _Innovation ) + if self._toStore("SimulatedObservationAtCurrentState") \ + or self._toStore("SimulatedObservationAtCurrentOptimum"): + self.StoredVariables["SimulatedObservationAtCurrentState"].store( _HX ) if self._parameters["StoreInternalVariables"] \ or self._toStore("CostFunctionJ") \ or self._toStore("CostFunctionJb") \ - or self._toStore("CostFunctionJo"): - Jb = 0.5 * (Xn - Xb).T * BI * (Xn - Xb) - Jo = 0.5 * d.T * RI * d - J = float( Jb ) + float( Jo ) + or self._toStore("CostFunctionJo") \ + or self._toStore("CurrentOptimum") \ + or self._toStore("APosterioriCovariance"): + Jb = float( 0.5 * (Xn - Xb).T * BI * (Xn - Xb) ) + Jo = float( 0.5 * _Innovation.T * RI * _Innovation ) + J = Jb + Jo self.StoredVariables["CostFunctionJb"].store( Jb ) self.StoredVariables["CostFunctionJo"].store( Jo ) self.StoredVariables["CostFunctionJ" ].store( J ) - if J < previousJMinimum: + if self._parameters["EstimationOf"] == "Parameters" \ + and J < previousJMinimum: previousJMinimum = J Xa = Xn - if self._toStore("APosterioriCovariance"): - covarianceXa = Pn - else: - Xa = Xn - # + if self._toStore("APosterioriCovariance"): covarianceXa = Pn + # + if self._toStore("IndexOfOptimum") \ + or self._toStore("CurrentOptimum") \ + or self._toStore("CostFunctionJAtCurrentOptimum") \ + or self._toStore("CostFunctionJbAtCurrentOptimum") \ + or self._toStore("CostFunctionJoAtCurrentOptimum") \ + or self._toStore("SimulatedObservationAtCurrentOptimum"): + IndexMin = numpy.argmin( self.StoredVariables["CostFunctionJ"][nbPreviousSteps:] ) + nbPreviousSteps + if self._toStore("IndexOfOptimum"): + self.StoredVariables["IndexOfOptimum"].store( IndexMin ) + if self._toStore("CurrentOptimum"): + self.StoredVariables["CurrentOptimum"].store( self.StoredVariables["CurrentState"][IndexMin] ) + if self._toStore("SimulatedObservationAtCurrentOptimum"): + self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( self.StoredVariables["SimulatedObservationAtCurrentState"][IndexMin] ) + if self._toStore("CostFunctionJbAtCurrentOptimum"): + self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJb"][IndexMin] ) + if self._toStore("CostFunctionJoAtCurrentOptimum"): + self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJo"][IndexMin] ) + if self._toStore("CostFunctionJAtCurrentOptimum"): + self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) + if self._toStore("APosterioriCovariance"): + self.StoredVariables["APosterioriCovariance"].store( Pn ) # - # Stockage supplementaire de l'optimum en estimation de parametres - # ---------------------------------------------------------------- + # Stockage final supplémentaire de l'optimum en estimation de paramètres + # ---------------------------------------------------------------------- if self._parameters["EstimationOf"] == "Parameters": self.StoredVariables["Analysis"].store( Xa.A1 ) if self._toStore("APosterioriCovariance"): self.StoredVariables["APosterioriCovariance"].store( covarianceXa ) - # - if self._toStore("BMA"): - self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) + if self._toStore("BMA"): + self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) # self._post_run(HO) return 0 diff --git a/src/daComposant/daAlgorithms/UnscentedKalmanFilter.py b/src/daComposant/daAlgorithms/UnscentedKalmanFilter.py index 5f078cc..bb3da55 100644 --- a/src/daComposant/daAlgorithms/UnscentedKalmanFilter.py +++ b/src/daComposant/daAlgorithms/UnscentedKalmanFilter.py @@ -83,16 +83,17 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", listval = [ + "Analysis", "APosterioriCorrelations", "APosterioriCovariance", "APosterioriStandardDeviations", "APosterioriVariances", "BMA", - "CurrentState", "CostFunctionJ", "CostFunctionJb", "CostFunctionJo", - "Innovation", + "CurrentState", + "InnovationAtCurrentState", ] ) self.defineRequiredParameter( # Pas de type @@ -164,10 +165,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # Initialisation # -------------- Xn = Xb - if hasattr(B,"asfullmatrix"): - Pn = B.asfullmatrix(Xn.size) - else: - Pn = B + if hasattr(B,"asfullmatrix"): Pn = B.asfullmatrix(Xn.size) + else: Pn = B # self.StoredVariables["Analysis"].store( Xn.A1 ) if self._toStore("APosterioriCovariance"): @@ -273,8 +272,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self.StoredVariables["Analysis"].store( Xn.A1 ) if self._toStore("APosterioriCovariance"): self.StoredVariables["APosterioriCovariance"].store( Pn ) - if self._toStore("Innovation"): - self.StoredVariables["Innovation"].store( numpy.ravel( d.A1 ) ) + if self._toStore("InnovationAtCurrentState"): + self.StoredVariables["InnovationAtCurrentState"].store( numpy.ravel( d.A1 ) ) if self._parameters["StoreInternalVariables"] \ or self._toStore("CurrentState"): self.StoredVariables["CurrentState"].store( Xn ) @@ -295,7 +294,6 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): covarianceXa = Pn else: Xa = Xn - # # # Stockage supplementaire de l'optimum en estimation de parametres # ---------------------------------------------------------------- @@ -303,9 +301,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self.StoredVariables["Analysis"].store( Xa.A1 ) if self._toStore("APosterioriCovariance"): self.StoredVariables["APosterioriCovariance"].store( covarianceXa ) - # - if self._toStore("BMA"): - self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) + if self._toStore("BMA"): + self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) # self._post_run(HO) return 0 -- 2.39.2