Salome HOME
Improving KF and EKF for parameter estimation
[modules/adao.git] / src / daComposant / daCore / BasicObjects.py
index 0c15f3d85c320b3727fae67f2c8c9037cb3d3ed6..fc3f16fb8b5a6e3a93cfbdbde9386f8d4b8e1ecc 100644 (file)
@@ -1,24 +1,24 @@
 #-*-coding:iso-8859-1-*-
 #
-#  Copyright (C) 2008-2012 EDF R&D
+# Copyright (C) 2008-2013 EDF R&D
 #
-#  This library is free software; you can redistribute it and/or
-#  modify it under the terms of the GNU Lesser General Public
-#  License as published by the Free Software Foundation; either
-#  version 2.1 of the License.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
 #
-#  This library is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  Lesser General Public License for more details.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
-#  You should have received a copy of the GNU Lesser General Public
-#  License along with this library; if not, write to the Free Software
-#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
-#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-#  Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
 
 __doc__ = """
     Définit les outils généraux élémentaires.
@@ -74,6 +74,23 @@ class Operator:
         else:
             return self.__Method( xValue )
 
+    def appliedControledFormTo(self, (xValue, uValue) ):
+        """
+        Permet de restituer le résultat de l'application de l'opérateur à une
+        paire (xValue, uValue). Cette méthode se contente d'appliquer, son
+        argument devant a priori être du bon type. Si la uValue est None,
+        on suppose que l'opérateur ne s'applique qu'à xValue.
+        Arguments :
+        - xValue : argument X adapté pour appliquer l'opérateur
+        - uValue : argument U adapté pour appliquer l'opérateur
+        """
+        if self.__Matrix is not None:
+            return self.__Matrix * xValue
+        elif uValue is not None:
+            return self.__Method( (xValue, uValue) )
+        else:
+            return self.__Method( xValue )
+
     def appliedInXTo(self, (xNominal, xValue) ):
         """
         Permet de restituer le résultat de l'application de l'opérateur à un
@@ -141,8 +158,9 @@ class Algorithm:
             - CurrentState : état courant lors d'itérations
             - Analysis : l'analyse
             - Innovation : l'innovation : d = Y - H Xb
-            - SigmaObs2 : correction optimale des erreurs d'observation
-            - SigmaBck2 : correction optimale des erreurs d'ébauche
+            - SigmaObs2 : indicateur de correction optimale des erreurs d'observation
+            - SigmaBck2 : indicateur de correction optimale des erreurs d'ébauche
+            - MahalanobisConsistency : indicateur de consistance des covariances
             - OMA : Observation moins Analysis : Y - Xa
             - OMB : Observation moins Background : Y - Xb
             - AMB : Analysis moins Background : Xa - Xb
@@ -167,6 +185,7 @@ class Algorithm:
         self.StoredVariables["Innovation"]               = Persistence.OneVector(name = "Innovation")
         self.StoredVariables["SigmaObs2"]                = Persistence.OneScalar(name = "SigmaObs2")
         self.StoredVariables["SigmaBck2"]                = Persistence.OneScalar(name = "SigmaBck2")
+        self.StoredVariables["MahalanobisConsistency"]   = Persistence.OneScalar(name = "MahalanobisConsistency")
         self.StoredVariables["OMA"]                      = Persistence.OneVector(name = "OMA")
         self.StoredVariables["OMB"]                      = Persistence.OneVector(name = "OMB")
         self.StoredVariables["BMA"]                      = Persistence.OneVector(name = "BMA")
@@ -254,11 +273,16 @@ class Algorithm:
             else:                __val = typecast( value )
         #
         if minval is not None and __val < minval:
-            raise ValueError("The parameter named \"%s\" of value %s can not be less than %s."%(name, __val, minval))
+            raise ValueError("The parameter named \"%s\" of value \"%s\" can not be less than %s."%(name, __val, minval))
         if maxval is not None and __val > maxval:
-            raise ValueError("The parameter named \"%s\" of value %s can not be greater than %s."%(name, __val, maxval))
-        if listval is not None and __val not in listval:
-            raise ValueError("The parameter named \"%s\" of value %s has to be in the list %s."%(name, __val, listval))
+            raise ValueError("The parameter named \"%s\" of value \"%s\" can not be greater than %s."%(name, __val, maxval))
+        if listval is not None:
+            if typecast is list or typecast is tuple or type(__val) is list or type(__val) is tuple:
+                for v in __val:
+                    if v not in listval:
+                        raise ValueError("The value \"%s\" of the parameter named \"%s\" is not allowed, it has to be in the list %s."%(v, name, listval))
+            elif __val not in listval:
+                raise ValueError("The value \"%s\" of the parameter named \"%s\" is not allowed, it has to be in the list %s."%( __val, name,listval))
         return __val
 
     def setParameters(self, fromDico={}):