X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FdaComposant%2FdaAlgorithms%2FFunctionTest.py;h=4457d8396792eabe3a29b218bc22744fe905d67e;hb=087028cb881b07298c2b68bf8b2c080dff09a042;hp=828930ebba863adf45042ffc15d499d3648b75f7;hpb=23322723a7fa4ff58aebc1f4364d28af7e07d9f7;p=modules%2Fadao.git diff --git a/src/daComposant/daAlgorithms/FunctionTest.py b/src/daComposant/daAlgorithms/FunctionTest.py index 828930e..4457d83 100644 --- a/src/daComposant/daAlgorithms/FunctionTest.py +++ b/src/daComposant/daAlgorithms/FunctionTest.py @@ -1,6 +1,6 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # -# Copyright (C) 2008-2017 EDF R&D +# Copyright (C) 2008-2020 EDF R&D # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,11 +20,13 @@ # # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D -import logging +import sys, logging from daCore import BasicObjects, PlatformInfo import numpy, copy mpr = PlatformInfo.PlatformInfo().MachinePrecision() mfp = PlatformInfo.PlatformInfo().MaximumPrecision() +if sys.version_info.major > 2: + unicode = str # ============================================================================== class ElementaryAlgorithm(BasicObjects.Algorithm): @@ -34,14 +36,14 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): name = "NumberOfPrintedDigits", default = 5, typecast = int, - message = "Nombre de chiffres affichés pour les impressions de réels", + message = "Nombre de chiffres affichés pour les impressions de réels", minval = 0, ) self.defineRequiredParameter( name = "NumberOfRepetition", default = 1, typecast = int, - message = "Nombre de fois où l'exécution de la fonction est répétée", + message = "Nombre de fois où l'exécution de la fonction est répétée", minval = 1, ) self.defineRequiredParameter( @@ -54,44 +56,51 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): name = "SetDebug", default = False, typecast = bool, - message = "Activation du mode debug lors de l'exécution", + message = "Activation du mode debug lors de l'exécution", ) self.defineRequiredParameter( name = "StoreSupplementaryCalculations", default = [], typecast = tuple, - message = "Liste de calculs supplémentaires à stocker et/ou effectuer", - listval = ["CurrentState", "SimulatedObservationAtCurrentState"] + message = "Liste de calculs supplémentaires à stocker et/ou effectuer", + listval = [ + "CurrentState", + "SimulatedObservationAtCurrentState", + ] + ) + self.requireInputArguments( + mandatory= ("Xb", "HO"), ) def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None): - self._pre_run() - # - self.setParameters(Parameters) + self._pre_run(Parameters, Xb, Y, R, B, Q) # Hm = HO["Direct"].appliedTo # Xn = copy.copy( Xb ) # # ---------- + __marge = 5*u" " _p = self._parameters["NumberOfPrintedDigits"] if len(self._parameters["ResultTitle"]) > 0: - msg = " ====" + "="*len(self._parameters["ResultTitle"]) + "====\n" - msg += " " + self._parameters["ResultTitle"] + "\n" - msg += " ====" + "="*len(self._parameters["ResultTitle"]) + "====\n" - print("%s"%msg) + __rt = unicode(self._parameters["ResultTitle"]) + msgs = u"\n" + msgs += __marge + "====" + "="*len(__rt) + "====\n" + msgs += __marge + " " + __rt + "\n" + msgs += __marge + "====" + "="*len(__rt) + "====\n" + print("%s"%msgs) # - msg = ("===> Information before launching:\n") - msg += (" -----------------------------\n") - msg += (" Characteristics of input vector X, internally converted:\n") - msg += (" Type...............: %s\n")%type( Xn ) - msg += (" Lenght of vector...: %i\n")%max(numpy.matrix( Xn ).shape) - msg += (" Minimum value......: %."+str(_p)+"e\n")%numpy.min( Xn ) - msg += (" Maximum value......: %."+str(_p)+"e\n")%numpy.max( Xn ) - msg += (" Mean of vector.....: %."+str(_p)+"e\n")%numpy.mean( Xn, dtype=mfp ) - msg += (" Standard error.....: %."+str(_p)+"e\n")%numpy.std( Xn, dtype=mfp ) - msg += (" L2 norm of vector..: %."+str(_p)+"e\n")%numpy.linalg.norm( Xn ) - print(msg) + msgs = ("===> Information before launching:\n") + msgs += (" -----------------------------\n") + msgs += (" Characteristics of input vector X, internally converted:\n") + msgs += (" Type...............: %s\n")%type( Xn ) + msgs += (" Lenght of vector...: %i\n")%max(numpy.matrix( Xn ).shape) + msgs += (" Minimum value......: %."+str(_p)+"e\n")%numpy.min( Xn ) + msgs += (" Maximum value......: %."+str(_p)+"e\n")%numpy.max( Xn ) + msgs += (" Mean of vector.....: %."+str(_p)+"e\n")%numpy.mean( Xn, dtype=mfp ) + msgs += (" Standard error.....: %."+str(_p)+"e\n")%numpy.std( Xn, dtype=mfp ) + msgs += (" L2 norm of vector..: %."+str(_p)+"e\n")%numpy.linalg.norm( Xn ) + print(msgs) # if self._parameters["SetDebug"]: CUR_LEVEL = logging.getLogger().getEffectiveLevel() @@ -105,7 +114,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ---------- Ys = [] for i in range(self._parameters["NumberOfRepetition"]): - if "CurrentState" in self._parameters["StoreSupplementaryCalculations"]: + if self._toStore("CurrentState"): self.StoredVariables["CurrentState"].store( numpy.ravel(Xn) ) print(" %s\n"%("-"*75,)) if self._parameters["NumberOfRepetition"] > 1: @@ -116,17 +125,17 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # print("\n===> End of direct operator evaluation\n") # - msg = ("===> Information after evaluation:\n") - msg += ("\n Characteristics of simulated output vector Y=H(X), to compare to others:\n") - msg += (" Type...............: %s\n")%type( Yn ) - msg += (" Lenght of vector...: %i\n")%max(numpy.matrix( Yn ).shape) - msg += (" Minimum value......: %."+str(_p)+"e\n")%numpy.min( Yn ) - msg += (" Maximum value......: %."+str(_p)+"e\n")%numpy.max( Yn ) - msg += (" Mean of vector.....: %."+str(_p)+"e\n")%numpy.mean( Yn, dtype=mfp ) - msg += (" Standard error.....: %."+str(_p)+"e\n")%numpy.std( Yn, dtype=mfp ) - msg += (" L2 norm of vector..: %."+str(_p)+"e\n")%numpy.linalg.norm( Yn ) - print(msg) - if "SimulatedObservationAtCurrentState" in self._parameters["StoreSupplementaryCalculations"]: + msgs = ("===> Information after evaluation:\n") + msgs += ("\n Characteristics of simulated output vector Y=H(X), to compare to others:\n") + msgs += (" Type...............: %s\n")%type( Yn ) + msgs += (" Lenght of vector...: %i\n")%max(numpy.matrix( Yn ).shape) + msgs += (" Minimum value......: %."+str(_p)+"e\n")%numpy.min( Yn ) + msgs += (" Maximum value......: %."+str(_p)+"e\n")%numpy.max( Yn ) + msgs += (" Mean of vector.....: %."+str(_p)+"e\n")%numpy.mean( Yn, dtype=mfp ) + msgs += (" Standard error.....: %."+str(_p)+"e\n")%numpy.std( Yn, dtype=mfp ) + msgs += (" L2 norm of vector..: %."+str(_p)+"e\n")%numpy.linalg.norm( Yn ) + print(msgs) + if self._toStore("SimulatedObservationAtCurrentState"): self.StoredVariables["SimulatedObservationAtCurrentState"].store( numpy.ravel(Yn) ) # Ys.append( copy.copy( numpy.ravel( @@ -138,40 +147,42 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # print(" %s\n"%("-"*75,)) if self._parameters["SetDebug"]: - print("===> End evaluation, deactivating debug if necessary\n") + print("===> End of evaluation, deactivating debug if necessary\n") logging.getLogger().setLevel(CUR_LEVEL) + else: + print("===> End of evaluation, without deactivating debug\n") # if self._parameters["NumberOfRepetition"] > 1: - msg = (" %s\n"%("-"*75,)) - msg += ("\n===> Statistical analysis of the outputs obtained throught repeated evaluations\n") - msg += ("\n (Remark: numbers that are (about) under %.0e represent 0 to machine precision)\n"%mpr) + msgs = (" %s\n"%("-"*75,)) + msgs += ("\n===> Statistical analysis of the outputs obtained through sequential repeated evaluations\n") + msgs += ("\n (Remark: numbers that are (about) under %.0e represent 0 to machine precision)\n"%mpr) Yy = numpy.array( Ys ) - msg += ("\n Characteristics of the whole set of outputs Y:\n") - msg += (" Number of evaluations.........................: %i\n")%len( Ys ) - msg += (" Minimum value of the whole set of outputs.....: %."+str(_p)+"e\n")%numpy.min( Yy ) - msg += (" Maximum value of the whole set of outputs.....: %."+str(_p)+"e\n")%numpy.max( Yy ) - msg += (" Mean of vector of the whole set of outputs....: %."+str(_p)+"e\n")%numpy.mean( Yy, dtype=mfp ) - msg += (" Standard error of the whole set of outputs....: %."+str(_p)+"e\n")%numpy.std( Yy, dtype=mfp ) + msgs += ("\n Characteristics of the whole set of outputs Y:\n") + msgs += (" Number of evaluations.........................: %i\n")%len( Ys ) + msgs += (" Minimum value of the whole set of outputs.....: %."+str(_p)+"e\n")%numpy.min( Yy ) + msgs += (" Maximum value of the whole set of outputs.....: %."+str(_p)+"e\n")%numpy.max( Yy ) + msgs += (" Mean of vector of the whole set of outputs....: %."+str(_p)+"e\n")%numpy.mean( Yy, dtype=mfp ) + msgs += (" Standard error of the whole set of outputs....: %."+str(_p)+"e\n")%numpy.std( Yy, dtype=mfp ) Ym = numpy.mean( numpy.array( Ys ), axis=0, dtype=mfp ) - msg += ("\n Characteristics of the vector Ym, mean of the outputs Y:\n") - msg += (" Size of the mean of the outputs...............: %i\n")%Ym.size - msg += (" Minimum value of the mean of the outputs......: %."+str(_p)+"e\n")%numpy.min( Ym ) - msg += (" Maximum value of the mean of the outputs......: %."+str(_p)+"e\n")%numpy.max( Ym ) - msg += (" Mean of the mean of the outputs...............: %."+str(_p)+"e\n")%numpy.mean( Ym, dtype=mfp ) - msg += (" Standard error of the mean of the outputs.....: %."+str(_p)+"e\n")%numpy.std( Ym, dtype=mfp ) + msgs += ("\n Characteristics of the vector Ym, mean of the outputs Y:\n") + msgs += (" Size of the mean of the outputs...............: %i\n")%Ym.size + msgs += (" Minimum value of the mean of the outputs......: %."+str(_p)+"e\n")%numpy.min( Ym ) + msgs += (" Maximum value of the mean of the outputs......: %."+str(_p)+"e\n")%numpy.max( Ym ) + msgs += (" Mean of the mean of the outputs...............: %."+str(_p)+"e\n")%numpy.mean( Ym, dtype=mfp ) + msgs += (" Standard error of the mean of the outputs.....: %."+str(_p)+"e\n")%numpy.std( Ym, dtype=mfp ) Ye = numpy.mean( numpy.array( Ys ) - Ym, axis=0, dtype=mfp ) - msg += "\n Characteristics of the mean of the differences between the outputs Y and their mean Ym:\n" - msg += (" Size of the mean of the differences...........: %i\n")%Ym.size - msg += (" Minimum value of the mean of the differences..: %."+str(_p)+"e\n")%numpy.min( Ye ) - msg += (" Maximum value of the mean of the differences..: %."+str(_p)+"e\n")%numpy.max( Ye ) - msg += (" Mean of the mean of the differences...........: %."+str(_p)+"e\n")%numpy.mean( Ye, dtype=mfp ) - msg += (" Standard error of the mean of the differences.: %."+str(_p)+"e\n")%numpy.std( Ye, dtype=mfp ) - msg += ("\n %s\n"%("-"*75,)) - print(msg) + msgs += "\n Characteristics of the mean of the differences between the outputs Y and their mean Ym:\n" + msgs += (" Size of the mean of the differences...........: %i\n")%Ym.size + msgs += (" Minimum value of the mean of the differences..: %."+str(_p)+"e\n")%numpy.min( Ye ) + msgs += (" Maximum value of the mean of the differences..: %."+str(_p)+"e\n")%numpy.max( Ye ) + msgs += (" Mean of the mean of the differences...........: %."+str(_p)+"e\n")%numpy.mean( Ye, dtype=mfp ) + msgs += (" Standard error of the mean of the differences.: %."+str(_p)+"e\n")%numpy.std( Ye, dtype=mfp ) + msgs += ("\n %s\n"%("-"*75,)) + print(msgs) # self._post_run(HO) return 0 # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC\n')