Salome HOME
Regression AnalysisFile
[modules/adao.git] / src / daComposant / daDiagnostics / ReduceBiais.py
1 #-*-coding:iso-8859-1-*-
2 #
3 #  Copyright (C) 2008-2010  EDF R&D
4 #
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.
9 #
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.
14 #
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
18 #
19 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 __doc__ = """
22     Diagnostic sur la reduction du biais lors de l'analyse
23 """
24 __author__ = "Sophie RICCI - Aout 2008"
25
26 import numpy
27 from daCore import BasicObjects, Persistence
28
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)
34
35     def _formula(self, V1, V2):
36         """
37         Vérification de la reduction du biais entre OMB et OMA lors de l'analyse
38         """
39         biaisOMB = V1.mean() 
40         biaisOMA = V2.mean() 
41         #
42         if biaisOMA > biaisOMB: 
43             reducebiais = False
44         else :
45             reducebiais = True
46         #
47         return reducebiais
48
49     def calculate(self, vectorOMB = None, vectorOMA = None, step = None):
50         """
51         Teste les arguments, active la formule de calcul et stocke le résultat
52         Arguments :
53             - vectorOMB : vecteur d'écart entre les observations et l'ébauche 
54             - vectorOMA : vecteur d'écart entre les observations et l'analyse
55         """
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")
64         #
65         value = self._formula( V1, V2 )
66         #
67         self.store( value = value,  step = step )
68
69 #===============================================================================
70 if __name__ == "__main__":
71     print '\n AUTODIAGNOSTIC \n'
72     #
73     # Instanciation de l'objet diagnostic
74     # -----------------------------------
75     D = ElementaryDiagnostic("Mon ReduceBiais")
76     #
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()
85     #
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"
89     else :
90             print " Résultat : l'analyse RÉDUIT le biais"
91     print
92     #
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()
101     #
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"
105     else :
106             print " Résultat : l'analyse RÉDUIT le biais"
107     print