1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2014 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
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 from daCore import BasicObjects, PlatformInfo
25 m = PlatformInfo.SystemUsage()
28 # ==============================================================================
29 class ElementaryAlgorithm(BasicObjects.Algorithm):
31 BasicObjects.Algorithm.__init__(self, "FUNCTIONTEST")
32 self.defineRequiredParameter(
33 name = "NumberOfPrintedDigits",
36 message = "Nombre de chiffres affichés pour les impressions de réels",
39 self.defineRequiredParameter(
40 name = "NumberOfRepetition",
43 message = "Nombre de fois où l'exécution de la fonction est répétée",
46 self.defineRequiredParameter(
50 message = "Titre du tableau et de la figure",
52 self.defineRequiredParameter(
56 message = "Activation du mode debug lors de l'exécution",
59 def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
60 logging.debug("%s Lancement"%self._name)
61 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
63 self.setParameters(Parameters)
65 Hm = HO["Direct"].appliedTo
67 Xn = numpy.asmatrix(numpy.ravel( Xb )).T
70 _p = self._parameters["NumberOfPrintedDigits"]
71 if len(self._parameters["ResultTitle"]) > 0:
72 msg = " ====" + "="*len(self._parameters["ResultTitle"]) + "====\n"
73 msg += " " + self._parameters["ResultTitle"] + "\n"
74 msg += " ====" + "="*len(self._parameters["ResultTitle"]) + "====\n"
77 msg = "===> Information before launching:\n"
78 msg += " -----------------------------\n"
79 msg += " Characteristics of input vector X, internally converted:\n"
80 msg += " Type...............: %s\n"%type( Xn )
81 msg += " Lenght of vector...: %i\n"%max(numpy.matrix( Xn ).shape)
82 msg += (" Minimum value......: %."+str(_p)+"e\n")%numpy.min( Xn )
83 msg += (" Maximum value......: %."+str(_p)+"e\n")%numpy.max( Xn )
84 msg += (" Mean of vector.....: %."+str(_p)+"e\n")%numpy.mean( Xn )
85 msg += (" Standard error.....: %."+str(_p)+"e\n")%numpy.std( Xn )
86 msg += (" L2 norm of vector..: %."+str(_p)+"e\n")%numpy.linalg.norm( Xn )
89 if self._parameters["SetDebug"]:
90 CUR_LEVEL = logging.getLogger().getEffectiveLevel()
91 logging.getLogger().setLevel(logging.DEBUG)
92 print("===> Beginning of evaluation, activating debug\n")
94 print("===> Beginning of evaluation, without activating debug\n")
98 for i in range(self._parameters["NumberOfRepetition"]):
99 print(" %s\n"%("-"*75,))
100 if self._parameters["NumberOfRepetition"] > 1:
101 print("===> Repetition step number %i on a total of %i\n"%(i+1,self._parameters["NumberOfRepetition"]))
102 print("===> Launching direct operator evaluation\n")
106 print("\n===> End of direct operator evaluation\n")
108 msg = ("===> Information after evaluation:\n")
109 msg += ("\n Characteristics of output vector Y, to compare to other calculations:\n")
110 msg += (" Type...............: %s\n")%type( Y )
111 msg += (" Lenght of vector...: %i\n")%max(numpy.matrix( Y ).shape)
112 msg += (" Minimum value......: %."+str(_p)+"e\n")%numpy.min( Y )
113 msg += (" Maximum value......: %."+str(_p)+"e\n")%numpy.max( Y )
114 msg += (" Mean of vector.....: %."+str(_p)+"e\n")%numpy.mean( Y )
115 msg += (" Standard error.....: %."+str(_p)+"e\n")%numpy.std( Y )
116 msg += (" L2 norm of vector..: %."+str(_p)+"e\n")%numpy.linalg.norm( Y )
119 Ys.append( copy.copy( numpy.ravel(Y) ) )
121 print(" %s\n"%("-"*75,))
122 if self._parameters["SetDebug"]:
123 print("===> End evaluation, deactivating debug if necessary\n")
124 logging.getLogger().setLevel(CUR_LEVEL)
126 if self._parameters["NumberOfRepetition"] > 1:
127 msg = (" %s\n"%("-"*75,))
128 msg += ("\n===> Statistical analysis of the outputs obtained throught repeated evaluations\n")
129 Yy = numpy.array( Ys )
130 msg += ("\n Characteristics of the whole set of outputs Y:\n")
131 msg += (" Number of evaluations.........................: %i\n")%len( Ys )
132 msg += (" Minimum value of the whole set of outputs.....: %."+str(_p)+"e\n")%numpy.min( Yy )
133 msg += (" Maximum value of the whole set of outputs.....: %."+str(_p)+"e\n")%numpy.max( Yy )
134 msg += (" Mean of vector of the whole set of outputs....: %."+str(_p)+"e\n")%numpy.mean( Yy )
135 msg += (" Standard error of the whole set of outputs....: %."+str(_p)+"e\n")%numpy.std( Yy )
136 Ym = numpy.mean( numpy.array( Ys ), axis=0 )
137 msg += ("\n Characteristics of the vector Ym, mean of the outputs Y:\n")
138 msg += (" Size of the mean of the outputs...............: %i\n")%Ym.size
139 msg += (" Minimum value of the mean of the outputs......: %."+str(_p)+"e\n")%numpy.min( Ym )
140 msg += (" Maximum value of the mean of the outputs......: %."+str(_p)+"e\n")%numpy.max( Ym )
141 msg += (" Mean of the mean of the outputs...............: %."+str(_p)+"e\n")%numpy.mean( Ym )
142 msg += (" Standard error of the mean of the outputs.....: %."+str(_p)+"e\n")%numpy.std( Ym )
143 Ye = numpy.mean( numpy.array( Ys ) - Ym, axis=0 )
144 msg += "\n Characteristics of the mean of the differences between the outputs Y and their mean Ym:\n"
145 msg += (" Size of the mean of the differences...........: %i\n")%Ym.size
146 msg += (" Minimum value of the mean of the differences..: %."+str(_p)+"e\n")%numpy.min( Ye )
147 msg += (" Maximum value of the mean of the differences..: %."+str(_p)+"e\n")%numpy.max( Ye )
148 msg += (" Mean of the mean of the differences...........: %."+str(_p)+"e\n")%numpy.mean( Ye )
149 msg += (" Standard error of the mean of the differences.: %."+str(_p)+"e\n")%numpy.std( Ye )
150 msg += ("\n %s\n"%("-"*75,))
153 logging.debug("%s Nombre d'évaluation(s) de l'opérateur d'observation direct/tangent/adjoint : %i/%i/%i"%(self._name, HO["Direct"].nbcalls(0),HO["Tangent"].nbcalls(0),HO["Adjoint"].nbcalls(0)))
154 logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M")))
155 logging.debug("%s Terminé"%self._name)
159 # ==============================================================================
160 if __name__ == "__main__":
161 print '\n AUTODIAGNOSTIC \n'