1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2012 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
23 from daCore import BasicObjects, Persistence
25 # ==============================================================================
26 class ElementaryDiagnostic(BasicObjects.Diagnostic,Persistence.OneScalar):
28 Diagnostic sur la reduction de la variance lors de l'analyse
30 def __init__(self, name = "", unit = "", basetype = None, parameters = {}):
31 BasicObjects.Diagnostic.__init__(self, name, parameters)
32 Persistence.OneScalar.__init__( self, name, unit, basetype = bool )
34 def _formula(self, V1, V2):
36 Vérification de la reduction de variance sur les écarts entre OMB et OMA
39 varianceOMB = V1.var()
40 varianceOMA = V2.var()
42 if varianceOMA > varianceOMB:
43 reducevariance = False
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 variance 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 ReduceVariance")
77 # Vecteur de type matrix
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 " La variance de OMB est de...........................:", x1.var()
84 print " L'écart entre les observations et l'analyse est OMA :", x2
85 print " La moyenne de OMA (i.e. le biais) est de............:", x2.mean()
86 print " La variance de OMA est de...........................:", x2.var()
88 D.calculate( vectorOMB = x1, vectorOMA = x2)
89 if not D.valueserie(0) :
90 print " Résultat : l'analyse NE RÉDUIT PAS la variance"
92 print " Résultat : l'analyse RÉDUIT la variance"
95 # Vecteur de type array
96 # ---------------------
97 x1 = numpy.array(range(11))
98 x2 = numpy.matrix(range(-10,12,2))
99 print " L'écart entre les observations et l'ébauche est OMB :", x1
100 print " La moyenne de OMB (i.e. le biais) est de............:", x1.mean()
101 print " La variance de OMB est de...........................:", x1.var()
102 print " L'écart entre les observations et l'analyse est OMA :", x2
103 print " La moyenne de OMA (i.e. le biais) est de............:", x2.mean()
104 print " La variance de OMA est de...........................:", x2.var()
106 D.calculate( vectorOMB = x1, vectorOMA = x2)
107 if not D.valueserie(1) :
108 print " Résultat : l'analyse NE RÉDUIT PAS la variance"
110 print " Résultat : l'analyse RÉDUIT la variance"