1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2009 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"
26 import sys ; sys.path.insert(0, "../daCore")
30 from BasicObjects import Diagnostic
31 from AssimilationStudy import AssimilationStudy
33 # ==============================================================================
34 class ElementaryDiagnostic(Diagnostic,Persistence.OneScalar):
35 def __init__(self, name = "", unit = "", basetype = None, parameters = {}):
36 Diagnostic.__init__(self, name, parameters)
37 Persistence.OneScalar.__init__( self, name, unit, basetype = bool)
39 def _formula(self, V1, V2):
41 Vérification de la reduction du biais entre OMB et OMA lors de l'analyse
46 if biaisOMA > biaisOMB:
53 def calculate(self, vectorOMB = None, vectorOMA = None, step = None):
55 Teste les arguments, active la formule de calcul et stocke le résultat
57 - vectorOMB : vecteur d'écart entre les observations et l'ébauche
58 - vectorOMA : vecteur d'écart entre les observations et l'analyse
60 if ( (vectorOMB is None) or (vectorOMA is None) ):
61 raise ValueError("Two vectors must be given to test the reduction of the biais after analysis")
62 V1 = numpy.array(vectorOMB)
63 V2 = numpy.array(vectorOMA)
64 if V1.size < 1 or V2.size < 1:
65 raise ValueError("The given vectors must not be empty")
66 if V1.size != V2.size:
67 raise ValueError("The two given vectors must have the same size")
69 value = self._formula( V1, V2 )
71 self.store( value = value, step = step )
73 #===============================================================================
74 if __name__ == "__main__":
75 print '\n AUTODIAGNOSTIC \n'
77 # Instanciation de l'objet diagnostic
78 # -----------------------------------
79 D = ElementaryDiagnostic("Mon ReduceBiais")
81 # Tirage des 2 vecteurs choisis
82 # -------------------------------
83 x1 = numpy.matrix(([3. , 4., 5. ]))
84 x2 = numpy.matrix(([1.5, 2., 2.5]))
85 print " L'écart entre les observations et l'ébauche est OMB :", x1
86 print " La moyenne de OMB (i.e. le biais) est de............:", x1.mean()
87 print " L'écart entre les observations et l'analyse est OMA :", x2
88 print " La moyenne de OMA (i.e. le biais) est de............:", x2.mean()
90 D.calculate( vectorOMB = x1, vectorOMA = x2)
91 if not D.valueserie(0) :
92 print " Résultat : l'analyse NE RÉDUIT PAS le biais"
94 print " Résultat : l'analyse RÉDUIT le biais"
97 # Tirage des 2 vecteurs choisis
98 # -------------------------------
99 x1 = numpy.matrix(range(-5,6))
100 x2 = numpy.array(range(11))
101 print " L'écart entre les observations et l'ébauche est OMB :", x1
102 print " La moyenne de OMB (i.e. le biais) est de............:", x1.mean()
103 print " L'écart entre les observations et l'analyse est OMA :", x2
104 print " La moyenne de OMA (i.e. le biais) est de............:", x2.mean()
106 D.calculate( vectorOMB = x1, vectorOMA = x2)
107 if not D.valueserie(1) :
108 print " Résultat : l'analyse NE RÉDUIT PAS le biais"
110 print " Résultat : l'analyse RÉDUIT le biais"