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 les variances dans B et R par rapport à l'ébauche Xb et aux
23 observations Y. On teste si on a les conditions :
24 1%*xb < sigma_b < 10%*xb
26 1%*yo < sigma_o < 10%*yo
27 Le diagnostic renvoie True si les deux conditions sont simultanément
28 vérifiées, False dans les autres cas.
30 __author__ = "Sophie RICCI, Jean-Philippe ARGAUD - Septembre 2008"
33 from scipy.linalg import eig
34 from daCore import BasicObjects, Persistence
37 # ==============================================================================
38 class ElementaryDiagnostic(BasicObjects.Diagnostic,Persistence.OneScalar):
39 def __init__(self, name = "", unit = "", basetype = None, parameters = {}):
40 BasicObjects.Diagnostic.__init__(self, name, parameters)
41 Persistence.OneScalar.__init__( self, name, unit, basetype = bool )
43 def _formula(self, xb, B, yo, R):
45 Comparaison des variables et de leur variance relative
47 valpB = eig(B, left = False, right = False)
48 valpR = eig(R, left = False, right = False)
49 logging.info(" Si l on souhaite 1%s*xb < sigma_b < 10%s*xb, les valeurs propres de B doivent etre comprises dans l intervalle [%.3e,%.3e]"%("%","%",1.e-4*xb.mean()*xb.mean(),1.e-2*xb.mean()*xb.mean()))
50 logging.info(" Si l on souhaite 1%s*yo < sigma_o < 10%s*yo, les valeurs propres de R doivent etre comprises dans l intervalle [%.3e,%.3e]"%("%","%",1.e-4*yo.mean()*yo.mean(),1.e-2*yo.mean()*yo.mean()))
52 limite_inf_valp = 1.e-4*xb.mean()*xb.mean()
53 limite_sup_valp = 1.e-2*xb.mean()*xb.mean()
54 variancexb = (valpB >= limite_inf_valp).all() and (valpB <= limite_sup_valp).all()
55 logging.info(" La condition empirique sur la variance de Xb est....: %s"%variancexb)
57 limite_inf_valp = 1.e-4*yo.mean()*yo.mean()
58 limite_sup_valp = 1.e-2*yo.mean()*yo.mean()
59 varianceyo = (valpR >= limite_inf_valp).all() and (valpR <= limite_sup_valp).all()
60 logging.info(" La condition empirique sur la variance de Y est.....: %s",varianceyo)
62 variance = variancexb and varianceyo
63 logging.info(" La condition empirique sur la variance globale est..: %s"%variance)
67 def calculate(self, Xb = None, B = None, Y = None, R = None, step = None):
69 Teste les arguments, active la formule de calcul et stocke le résultat
71 - Xb : valeur d'ébauche du paramêtre
72 - B : matrice de covariances d'erreur d'ébauche
73 - yo : vecteur d'observation
74 - R : matrice de covariances d'erreur d'observation
76 if (Xb is None) or (B is None) or (Y is None) or (R is None):
77 raise ValueError("You must specify Xb, B, Y, R")
82 if (RR.size < 1 ) or (BB.size < 1) :
83 raise ValueError("The background and the observation covariance matrices must not be empty")
84 if ( yo.size < 1 ) or ( xb.size < 1 ):
85 raise ValueError("The Xb background and the Y observation vectors must not be empty")
86 if xb.size*xb.size != BB.size:
87 raise ValueError("Xb background vector and B covariance matrix sizes are not consistent")
88 if yo.size*yo.size != RR.size:
89 raise ValueError("Y observation vector and R covariance matrix sizes are not consistent")
90 if yo.all() == 0. or xb.all() == 0. :
91 raise ValueError("The diagnostic can not be applied to zero vectors")
93 value = self._formula( xb, BB, yo, RR)
95 self.store( value = value, step = step )
97 #===============================================================================
98 if __name__ == "__main__":
99 print '\n AUTODIAGNOSTIC \n'
101 # Instanciation de l'objet diagnostic
102 # -----------------------------------
103 D = ElementaryDiagnostic("Mon OrdreVariance")
105 # Vecteur de type matrix
106 # ----------------------
107 xb = numpy.array([11000.])
108 yo = numpy.array([1.e12 , 2.e12, 3.e12 ])
109 B = 1.e06 * numpy.matrix(numpy.identity(1))
110 R = 1.e22 * numpy.matrix(numpy.identity(3))
112 D.calculate( Xb = xb, B = B, Y = yo, R = R)
113 print " L'ébauche est.......................................:",xb
114 print " Les observations sont...............................:",yo
115 print " La valeur moyenne des observations est..............: %.2e"%yo.mean()
116 print " La valeur moyenne de l'ebauche est..................: %.2e"%xb.mean()
117 print " La variance d'ébauche specifiée est.................: %.2e"%1.e6
118 print " La variance d'observation spécifiée est.............: %.2e"%1.e22
121 print " Les variances specifiées sont de l'ordre de 1% a 10% de l'ébauche et des observations"
123 print " Les variances specifiées ne sont pas de l'ordre de 1% a 10% de l'ébauche et des observations"