From b09c0d168e7e277a0a007c70e1a809c1d7ca0273 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Ribes?= Date: Fri, 2 Jul 2010 11:25:23 +0200 Subject: [PATCH] Nouveau test Aster LBFGSB --- configure.ac | 1 + src/daSalome/daYacsSchemaCreator/methods.py | 9 ++ src/tests/daSalome/Makefile.am | 4 + src/tests/daSalome/test_aster_zzzz159a.py.in | 61 ++++++++- .../daSalome/test_aster_zzzz159a_LBFGSB.py.in | 119 ++++++++++++++++++ ...st_aster_zzzz159a_init_algorithm_LBFGSB.py | 15 +++ 6 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py.in create mode 100644 src/tests/daSalome/test_aster_zzzz159a_init_algorithm_LBFGSB.py diff --git a/configure.ac b/configure.ac index a7fe04e..5b235e5 100644 --- a/configure.ac +++ b/configure.ac @@ -118,6 +118,7 @@ AC_CONFIG_FILES([ src/tests/daSalome/test017_3DVAR_par_fonction.py src/tests/daSalome/test_aster_zzzz159a_init_parameters.py src/tests/daSalome/test_aster_zzzz159a.py + src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py src/tests/daSalome/zzzz159a.export.esclave src/tests/daComposant/Makefile src/tests/daComposant/Plateforme/Makefile diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index c4f8eef..5f5b967 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -254,6 +254,11 @@ def create_yacs_proc(study_config): else: proc.edAddDFLink(execute_node.getOutputPort("Study"), analysis_node.getInputPort("Study")) + # Connect node with InitUserData + if "Analysis" in init_config["Target"]: + analysis_node.edAddInputPort("init_data", t_pyobj) + proc.edAddDFLink(init_node.getOutputPort("init_data"), analysis_node.getInputPort("init_data")) + elif analysis_config["From"] == "File": factory_analysis_node = catalogAd._nodeMap["SimpleUserAnalysis"] analysis_node = factory_analysis_node.cloneNode("User Analysis") @@ -276,6 +281,10 @@ def create_yacs_proc(study_config): proc.edAddDFLink(optimizer_node.edGetAlgoResultPort(), analysis_node.getInputPort("Study")) else: proc.edAddDFLink(execute_node.getOutputPort("Study"), analysis_node.getInputPort("Study")) + # Connect node with InitUserData + if "Analysis" in init_config["Target"]: + analysis_node.edAddInputPort("init_data", t_pyobj) + proc.edAddDFLink(init_node.getOutputPort("init_data"), analysis_node.getInputPort("init_data")) pass diff --git a/src/tests/daSalome/Makefile.am b/src/tests/daSalome/Makefile.am index 52e5ece..b3b1f65 100644 --- a/src/tests/daSalome/Makefile.am +++ b/src/tests/daSalome/Makefile.am @@ -12,6 +12,8 @@ DATA_INST = \ test_aster_zzzz159a_init_algorithm.py \ test_aster_zzzz159a_init_parameters.py \ test_aster_zzzz159a.py \ + test_aster_zzzz159a_LBFGSB.py \ + test_aster_zzzz159a_init_algorithm_LBFGSB.py \ zzzz159a.3 zzzz159a.export.esclave zzzz159a.mail testsdasalome_DATA = ${DATA_INST} @@ -27,4 +29,6 @@ EXTRA_DIST = test000_Blue_AnalysisCode.py test000_Blue_AnalysisFile.py.in test00 test_aster_zzzz159a_init_algorithm.py \ test_aster_zzzz159a_init_parameters.py.in \ test_aster_zzzz159a.py.in \ + test_aster_zzzz159a_LBFGSB.py.in \ + test_aster_zzzz159a_init_algorithm_LBFGSB.py \ zzzz159a.3 zzzz159a.export.esclave.in zzzz159a.mail diff --git a/src/tests/daSalome/test_aster_zzzz159a.py.in b/src/tests/daSalome/test_aster_zzzz159a.py.in index 98246f3..6b6109b 100644 --- a/src/tests/daSalome/test_aster_zzzz159a.py.in +++ b/src/tests/daSalome/test_aster_zzzz159a.py.in @@ -8,7 +8,7 @@ Init_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_init_paramete Init_config["Type"] = "Dict" Init_config["From"] = "Script" Init_config["Target"] = ["AlgorithmParameters", "Background", "BackgroundError", - "Observation", "ObservationError", "ObservationOperator"] + "Observation", "ObservationError", "ObservationOperator", "Analysis"] study_config["Init"] = Init_config Algorithm_config = {} @@ -57,8 +57,63 @@ Analysis_config = {} Analysis_config["Data"] = """ import numpy -Xa = ADD.get("Analysis").valueserie(0) -print "Analyse = ",Xa +xa = ADD.get("Analysis").valueserie(0) +Innovation = ADD.get("Innovation").valueserie(0) +A = [] +J = ADD.get("CostFunctionJ").valueserie() +# +ADD.setDiagnostic("PlotVectors", "J") +MonPlot = ADD.get("J") +MonPlot.calculate([J,ADD.get("CostFunctionJb").valueserie(),ADD.get("CostFunctionJo").valueserie()], + title = "Fonctionnelles J, Jb et Jo", + ltitle = ["J","Jb","Jo"], + xlabel = "Pas", ylabel = "Valeur", + filename = "recherche_xx_Fonctionnelles.ps", + pause = False ) + + +nbmesures = 11 # De 0 à 1 par pas de 0.1 +instants = numpy.array([0.1*i for i in range(nbmesures)]) +yo = [] +for reponse in init_data['experience']: + for t,v in list(reponse): + if min(abs(t - instants)) < 1.e-8: + yo.append(v) +xb = [] +Bornes = [] +for parametre in init_data['parametres']: + xb.append( parametre[1] ) + Bornes.append( parametre[2:4] ) +B = numpy.matrix(numpy.core.identity(len(xb))) +alpha = 1.e14 +B[0,0] = alpha * 100 +B[1,1] = alpha * 10 +B[2,2] = alpha * 1 + +# Calcul de la RMS +# ---------------- +import test_aster_zzzz159a_aster_functions as Code_Aster +Hxa = Code_Aster.Calcul_Aster_Ponctuel( xa ) +V1 = numpy.array(Hxa) +V2 = numpy.array(yo) +import math +rms = math.sqrt( ((V2 - V1)**2).sum() / float(V1.size) ) + +print +print "=========" +print "Ebauche = ",xb +print "Analyse = ",xa +print "RMS = ",rms +print +print "NbSteps = ",len(J) +print "J = ",J +print +print "B[0,0] = ",B[0,0] +print "B[1,1] = ",B[1,1] +print "B[2,2] = ",B[2,2] +print "Bornes = ",Bornes +print "=========" +print """ Analysis_config["From"] = "String" study_config["Analysis"] = Analysis_config diff --git a/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py.in b/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py.in new file mode 100644 index 0000000..04bfd0e --- /dev/null +++ b/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py.in @@ -0,0 +1,119 @@ +#-*-coding:iso-8859-1-*- +study_config = {} +study_config["Name"] = "test_aster_zzzz159a" +study_config["Algorithm"] = "3DVAR" + +Init_config = {} +Init_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_init_parameters.py" +Init_config["Type"] = "Dict" +Init_config["From"] = "Script" +Init_config["Target"] = ["AlgorithmParameters", "Background", "BackgroundError", + "Observation", "ObservationError", "ObservationOperator", "Analysis"] +study_config["Init"] = Init_config + +Algorithm_config = {} +Algorithm_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_init_algorithm_LBFGSB.py" +Algorithm_config["Type"] = "Dict" +Algorithm_config["From"] = "Script" +study_config["AlgorithmParameters"] = Algorithm_config + +Background_config = {} +Background_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_background.py" +Background_config["Type"] = "Vector" +Background_config["From"] = "Script" +study_config["Background"] = Background_config + +BackgroundError_config = {} +BackgroundError_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_background_error.py" +BackgroundError_config["Type"] = "Matrix" +BackgroundError_config["From"] = "Script" +study_config["BackgroundError"] = BackgroundError_config + +Observation_config = {} +Observation_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_observation.py" +Observation_config["Type"] = "Vector" +Observation_config["From"] = "Script" +study_config["Observation"] = Observation_config + +ObservationError_config = {} +ObservationError_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_observation_error.py" +ObservationError_config["Type"] = "Matrix" +ObservationError_config["From"] = "Script" +study_config["ObservationError"] = ObservationError_config + +FunctionDict = {} +FunctionDict["Function"] = ["Direct", "Tangent", "Adjoint"] +FunctionDict["Script"] = {} +FunctionDict["Script"]["Direct"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" +FunctionDict["Script"]["Tangent"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" +FunctionDict["Script"]["Adjoint"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" +ObservationOperator_config = {} +ObservationOperator_config["Data"] = FunctionDict +ObservationOperator_config["Type"] = "Function" +ObservationOperator_config["From"] = "Dict" +study_config["ObservationOperator"] = ObservationOperator_config + +Analysis_config = {} +Analysis_config["Data"] = """ +import numpy + +xa = ADD.get("Analysis").valueserie(0) +Innovation = ADD.get("Innovation").valueserie(0) +A = [] +J = ADD.get("CostFunctionJ").valueserie() +# +ADD.setDiagnostic("PlotVectors", "J") +MonPlot = ADD.get("J") +MonPlot.calculate([J,ADD.get("CostFunctionJb").valueserie(),ADD.get("CostFunctionJo").valueserie()], + title = "Fonctionnelles J, Jb et Jo", + ltitle = ["J","Jb","Jo"], + xlabel = "Pas", ylabel = "Valeur", + filename = "recherche_xx_Fonctionnelles.ps", + pause = False ) + + +nbmesures = 11 # De 0 à 1 par pas de 0.1 +instants = numpy.array([0.1*i for i in range(nbmesures)]) +yo = [] +for reponse in init_data['experience']: + for t,v in list(reponse): + if min(abs(t - instants)) < 1.e-8: + yo.append(v) +xb = [] +Bornes = [] +for parametre in init_data['parametres']: + xb.append( parametre[1] ) + Bornes.append( parametre[2:4] ) +B = numpy.matrix(numpy.core.identity(len(xb))) +alpha = 1.e14 +B[0,0] = alpha * 100 +B[1,1] = alpha * 10 +B[2,2] = alpha * 1 + +# Calcul de la RMS +# ---------------- +import test_aster_zzzz159a_aster_functions as Code_Aster +Hxa = Code_Aster.Calcul_Aster_Ponctuel( xa ) +V1 = numpy.array(Hxa) +V2 = numpy.array(yo) +import math +rms = math.sqrt( ((V2 - V1)**2).sum() / float(V1.size) ) + +print +print "=========" +print "Ebauche = ",xb +print "Analyse = ",xa +print "RMS = ",rms +print +print "NbSteps = ",len(J) +print "J = ",J +print +print "B[0,0] = ",B[0,0] +print "B[1,1] = ",B[1,1] +print "B[2,2] = ",B[2,2] +print "Bornes = ",Bornes +print "=========" +print +""" +Analysis_config["From"] = "String" +study_config["Analysis"] = Analysis_config diff --git a/src/tests/daSalome/test_aster_zzzz159a_init_algorithm_LBFGSB.py b/src/tests/daSalome/test_aster_zzzz159a_init_algorithm_LBFGSB.py new file mode 100644 index 0000000..68fd1f0 --- /dev/null +++ b/src/tests/daSalome/test_aster_zzzz159a_init_algorithm_LBFGSB.py @@ -0,0 +1,15 @@ +debug = init_data["debug"] +parametres = init_data["parametres"] + +Bornes = [] +for parametre in parametres: + Bornes.append(parametre[2:4]) + +if debug: + print + print "Bornes = ",Bornes + print + +AlgorithmParameters = { "Minimizer" : "LBFSGB", + "Bounds" : Bornes, + } -- 2.39.2