From: Jean-Philippe ARGAUD Date: Mon, 20 Nov 2023 14:25:53 +0000 (+0100) Subject: Minor tests review corrections X-Git-Tag: V9_12_0rc1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=db7aafdc4528f817f5b9768828741db3d2f5d52b;p=modules%2Fadao.git Minor tests review corrections --- diff --git a/src/daComposant/daAlgorithms/GradientTest.py b/src/daComposant/daAlgorithms/GradientTest.py index 99b4ad1..67627ec 100644 --- a/src/daComposant/daAlgorithms/GradientTest.py +++ b/src/daComposant/daAlgorithms/GradientTest.py @@ -216,6 +216,10 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # msgs += ("\n") msgs += (__marge + "We take dX0 = Normal(0,X) and dX = Alpha*dX0. F is the calculation code.\n") + if "DifferentialIncrement" in HO and HO["DifferentialIncrement"] is not None: + msgs += ("\n") + msgs += (__marge + "Reminder: gradient operator is obtained internally by finite differences,\n") + msgs += (__marge + "with a differential increment of value %.2e.\n"%HO["DifferentialIncrement"]) msgs += ("\n") msgs += (__marge + "(Remark: numbers that are (about) under %.0e represent 0 to machine precision)\n"%mpr) print(msgs) # 1 diff --git a/src/daComposant/daAlgorithms/LinearityTest.py b/src/daComposant/daAlgorithms/LinearityTest.py index a151f55..97d3113 100644 --- a/src/daComposant/daAlgorithms/LinearityTest.py +++ b/src/daComposant/daAlgorithms/LinearityTest.py @@ -223,6 +223,10 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # msgs += ("\n") msgs += (__marge + "We take dX0 = Normal(0,X) and dX = Alpha*dX0. F is the calculation code.\n") + if (self._parameters["ResiduFormula"] == "Taylor") and ("DifferentialIncrement" in HO and HO["DifferentialIncrement"] is not None): + msgs += ("\n") + msgs += (__marge + "Reminder: gradient operator is obtained internally by finite differences,\n") + msgs += (__marge + "with a differential increment of value %.2e.\n"%HO["DifferentialIncrement"]) msgs += ("\n") msgs += (__marge + "(Remark: numbers that are (about) under %.0e represent 0 to machine precision)\n"%mpr) print(msgs) # 1 @@ -245,7 +249,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): X0, ) # - if self._parameters["ResiduFormula"] in ["Taylor", "NominalTaylor", "NominalTaylorRMS"]: + if self._parameters["ResiduFormula"] == "Taylor": dX1 = float(self._parameters["AmplitudeOfTangentPerturbation"]) * dX0 GradFxdX = Ht( (X0, dX1) ) GradFxdX = numpy.ravel( GradFxdX ).reshape((-1,1)) diff --git a/src/daComposant/daAlgorithms/TangentTest.py b/src/daComposant/daAlgorithms/TangentTest.py index e653bed..525210f 100644 --- a/src/daComposant/daAlgorithms/TangentTest.py +++ b/src/daComposant/daAlgorithms/TangentTest.py @@ -167,6 +167,10 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # msgs += ("\n") msgs += (__marge + "We take dX0 = Normal(0,X) and dX = Alpha*dX0. F is the calculation code.\n") + if "DifferentialIncrement" in HO and HO["DifferentialIncrement"] is not None: + msgs += ("\n") + msgs += (__marge + "Reminder: tangent operator is obtained internally by finite differences,\n") + msgs += (__marge + "with a differential increment of value %.2e.\n"%HO["DifferentialIncrement"]) msgs += ("\n") msgs += (__marge + "(Remark: numbers that are (about) under %.0e represent 0 to machine precision)\n"%mpr) print(msgs) # 1 diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 7977635..659e34d 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -587,6 +587,7 @@ class FullOperator(object): avoidingRedundancy = __avoidRC, inputAsMultiFunction = inputAsMF, extraArguments = self.__extraArgs ) + self.__FO["DifferentialIncrement"] = __Function["DifferentialIncrement"] elif isinstance(__Function, dict) and \ ("Direct" in __Function) and ("Tangent" in __Function) and ("Adjoint" in __Function) and \ (__Function["Direct"] is not None) and (__Function["Tangent"] is not None) and (__Function["Adjoint"] is not None): @@ -612,6 +613,7 @@ class FullOperator(object): avoidingRedundancy = __avoidRC, inputAsMultiFunction = inputAsMF, extraArguments = self.__extraArgs ) + self.__FO["DifferentialIncrement"] = None elif asMatrix is not None: if isinstance(__Matrix, str): __Matrix = PlatformInfo.strmatrix2liststr( __Matrix ) @@ -636,6 +638,7 @@ class FullOperator(object): avoidingRedundancy = __avoidRC, inputAsMultiFunction = inputAsMF ) del __matrice + self.__FO["DifferentialIncrement"] = None else: raise ValueError( "The %s object is improperly defined or undefined,"%self.__name+\ diff --git a/test/test6902/Verification_des_Checking_Algorithms.py b/test/test6902/Verification_des_Checking_Algorithms.py index 5b96d99..2485727 100644 --- a/test/test6902/Verification_des_Checking_Algorithms.py +++ b/test/test6902/Verification_des_Checking_Algorithms.py @@ -77,6 +77,25 @@ class Test_Adao(unittest.TestCase): adaopy.setObserver ("CurrentState",Template="ValuePrinter") adaopy.execute() del adaopy + # + for algo in ("AdjointTest", "FunctionTest", "GradientTest", "LinearityTest", "TangentTest"): + print("") + msg = "Algorithme en test : %s"%algo + print(msg+"\n"+"-"*len(msg)) + # + def simulation( arguments ): + _X = arguments + X = numpy.ravel( _X ) + H = numpy.array([[1,0,0],[0,2,0],[0,0,3],[1,2,3]]) + return numpy.dot(H,X) + # + adaopy = adaoBuilder.New() + adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10,"NumberOfRepetition":2, "SetSeed":1000}) + adaopy.setCheckingPoint (Vector = [0,1,2]) + adaopy.setBackgroundError (ScalarSparseMatrix = 1.) + adaopy.setObservationOperator(OneFunction = simulation) + adaopy.execute() + del adaopy #=============================================================================== if __name__ == "__main__":