From a58de8683d9a3187be2498544eb17b20b7f7ed22 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Thu, 3 Oct 2013 10:40:59 +0200 Subject: [PATCH] Updating some examples --- examples/daSalome/Makefile.am | 2 + .../test001_ADAO_JDC_using_strings.comm | 9 ++- .../test002_ADAO_JDC_using_strings.comm | 9 ++- .../test008_ADAO_Elementary_GradientTest.comm | 17 +++++ .../test009_ADAO_Simple_GradientTest.comm | 7 +- .../test010_ADAO_Simple_AdjointTest.comm | 7 +- .../ADAO_Case.comm.in | 4 +- .../Physical_simulation_functions.py | 64 ++----------------- .../Script_AlgorithmParameters.py | 1 + .../Script_ObservationError_R.py | 4 +- .../Script_Observation_yo.py | 4 +- .../Script_UserPostAnalysis.py | 10 ++- 12 files changed, 65 insertions(+), 73 deletions(-) create mode 100644 examples/daSalome/test008_ADAO_Elementary_GradientTest.comm diff --git a/examples/daSalome/Makefile.am b/examples/daSalome/Makefile.am index 0dc2403..ef667f0 100644 --- a/examples/daSalome/Makefile.am +++ b/examples/daSalome/Makefile.am @@ -37,6 +37,7 @@ DATA_INST = \ test006_Observers_init.py \ test006_Observers_Observation_Operator.py \ test006_Observers_var.py \ + test008_ADAO_Elementary_GradientTest.comm \ test009_ADAO_Simple_GradientTest.comm \ test010_ADAO_Simple_AdjointTest.comm @@ -59,5 +60,6 @@ EXTRA_DIST = \ test006_Observers_init.py \ test006_Observers_Observation_Operator.py \ test006_Observers_var.py \ + test008_ADAO_Elementary_GradientTest.comm \ test009_ADAO_Simple_GradientTest.comm \ test010_ADAO_Simple_AdjointTest.comm diff --git a/examples/daSalome/test001_ADAO_JDC_using_strings.comm b/examples/daSalome/test001_ADAO_JDC_using_strings.comm index 8caf22b..4196350 100644 --- a/examples/daSalome/test001_ADAO_JDC_using_strings.comm +++ b/examples/daSalome/test001_ADAO_JDC_using_strings.comm @@ -21,4 +21,11 @@ ASSIMILATION_STUDY(Study_name='Test', ObservationOperator=_F(Stored=0, INPUT_TYPE='Matrix', data=_F(FROM='String', - STRING='1 0 0 ; 0 1 0 ; 0 0 1',),),); + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + UserPostAnalysis=_F(FROM='Template', + Template='AnalysisPrinter', + ValueTemplate= + """import numpy +xa=numpy.ravel(ADD.get('Analysis')[-1]) +print 'Analysis:',xa""",),); +#CHECKSUM:05af4155253fa5540d31e30d50b2b2b3 -:FIN CHECKSUM \ No newline at end of file diff --git a/examples/daSalome/test002_ADAO_JDC_using_strings.comm b/examples/daSalome/test002_ADAO_JDC_using_strings.comm index afbde56..efb2bbd 100644 --- a/examples/daSalome/test002_ADAO_JDC_using_strings.comm +++ b/examples/daSalome/test002_ADAO_JDC_using_strings.comm @@ -21,4 +21,11 @@ ASSIMILATION_STUDY(Study_name='Test', ObservationOperator=_F(Stored=0, INPUT_TYPE='Matrix', data=_F(FROM='String', - STRING='1 0 0 ; 0 1 0 ; 0 0 1',),),); + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + UserPostAnalysis=_F(FROM='Template', + Template='AnalysisPrinter', + ValueTemplate= + """import numpy +xa=numpy.ravel(ADD.get('Analysis')[-1]) +print 'Analysis:',xa""",),); +#CHECKSUM:17bc9d8f671d897f163b094a1e21d53f -:FIN CHECKSUM \ No newline at end of file diff --git a/examples/daSalome/test008_ADAO_Elementary_GradientTest.comm b/examples/daSalome/test008_ADAO_Elementary_GradientTest.comm new file mode 100644 index 0000000..b70cc22 --- /dev/null +++ b/examples/daSalome/test008_ADAO_Elementary_GradientTest.comm @@ -0,0 +1,17 @@ + +CHECKING_STUDY(Study_name='Elementary gradient test', + Study_repertory='/home/ahbhhjp/ADAO', + Debug=0, + Algorithm='GradientTest', + CheckingPoint=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='String', + STRING='1 1 1',),), + ObservationOperator=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + AlgorithmParameters=_F(INPUT_TYPE='Dict', + data=_F(FROM='String', + STRING='{ "SetSeed" : 1000 }',),),); +#CHECKSUM:195fb2032d0dcb0cb5668d4084352fb0 -:FIN CHECKSUM \ No newline at end of file diff --git a/examples/daSalome/test009_ADAO_Simple_GradientTest.comm b/examples/daSalome/test009_ADAO_Simple_GradientTest.comm index dddb3e6..3cc522e 100644 --- a/examples/daSalome/test009_ADAO_Simple_GradientTest.comm +++ b/examples/daSalome/test009_ADAO_Simple_GradientTest.comm @@ -9,5 +9,8 @@ CHECKING_STUDY(Study_name='Test', ObservationOperator=_F(Stored=0, INPUT_TYPE='Matrix', data=_F(FROM='String', - STRING='1 0 0 ; 0 1 0 ; 0 0 1 ; 1 0 0 ; 0 1 0 ; 0 0 1',),),); -#CHECKSUM:68032af53e12f34f4d709332ef02b294 -:FIN CHECKSUM \ No newline at end of file + STRING='1 0 0 ; 0 1 0 ; 0 0 1 ; 1 0 0 ; 0 1 0 ; 0 0 1',),), + AlgorithmParameters=_F(INPUT_TYPE='Dict', + data=_F(FROM='String', + STRING='{ "SetSeed" : 1000 }',),),); +#CHECKSUM:b61b9cb1c617749ecfcf3fbfa3fadde1 -:FIN CHECKSUM \ No newline at end of file diff --git a/examples/daSalome/test010_ADAO_Simple_AdjointTest.comm b/examples/daSalome/test010_ADAO_Simple_AdjointTest.comm index aac3dc0..07f4668 100644 --- a/examples/daSalome/test010_ADAO_Simple_AdjointTest.comm +++ b/examples/daSalome/test010_ADAO_Simple_AdjointTest.comm @@ -9,5 +9,8 @@ CHECKING_STUDY(Study_name='Test', ObservationOperator=_F(Stored=0, INPUT_TYPE='Matrix', data=_F(FROM='String', - STRING='1 0 0 ; 0 1 0 ; 0 0 1 ; 1 0 0 ; 0 1 0 ; 0 0 1',),),); -#CHECKSUM:f57c937e2c8bbc8e3f96a4b0ab10b907 -:FIN CHECKSUM \ No newline at end of file + STRING='1 0 0 ; 0 1 0 ; 0 0 1 ; 1 0 0 ; 0 1 0 ; 0 0 1',),), + AlgorithmParameters=_F(INPUT_TYPE='Dict', + data=_F(FROM='String', + STRING='{ "SetSeed" : 1000 }',),),); +#CHECKSUM:66b339da11b97e97e44e775a4cdb1824 -:FIN CHECKSUM \ No newline at end of file diff --git a/examples/daSkeletons/External_data_definition_by_scripts/ADAO_Case.comm.in b/examples/daSkeletons/External_data_definition_by_scripts/ADAO_Case.comm.in index 9752c17..f4cf10f 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/ADAO_Case.comm.in +++ b/examples/daSkeletons/External_data_definition_by_scripts/ADAO_Case.comm.in @@ -3,7 +3,7 @@ ASSIMILATION_STUDY(Study_name='ADAO skeleton case', Study_repertory='@prefix@/share/salome/adao_examples/daSkeletons/External_data_definition_by_scripts', Debug=0, Algorithm='3DVAR', - Background=_F(Stored=0, + Background=_F(Stored=1, INPUT_TYPE='Vector', data=_F(FROM='Script', SCRIPT_FILE='Script_Background_xb.py',),), @@ -11,7 +11,7 @@ ASSIMILATION_STUDY(Study_name='ADAO skeleton case', INPUT_TYPE='Matrix', data=_F(FROM='Script', SCRIPT_FILE='Script_BackgroundError_B.py',),), - Observation=_F(Stored=0, + Observation=_F(Stored=1, INPUT_TYPE='Vector', data=_F(FROM='Script', SCRIPT_FILE='Script_Observation_yo.py',),), diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py b/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py index a1fadfc..9d2e281 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py @@ -47,64 +47,12 @@ def DirectOperator( XX ): # --------------------------------------> EXAMPLE TO BE REMOVED # return numpy.array( HX ) -# -def TangentHMatrix( X, increment = 0.01, centeredDF = False ): - """ Tangent operator (Jacobian) calculated by finite differences """ - # - dX = increment * X.A1 - # - if centeredDF: - # - Jacobian = [] - for i in range( len(dX) ): - X_plus_dXi = numpy.array( X.A1 ) - X_plus_dXi[i] = X[i] + dX[i] - X_moins_dXi = numpy.array( X.A1 ) - X_moins_dXi[i] = X[i] - dX[i] - # - HX_plus_dXi = DirectOperator( X_plus_dXi ) - HX_moins_dXi = DirectOperator( X_moins_dXi ) - # - HX_Diff = ( HX_plus_dXi - HX_moins_dXi ) / (2.*dX[i]) - # - Jacobian.append( HX_Diff ) - # - else: - # - HX_plus_dX = [] - for i in range( len(dX) ): - X_plus_dXi = numpy.array( X.A1 ) - X_plus_dXi[i] = X[i] + dX[i] - # - HX_plus_dXi = DirectOperator( X_plus_dXi ) - # - HX_plus_dX.append( HX_plus_dXi ) - # - HX = DirectOperator( X ) - # - Jacobian = [] - for i in range( len(dX) ): - Jacobian.append( ( HX_plus_dX[i] - HX ) / dX[i] ) - # - Jacobian = numpy.matrix( Jacobian ) - # - return Jacobian -# -def TangentOperator( X ): - """ Tangent operator """ - _X = numpy.asmatrix(X).flatten().T - HtX = self.TangentHMatrix( _X ) * _X - return HtX.A1 -# -def AdjointOperator( (X, Y) ): - """ Ajoint operator """ - # - Jacobian = TangentHMatrix( X, centeredDF = False ) - # - Y = numpy.asmatrix(Y).flatten().T - HaY = numpy.dot(Jacobian, Y) - # - return HaY.A1 + +# ============================================================================== +from ApproximatedDerivatives import FDApproximation +FDA = FDApproximation( DirectOperator ) +TangentOperator = FDA.TangentOperator +AdjointOperator = FDA.AdjointOperator # ============================================================================== if __name__ == "__main__": diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_AlgorithmParameters.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_AlgorithmParameters.py index 8d3da3a..c5ce4ae 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_AlgorithmParameters.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_AlgorithmParameters.py @@ -40,6 +40,7 @@ AlgorithmParameters = { [ 0., 4. ], # Bound on the second parameter [ 0., None ], # Bound on the third parameter ], + "StoreInternalVariables":True, } # # ============================================================================== diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationError_R.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationError_R.py index d7f3f6b..3034a12 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationError_R.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationError_R.py @@ -32,11 +32,11 @@ __author__ = "Jean-Philippe ARGAUD" # import sys, os ; sys.path.insert(0,os.path.dirname(os.path.abspath(__file__))) from Physical_data_and_covariance_matrices import True_state, Simple_Matrix -from Physical_simulation_functions import FunctionH +from Physical_simulation_functions import DirectOperator # xt, names = True_state() # -yo = FunctionH( xt ) +yo = DirectOperator( xt ) # R = 0.0001 * Simple_Matrix( size = len(yo) ) # diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_Observation_yo.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_Observation_yo.py index 76e0313..645f422 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_Observation_yo.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_Observation_yo.py @@ -32,11 +32,11 @@ __author__ = "Jean-Philippe ARGAUD" # import sys, os ; sys.path.insert(0,os.path.dirname(os.path.abspath(__file__))) from Physical_data_and_covariance_matrices import True_state -from Physical_simulation_functions import FunctionH +from Physical_simulation_functions import DirectOperator # xt, noms = True_state() # -yo = FunctionH( xt ) +yo = DirectOperator( xt ) # # Creating the required ADAO variable # ----------------------------------- diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py index 61426e8..49de57c 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py @@ -32,6 +32,7 @@ __author__ = "Jean-Philippe ARGAUD" # from Physical_data_and_covariance_matrices import True_state import numpy +numpy.set_printoptions(precision=4) # xt, names = True_state() xa = ADD.get("Analysis")[-1] @@ -41,11 +42,14 @@ J = ADD.get("CostFunctionJ")[:] # Verifying the results by printing # --------------------------------- print -print "xt = %s"%xt -print "xa = %s"%numpy.array(xa) +print "obs = [%s]"%(", ".join(["%.4f"%v for v in ADD.get("Observation").A1])) +print +print "xb = [%s]"%(", ".join(["%.4f"%v for v in ADD.get("Background").A1])) +print "xt = [%s]"%(", ".join(["%.4f"%v for v in numpy.array(xt)])) +print "xa = [%s]"%(", ".join(["%.4f"%v for v in numpy.array(xa)])) print for i in range( len(x_series) ): - print "Step %2i : J = %.5e et X = %s"%(i, J[i], x_series[i]) + print "Step %2i : J = %.4e X = [%s]"%(i, J[i], ", ".join(["%.4f"%v for v in x_series[i]])) print # # ============================================================================== -- 2.39.2