From 23322723a7fa4ff58aebc1f4364d28af7e07d9f7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Tue, 10 Jan 2017 22:41:29 +0100 Subject: [PATCH] Adding calculation precision information --- src/daComposant/daAlgorithms/AdjointTest.py | 11 +++++----- src/daComposant/daAlgorithms/FunctionTest.py | 3 ++- src/daComposant/daAlgorithms/GradientTest.py | 21 +++++++------------ src/daComposant/daAlgorithms/LinearityTest.py | 14 ++++++++----- src/daComposant/daAlgorithms/TangentTest.py | 11 +++++----- src/daComposant/daCore/PlatformInfo.py | 12 ++++++++--- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/daComposant/daAlgorithms/AdjointTest.py b/src/daComposant/daAlgorithms/AdjointTest.py index acb16eb..49428a9 100644 --- a/src/daComposant/daAlgorithms/AdjointTest.py +++ b/src/daComposant/daAlgorithms/AdjointTest.py @@ -21,8 +21,9 @@ # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D import logging -from daCore import BasicObjects +from daCore import BasicObjects, PlatformInfo import numpy +mpr = PlatformInfo.PlatformInfo().MachinePrecision() # ============================================================================== class ElementaryAlgorithm(BasicObjects.Algorithm): @@ -113,6 +114,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # Entete des resultats # -------------------- __marge = 12*" " + __precision = """ + Remarque : les nombres inferieurs a %.0e (environ) representent un zero + a la precision machine.\n"""%mpr if self._parameters["ResiduFormula"] == "ScalarProduct": __entete = " i Alpha ||X|| ||Y|| ||dX|| R(Alpha) " __msgdoc = """ @@ -123,10 +127,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): qui doit rester constamment egal a zero a la precision du calcul. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. Y doit etre dans l'image de F. S'il n'est pas donne, on prend Y = F(X). - - Remarque : les nombres inferieurs a 1.e-16 (environ) representent un zero - a la precision machine. - """ + """ + __precision # if len(self._parameters["ResultTitle"]) > 0: msgs = "\n" diff --git a/src/daComposant/daAlgorithms/FunctionTest.py b/src/daComposant/daAlgorithms/FunctionTest.py index 20c5c72..828930e 100644 --- a/src/daComposant/daAlgorithms/FunctionTest.py +++ b/src/daComposant/daAlgorithms/FunctionTest.py @@ -23,6 +23,7 @@ import logging from daCore import BasicObjects, PlatformInfo import numpy, copy +mpr = PlatformInfo.PlatformInfo().MachinePrecision() mfp = PlatformInfo.PlatformInfo().MaximumPrecision() # ============================================================================== @@ -143,7 +144,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): 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 1.e-16 represent 0 to machine precision)\n") + msg += ("\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 ) diff --git a/src/daComposant/daAlgorithms/GradientTest.py b/src/daComposant/daAlgorithms/GradientTest.py index a7c3df5..cc49cb7 100644 --- a/src/daComposant/daAlgorithms/GradientTest.py +++ b/src/daComposant/daAlgorithms/GradientTest.py @@ -21,8 +21,9 @@ # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D import logging -from daCore import BasicObjects +from daCore import BasicObjects, PlatformInfo import numpy, math +mpr = PlatformInfo.PlatformInfo().MachinePrecision() # ============================================================================== class ElementaryAlgorithm(BasicObjects.Algorithm): @@ -143,6 +144,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # Entete des resultats # -------------------- __marge = 12*" " + __precision = """ + Remarque : les nombres inferieurs a %.0e (environ) representent un zero + a la precision machine.\n"""%mpr if self._parameters["ResiduFormula"] == "Taylor": __entete = " i Alpha ||X|| ||F(X)|| ||F(X+dX)|| ||dX|| ||F(X+dX)-F(X)|| ||F(X+dX)-F(X)||/||dX|| R(Alpha) log( R ) " __msgdoc = """ @@ -163,10 +167,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): faite dans le calcul du terme GradientF_X. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. - - Remarque : les nombres inferieurs a 1.e-16 (environ) representent un zero - a la precision machine. - """ + """ + __precision if self._parameters["ResiduFormula"] == "TaylorOnNorm": __entete = " i Alpha ||X|| ||F(X)|| ||F(X+dX)|| ||dX|| ||F(X+dX)-F(X)|| ||F(X+dX)-F(X)||/||dX|| R(Alpha) log( R ) " __msgdoc = """ @@ -191,10 +192,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): grandeur de ||F(X)||. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. - - Remarque : les nombres inferieurs a 1.e-16 (environ) representent un zero - a la precision machine. - """ + """ + __precision if self._parameters["ResiduFormula"] == "Norm": __entete = " i Alpha ||X|| ||F(X)|| ||F(X+dX)|| ||dX|| ||F(X+dX)-F(X)|| ||F(X+dX)-F(X)||/||dX|| R(Alpha) log( R ) " __msgdoc = """ @@ -207,10 +205,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): qui doit rester constant jusqu'à ce que l'on atteigne la précision du calcul. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. - - Remarque : les nombres inferieurs a 1.e-16 (environ) representent un zero - a la precision machine. - """ + """ + __precision # if len(self._parameters["ResultTitle"]) > 0: msgs = "\n" diff --git a/src/daComposant/daAlgorithms/LinearityTest.py b/src/daComposant/daAlgorithms/LinearityTest.py index 144b791..22baa9b 100644 --- a/src/daComposant/daAlgorithms/LinearityTest.py +++ b/src/daComposant/daAlgorithms/LinearityTest.py @@ -21,8 +21,9 @@ # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D import logging -from daCore import BasicObjects +from daCore import BasicObjects, PlatformInfo import numpy, math +mpr = PlatformInfo.PlatformInfo().MachinePrecision() # ============================================================================== class ElementaryAlgorithm(BasicObjects.Algorithm): @@ -140,6 +141,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # Entete des resultats # -------------------- __marge = 12*" " + __precision = """ + Remarque : les nombres inferieurs a %.0e (environ) representent un zero + a la precision machine.\n"""%mpr if self._parameters["ResiduFormula"] == "CenteredDL": __entete = " i Alpha ||X|| ||F(X)|| | R(Alpha) log10( R ) " __msgdoc = """ @@ -163,7 +167,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): de la décroissance quadratique. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. - """ + """ + __precision if self._parameters["ResiduFormula"] == "Taylor": __entete = " i Alpha ||X|| ||F(X)|| | R(Alpha) log10( R ) " __msgdoc = """ @@ -186,7 +190,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): de la décroissance quadratique. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. - """ + """ + __precision if self._parameters["ResiduFormula"] == "NominalTaylor": __entete = " i Alpha ||X|| ||F(X)|| | R(Alpha) |R-1| en % " __msgdoc = """ @@ -207,7 +211,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): est vérifiée. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. - """ + """ + __precision if self._parameters["ResiduFormula"] == "NominalTaylorRMS": __entete = " i Alpha ||X|| ||F(X)|| | R(Alpha) |R| en % " __msgdoc = """ @@ -227,7 +231,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): est vérifiée. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. - """ + """ + __precision # if len(self._parameters["ResultTitle"]) > 0: msgs = "\n" diff --git a/src/daComposant/daAlgorithms/TangentTest.py b/src/daComposant/daAlgorithms/TangentTest.py index 66e3bc7..1039bdf 100644 --- a/src/daComposant/daAlgorithms/TangentTest.py +++ b/src/daComposant/daAlgorithms/TangentTest.py @@ -21,8 +21,9 @@ # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D import logging -from daCore import BasicObjects +from daCore import BasicObjects, PlatformInfo import numpy, math +mpr = PlatformInfo.PlatformInfo().MachinePrecision() # ============================================================================== class ElementaryAlgorithm(BasicObjects.Algorithm): @@ -136,6 +137,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # Entete des resultats # -------------------- __marge = 12*" " + __precision = """ + Remarque : les nombres inferieurs a %.0e (environ) representent un zero + a la precision machine.\n"""%mpr if self._parameters["ResiduFormula"] == "Taylor": __entete = " i Alpha ||X|| ||F(X)|| | R(Alpha) |R-1|/Alpha " __msgdoc = """ @@ -158,10 +162,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): l'on atteigne la précision du calcul. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. - - Remarque : les nombres inferieurs a 1.e-16 (environ) representent un zero - a la precision machine. - """ + """ + __precision # if len(self._parameters["ResultTitle"]) > 0: msgs = "\n" diff --git a/src/daComposant/daCore/PlatformInfo.py b/src/daComposant/daCore/PlatformInfo.py index b50c0ac..14792d7 100644 --- a/src/daComposant/daCore/PlatformInfo.py +++ b/src/daComposant/daCore/PlatformInfo.py @@ -39,7 +39,7 @@ __author__ = "Jean-Philippe ARGAUD" __all__ = [] -import os +import os, sys # ============================================================================== class PlatformInfo(object): @@ -67,7 +67,6 @@ class PlatformInfo(object): def getPythonVersion(self): "Retourne la version de python disponible" - import sys return ".".join([str(x) for x in sys.version_info[0:3]]) # map(str,sys.version_info[0:3])) def getNumpyVersion(self): @@ -130,6 +129,14 @@ class PlatformInfo(object): mfp = 'float64' return mfp + def MachinePrecision(self): + # Alternative sans module : + # eps = 2.38 + # while eps > 0: + # old_eps = eps + # eps = (1.0 + eps/2) - 1.0 + return sys.float_info.epsilon + def __str__(self): import version as dav return "%s %s (%s)"%(dav.name,dav.version,dav.date) @@ -174,7 +181,6 @@ class PathManagement(object): """ def __init__(self): "Déclaration des répertoires statiques" - import sys parent = os.path.abspath(os.path.join(os.path.dirname(__file__),"..")) self.__paths = {} self.__paths["daExternals"] = os.path.join(parent,"daExternals") -- 2.39.2