1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2017 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
26 mpr = PlatformInfo.PlatformInfo().MachinePrecision()
27 mfp = PlatformInfo.PlatformInfo().MaximumPrecision()
29 # ==============================================================================
30 class ElementaryAlgorithm(BasicObjects.Algorithm):
32 BasicObjects.Algorithm.__init__(self, "FUNCTIONTEST")
33 self.defineRequiredParameter(
34 name = "NumberOfPrintedDigits",
37 message = "Nombre de chiffres affichés pour les impressions de réels",
40 self.defineRequiredParameter(
41 name = "NumberOfRepetition",
44 message = "Nombre de fois où l'exécution de la fonction est répétée",
47 self.defineRequiredParameter(
51 message = "Titre du tableau et de la figure",
53 self.defineRequiredParameter(
57 message = "Activation du mode debug lors de l'exécution",
59 self.defineRequiredParameter(
60 name = "StoreSupplementaryCalculations",
63 message = "Liste de calculs supplémentaires à stocker et/ou effectuer",
64 listval = ["CurrentState", "SimulatedObservationAtCurrentState"]
67 def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
70 self.setParameters(Parameters)
72 Hm = HO["Direct"].appliedTo
77 _p = self._parameters["NumberOfPrintedDigits"]
78 if len(self._parameters["ResultTitle"]) > 0:
79 msg = " ====" + "="*len(self._parameters["ResultTitle"]) + "====\n"
80 msg += " " + self._parameters["ResultTitle"] + "\n"
81 msg += " ====" + "="*len(self._parameters["ResultTitle"]) + "====\n"
84 msg = ("===> Information before launching:\n")
85 msg += (" -----------------------------\n")
86 msg += (" Characteristics of input vector X, internally converted:\n")
87 msg += (" Type...............: %s\n")%type( Xn )
88 msg += (" Lenght of vector...: %i\n")%max(numpy.matrix( Xn ).shape)
89 msg += (" Minimum value......: %."+str(_p)+"e\n")%numpy.min( Xn )
90 msg += (" Maximum value......: %."+str(_p)+"e\n")%numpy.max( Xn )
91 msg += (" Mean of vector.....: %."+str(_p)+"e\n")%numpy.mean( Xn, dtype=mfp )
92 msg += (" Standard error.....: %."+str(_p)+"e\n")%numpy.std( Xn, dtype=mfp )
93 msg += (" L2 norm of vector..: %."+str(_p)+"e\n")%numpy.linalg.norm( Xn )
96 if self._parameters["SetDebug"]:
97 CUR_LEVEL = logging.getLogger().getEffectiveLevel()
98 logging.getLogger().setLevel(logging.DEBUG)
99 print("===> Beginning of evaluation, activating debug\n")
101 print("===> Beginning of evaluation, without activating debug\n")
104 HO["Direct"].disableAvoidingRedundancy()
107 for i in range(self._parameters["NumberOfRepetition"]):
108 if "CurrentState" in self._parameters["StoreSupplementaryCalculations"]:
109 self.StoredVariables["CurrentState"].store( numpy.ravel(Xn) )
110 print(" %s\n"%("-"*75,))
111 if self._parameters["NumberOfRepetition"] > 1:
112 print("===> Repetition step number %i on a total of %i\n"%(i+1,self._parameters["NumberOfRepetition"]))
113 print("===> Launching direct operator evaluation\n")
117 print("\n===> End of direct operator evaluation\n")
119 msg = ("===> Information after evaluation:\n")
120 msg += ("\n Characteristics of simulated output vector Y=H(X), to compare to others:\n")
121 msg += (" Type...............: %s\n")%type( Yn )
122 msg += (" Lenght of vector...: %i\n")%max(numpy.matrix( Yn ).shape)
123 msg += (" Minimum value......: %."+str(_p)+"e\n")%numpy.min( Yn )
124 msg += (" Maximum value......: %."+str(_p)+"e\n")%numpy.max( Yn )
125 msg += (" Mean of vector.....: %."+str(_p)+"e\n")%numpy.mean( Yn, dtype=mfp )
126 msg += (" Standard error.....: %."+str(_p)+"e\n")%numpy.std( Yn, dtype=mfp )
127 msg += (" L2 norm of vector..: %."+str(_p)+"e\n")%numpy.linalg.norm( Yn )
129 if "SimulatedObservationAtCurrentState" in self._parameters["StoreSupplementaryCalculations"]:
130 self.StoredVariables["SimulatedObservationAtCurrentState"].store( numpy.ravel(Yn) )
132 Ys.append( copy.copy( numpy.ravel(
136 HO["Direct"].enableAvoidingRedundancy()
139 print(" %s\n"%("-"*75,))
140 if self._parameters["SetDebug"]:
141 print("===> End evaluation, deactivating debug if necessary\n")
142 logging.getLogger().setLevel(CUR_LEVEL)
144 if self._parameters["NumberOfRepetition"] > 1:
145 msg = (" %s\n"%("-"*75,))
146 msg += ("\n===> Statistical analysis of the outputs obtained throught repeated evaluations\n")
147 msg += ("\n (Remark: numbers that are (about) under %.0e represent 0 to machine precision)\n"%mpr)
148 Yy = numpy.array( Ys )
149 msg += ("\n Characteristics of the whole set of outputs Y:\n")
150 msg += (" Number of evaluations.........................: %i\n")%len( Ys )
151 msg += (" Minimum value of the whole set of outputs.....: %."+str(_p)+"e\n")%numpy.min( Yy )
152 msg += (" Maximum value of the whole set of outputs.....: %."+str(_p)+"e\n")%numpy.max( Yy )
153 msg += (" Mean of vector of the whole set of outputs....: %."+str(_p)+"e\n")%numpy.mean( Yy, dtype=mfp )
154 msg += (" Standard error of the whole set of outputs....: %."+str(_p)+"e\n")%numpy.std( Yy, dtype=mfp )
155 Ym = numpy.mean( numpy.array( Ys ), axis=0, dtype=mfp )
156 msg += ("\n Characteristics of the vector Ym, mean of the outputs Y:\n")
157 msg += (" Size of the mean of the outputs...............: %i\n")%Ym.size
158 msg += (" Minimum value of the mean of the outputs......: %."+str(_p)+"e\n")%numpy.min( Ym )
159 msg += (" Maximum value of the mean of the outputs......: %."+str(_p)+"e\n")%numpy.max( Ym )
160 msg += (" Mean of the mean of the outputs...............: %."+str(_p)+"e\n")%numpy.mean( Ym, dtype=mfp )
161 msg += (" Standard error of the mean of the outputs.....: %."+str(_p)+"e\n")%numpy.std( Ym, dtype=mfp )
162 Ye = numpy.mean( numpy.array( Ys ) - Ym, axis=0, dtype=mfp )
163 msg += "\n Characteristics of the mean of the differences between the outputs Y and their mean Ym:\n"
164 msg += (" Size of the mean of the differences...........: %i\n")%Ym.size
165 msg += (" Minimum value of the mean of the differences..: %."+str(_p)+"e\n")%numpy.min( Ye )
166 msg += (" Maximum value of the mean of the differences..: %."+str(_p)+"e\n")%numpy.max( Ye )
167 msg += (" Mean of the mean of the differences...........: %."+str(_p)+"e\n")%numpy.mean( Ye, dtype=mfp )
168 msg += (" Standard error of the mean of the differences.: %."+str(_p)+"e\n")%numpy.std( Ye, dtype=mfp )
169 msg += ("\n %s\n"%("-"*75,))
175 # ==============================================================================
176 if __name__ == "__main__":
177 print '\n AUTODIAGNOSTIC \n'