From: Jean-Philippe ARGAUD Date: Thu, 13 Apr 2017 17:13:58 +0000 (+0200) Subject: Minor corrections for variables handling X-Git-Tag: V8_3_0rc1~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=579800a330ac05e9aa5845a8dc1cb0729979f7ac;p=modules%2Fadao.git Minor corrections for variables handling --- diff --git a/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py b/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py index 0fbd0db..621cf51 100644 --- a/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py +++ b/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py @@ -168,12 +168,15 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self.StoredVariables["APosterioriCovariance"].store( Pn ) if "Innovation" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["Innovation"].store( numpy.ravel( d.A1 ) ) - if self._parameters["StoreInternalVariables"]: + if self._parameters["StoreInternalVariables"] or "CurrentState" in self._parameters["StoreSupplementaryCalculations"]: + self.StoredVariables["CurrentState"].store( Xn ) + if self._parameters["StoreInternalVariables"] \ + or "CostFunctionJ" in self._parameters["StoreSupplementaryCalculations"] \ + or "CostFunctionJb" in self._parameters["StoreSupplementaryCalculations"] \ + or "CostFunctionJo" in self._parameters["StoreSupplementaryCalculations"]: Jb = 0.5 * (Xn - Xb).T * BI * (Xn - Xb) Jo = 0.5 * d.T * RI * d J = float( Jb ) + float( Jo ) - if self._parameters["StoreInternalVariables"] or "CurrentState" in self._parameters["StoreSupplementaryCalculations"]: - self.StoredVariables["CurrentState"].store( Xn ) self.StoredVariables["CostFunctionJb"].store( Jb ) self.StoredVariables["CostFunctionJo"].store( Jo ) self.StoredVariables["CostFunctionJ" ].store( J ) diff --git a/src/daComposant/daAlgorithms/KalmanFilter.py b/src/daComposant/daAlgorithms/KalmanFilter.py index e613ae2..f8885e9 100644 --- a/src/daComposant/daAlgorithms/KalmanFilter.py +++ b/src/daComposant/daAlgorithms/KalmanFilter.py @@ -144,12 +144,15 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self.StoredVariables["APosterioriCovariance"].store( Pn ) if "Innovation" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["Innovation"].store( numpy.ravel( d.A1 ) ) - if self._parameters["StoreInternalVariables"]: + if self._parameters["StoreInternalVariables"] or "CurrentState" in self._parameters["StoreSupplementaryCalculations"]: + self.StoredVariables["CurrentState"].store( Xn ) + if self._parameters["StoreInternalVariables"] \ + or "CostFunctionJ" in self._parameters["StoreSupplementaryCalculations"] \ + or "CostFunctionJb" in self._parameters["StoreSupplementaryCalculations"] \ + or "CostFunctionJo" in self._parameters["StoreSupplementaryCalculations"]: Jb = 0.5 * (Xn - Xb).T * BI * (Xn - Xb) Jo = 0.5 * d.T * RI * d J = float( Jb ) + float( Jo ) - if self._parameters["StoreInternalVariables"] or "CurrentState" in self._parameters["StoreSupplementaryCalculations"]: - self.StoredVariables["CurrentState"].store( Xn ) self.StoredVariables["CostFunctionJb"].store( Jb ) self.StoredVariables["CostFunctionJo"].store( Jo ) self.StoredVariables["CostFunctionJ" ].store( J ) diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 917848a..5e9b4e4 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -547,6 +547,74 @@ class Diagnostic(object): """ raise NotImplementedError("Diagnostic activation method has not been implemented!") +# ============================================================================== +class Vector(object): + """ + Classe générale d'interface de type vecteur + """ + def __init__(self, + name = "GenericVector", + asVector = None, + asPersistentVector = None, + Scheduler = None, + toBeChecked = False, + ): + """ + Permet de définir un vecteur : + - asVector : entrée des données, comme un vecteur compatible avec + le constructeur de numpy.matrix + - asPersistentVector : entrée des données, comme une série de + vecteurs compatible avec le constructeur de numpy.matrix, ou + comme un objet de type Persistence + """ + self.__name = str(name) + self.__check = bool(toBeChecked) + # + self.__V = None + self.__T = None + self.__is_vector = False + self.__is_series = False + if asVector is not None: + self.__is_vector = True + self.__V = numpy.matrix( numpy.ravel(numpy.matrix(asVector)), numpy.float ).T + self.shape = self.__V.shape + self.size = self.__V.size + elif asPersistentVector is not None: + self.__is_series = True + if type(asPersistentVector) in [tuple, list, numpy.ndarray, numpy.matrix]: + self.__V = Persistence.OneVector(self.__name, basetype=numpy.matrix) + for member in asPersistentVector: + self.__V.store( numpy.matrix( numpy.asmatrix(member).A1, numpy.float ).T ) + import sys ; sys.stdout.flush() + else: + self.__V = asPersistentVector + if type(self.__V.shape) in (tuple, list): + self.shape = self.__V.shape + else: + self.shape = self.__V.shape() + self.size = self.shape[0] * self.shape[1] + else: + raise ValueError("The %s object is improperly defined, it requires at minima either a vector, a list/tuple of vectors or a persistent object. Please check your vector input."%self.__name) + # + if Scheduler is not None: + self.__T = Scheduler + + def isvector(self): + "Vérification du type interne" + return self.__is_vector + + def isseries(self): + "Vérification du type interne" + return self.__is_series + + def __repr__(self): + "x.__repr__() <==> repr(x)" + return repr(self.__V) + + def __str__(self): + "x.__str__() <==> str(x)" + return str(self.__V) + # ============================================================================== class Covariance(object): """ diff --git a/src/daComposant/daCore/Persistence.py b/src/daComposant/daCore/Persistence.py index 3ff81f5..d867d07 100644 --- a/src/daComposant/daCore/Persistence.py +++ b/src/daComposant/daCore/Persistence.py @@ -112,7 +112,7 @@ class Persistence(object): longueur. Par défaut, renvoie 1. """ if len(self.__values) > 0: - if self.__basetype in [numpy.matrix, numpy.array, numpy.ravel]: + if self.__basetype in [numpy.matrix, numpy.ndarray, numpy.array, numpy.ravel]: return self.__values[-1].shape elif self.__basetype in [int, float]: return (1,)