]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Minor corrections for variables handling
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Thu, 13 Apr 2017 17:13:58 +0000 (19:13 +0200)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Thu, 13 Apr 2017 17:13:58 +0000 (19:13 +0200)
src/daComposant/daAlgorithms/ExtendedKalmanFilter.py
src/daComposant/daAlgorithms/KalmanFilter.py
src/daComposant/daCore/BasicObjects.py
src/daComposant/daCore/Persistence.py

index 0fbd0db655fb1dc8257f6cedf7c1a0bed21d7833..621cf51d0a02f2b23c4926165b8b18722dac1572 100644 (file)
@@ -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 )
index e613ae2cf0f653e92a8ad95d3e0070ff8633ba47..f8885e9a05831a9b504471749866f59cb1f887ab 100644 (file)
@@ -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 )
index 917848add3501eb54d90472116978b63481f0ac5..5e9b4e481b8970dba565fc482e1fe875528bfa50 100644 (file)
@@ -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):
     """
index 3ff81f55635f35680a38b58d07fe300ba5bd8fe6..d867d07ba01627e06a6c89c7fc4ef651d870742f 100644 (file)
@@ -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,)