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 Diagnostic sur la reduction du biais lors de l'analyse
24 __author__ = "Sophie RICCI - Aout 2008"
27 from daCore import BasicObjects, Persistence
29 # ==============================================================================
30 class ElementaryDiagnostic(BasicObjects.Diagnostic,Persistence.OneScalar):
31 def __init__(self, name = "", unit = "", basetype = None, parameters = {}):
32 BasicObjects.Diagnostic.__init__(self, name, parameters)
33 Persistence.OneScalar.__init__( self, name, unit, basetype = bool)
35 def _formula(self, V1, V2):
37 Vérification de la reduction du biais entre OMB et OMA lors de l'analyse
42 if biaisOMA > biaisOMB:
49 def calculate(self, vectorOMB = None, vectorOMA = None, step = None):
51 Teste les arguments, active la formule de calcul et stocke le résultat
53 - vectorOMB : vecteur d'écart entre les observations et l'ébauche
54 - vectorOMA : vecteur d'écart entre les observations et l'analyse
56 if ( (vectorOMB is None) or (vectorOMA is None) ):
57 raise ValueError("Two vectors must be given to test the reduction of the biais after analysis")
58 V1 = numpy.array(vectorOMB)
59 V2 = numpy.array(vectorOMA)
60 if V1.size < 1 or V2.size < 1:
61 raise ValueError("The given vectors must not be empty")
62 if V1.size != V2.size:
63 raise ValueError("The two given vectors must have the same size")
65 value = self._formula( V1, V2 )
67 self.store( value = value, step = step )
69 #===============================================================================
70 if __name__ == "__main__":
71 print '\n AUTODIAGNOSTIC \n'
73 # Instanciation de l'objet diagnostic
74 # -----------------------------------
75 D = ElementaryDiagnostic("Mon ReduceBiais")
77 # Tirage des 2 vecteurs choisis
78 # -------------------------------
79 x1 = numpy.matrix(([3. , 4., 5. ]))
80 x2 = numpy.matrix(([1.5, 2., 2.5]))
81 print " L'écart entre les observations et l'ébauche est OMB :", x1
82 print " La moyenne de OMB (i.e. le biais) est de............:", x1.mean()
83 print " L'écart entre les observations et l'analyse est OMA :", x2
84 print " La moyenne de OMA (i.e. le biais) est de............:", x2.mean()
86 D.calculate( vectorOMB = x1, vectorOMA = x2)
87 if not D.valueserie(0) :
88 print " Résultat : l'analyse NE RÉDUIT PAS le biais"
90 print " Résultat : l'analyse RÉDUIT le biais"
93 # Tirage des 2 vecteurs choisis
94 # -------------------------------
95 x1 = numpy.matrix(range(-5,6))
96 x2 = numpy.array(range(11))
97 print " L'écart entre les observations et l'ébauche est OMB :", x1
98 print " La moyenne de OMB (i.e. le biais) est de............:", x1.mean()
99 print " L'écart entre les observations et l'analyse est OMA :", x2
100 print " La moyenne de OMA (i.e. le biais) est de............:", x2.mean()
102 D.calculate( vectorOMB = x1, vectorOMA = x2)
103 if not D.valueserie(1) :
104 print " Résultat : l'analyse NE RÉDUIT PAS le biais"
106 print " Résultat : l'analyse RÉDUIT le biais"