From 83162a362512da56b2d56c0408e8000d4128237a Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Sun, 10 Jan 2021 14:16:39 +0100 Subject: [PATCH] Minor corrections of internal variables --- .../daAlgorithms/EnsembleKalmanFilter.py | 9 +++- src/daComposant/daCore/BasicObjects.py | 44 +++++++++++-------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py b/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py index be85553..ead0c30 100644 --- a/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py +++ b/src/daComposant/daAlgorithms/EnsembleKalmanFilter.py @@ -35,10 +35,10 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): message = "Minimiseur utilisé", listval = [ "StochasticEnKF", - "ETKF", # Default ETKF + "ETKF", "ETKF-KFF", "ETKF-VAR", - "ETKF-N", # Default ETKF-N + "ETKF-N", "ETKF-N-11", "ETKF-N-15", "ETKF-N-16", @@ -159,15 +159,20 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None): self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q) # + #-------------------------- if self._parameters["Minimizer"] == "StochasticEnKF": NumericObjects.senkf(self, Xb, Y, U, HO, EM, CM, R, B, Q) # + #-------------------------- + # Default 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") # + #-------------------------- + # Default ETKF-N = ETKF-N-16 elif self._parameters["Minimizer"] == "ETKF-N-11": NumericObjects.etkf(self, Xb, Y, U, HO, EM, CM, R, B, Q, KorV="FiniteSize11") # diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 74f9bfb..7aaf176 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -179,7 +179,7 @@ class Operator(object): "Renvoie le type" return self.__Type - def appliedTo(self, xValue, HValue = None, argsAsSerie = False): + def appliedTo(self, xValue, HValue = None, argsAsSerie = False, returnSerieAsArrayMatrix = False): """ Permet de restituer le résultat de l'application de l'opérateur à une série d'arguments xValue. Cette méthode se contente d'appliquer, chaque @@ -203,13 +203,13 @@ class Operator(object): # if _HValue is not None: assert len(_xValue) == len(_HValue), "Incompatible number of elements in xValue and HValue" - HxValue = [] + _HxValue = [] for i in range(len(_HValue)): - HxValue.append( numpy.asmatrix( numpy.ravel( _HValue[i] ) ).T ) + _HxValue.append( numpy.asmatrix( numpy.ravel( _HValue[i] ) ).T ) if self.__AvoidRC: - Operator.CM.storeValueInX(_xValue[i],HxValue[-1],self.__name) + Operator.CM.storeValueInX(_xValue[i],_HxValue[-1],self.__name) else: - HxValue = [] + _HxValue = [] _xserie = [] _hindex = [] for i, xv in enumerate(_xValue): @@ -230,7 +230,7 @@ class Operator(object): _xserie.append( xv ) _hindex.append( i ) _hv = None - HxValue.append( _hv ) + _HxValue.append( _hv ) # if len(_xserie)>0 and self.__Matrix is None: if self.__extraArgs is None: @@ -242,14 +242,17 @@ class Operator(object): for i in _hindex: _xv = _xserie.pop(0) _hv = _hserie.pop(0) - HxValue[i] = _hv + _HxValue[i] = _hv if self.__AvoidRC: Operator.CM.storeValueInX(_xv,_hv,self.__name) # - if argsAsSerie: return HxValue - else: return HxValue[-1] + if returnSerieAsArrayMatrix: + _HxValue = numpy.stack([numpy.ravel(_hv) for _hv in _HxValue], axis=1) + # + if argsAsSerie: return _HxValue + else: return _HxValue[-1] - def appliedControledFormTo(self, paires, argsAsSerie = False): + def appliedControledFormTo(self, paires, argsAsSerie = False, returnSerieAsArrayMatrix = False): """ Permet de restituer le résultat de l'application de l'opérateur à des paires (xValue, uValue). Cette méthode se contente d'appliquer, son @@ -272,7 +275,6 @@ class Operator(object): self.__addOneMatrixCall() _HxValue.append( self.__Matrix * _xValue ) else: - _HxValue = [] _xuArgs = [] for paire in _xuValue: _xValue, _uValue = paire @@ -286,10 +288,13 @@ class Operator(object): else: _HxValue = self.__Method( _xuArgs, self.__extraArgs ) # Calcul MF # + if returnSerieAsArrayMatrix: + _HxValue = numpy.stack([numpy.ravel(_hv) for _hv in _HxValue], axis=1) + # if argsAsSerie: return _HxValue else: return _HxValue[-1] - def appliedInXTo(self, paires, argsAsSerie = False): + def appliedInXTo(self, paires, argsAsSerie = False, returnSerieAsArrayMatrix = False): """ Permet de restituer le résultat de l'application de l'opérateur à une série d'arguments xValue, sachant que l'opérateur est valable en @@ -310,20 +315,23 @@ class Operator(object): PlatformInfo.isIterable( _nxValue, True, " in Operator.appliedInXTo" ) # if self.__Matrix is not None: - HxValue = [] + _HxValue = [] for paire in _nxValue: _xNominal, _xValue = paire self.__addOneMatrixCall() - HxValue.append( self.__Matrix * _xValue ) + _HxValue.append( self.__Matrix * _xValue ) else: self.__addOneMethodCall( len(_nxValue) ) if self.__extraArgs is None: - HxValue = self.__Method( _nxValue ) # Calcul MF + _HxValue = self.__Method( _nxValue ) # Calcul MF else: - HxValue = self.__Method( _nxValue, self.__extraArgs ) # Calcul MF + _HxValue = self.__Method( _nxValue, self.__extraArgs ) # Calcul MF # - if argsAsSerie: return HxValue - else: return HxValue[-1] + if returnSerieAsArrayMatrix: + _HxValue = numpy.stack([numpy.ravel(_hv) for _hv in _HxValue], axis=1) + # + if argsAsSerie: return _HxValue + else: return _HxValue[-1] def asMatrix(self, ValueForMethodForm = "UnknownVoidValue", argsAsSerie = False): """ -- 2.39.2