1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2010 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 Calcul du biais (i.e. la moyenne) à chaque pas. Ce diagnostic très simple
23 est présent pour rappeller à l'utilisateur de l'assimilation qu'il faut
24 qu'il vérifie le biais de ses erreurs en particulier.
26 __author__ = "Sophie RICCI - Aout 2008"
29 from daCore import BasicObjects, Persistence
31 # ==============================================================================
32 class ElementaryDiagnostic(BasicObjects.Diagnostic,Persistence.OneScalar):
33 def __init__(self, name = "", unit = "", basetype = None, parameters = {}):
34 BasicObjects.Diagnostic.__init__(self, name, parameters)
35 Persistence.OneScalar.__init__( self, name, unit, basetype = float )
37 def _formula(self, V):
39 Calcul du biais, qui est simplement la moyenne du vecteur
45 def calculate(self, vector = None, step = None):
47 Teste les arguments, active la formule de calcul et stocke le résultat
50 raise ValueError("One vector must be given to compute biais")
51 V = numpy.array(vector)
53 raise ValueError("The given vector must not be empty")
55 value = self._formula( V)
57 self.store( value = value, step = step )
59 #===============================================================================
60 if __name__ == "__main__":
61 print '\n AUTODIAGNOSTIC \n'
63 # Instanciation de l'objet diagnostic
64 # -----------------------------------
65 D = ElementaryDiagnostic("Mon ComputeBiais")
67 # Tirage d un vecteur choisi
68 # --------------------------
69 x = numpy.matrix(([3., 4., 5.]))
70 print " Le vecteur de type 'matrix' choisi est..:", x
71 print " Le biais attendu de ce vecteur est......:", x.mean()
73 D.calculate( vector = x)
74 print " Le biais obtenu de ce vecteur est.......:", D.valueserie(0)
77 # Tirage d un vecteur choisi
78 # --------------------------
79 x = numpy.array(range(11))
80 print " Le vecteur de type 'array' choisi est...:", x
81 print " Le biais attendu de ce vecteur est......:", x.mean()
83 D.calculate( vector = x)
84 print " Le biais obtenu de ce vecteur est.......:", D.valueserie(1)