Salome HOME
Test extension for DFO
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 18 Jan 2017 12:51:27 +0000 (13:51 +0100)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 18 Jan 2017 13:07:03 +0000 (14:07 +0100)
test/test6901/Verification_des_Assimilation_Algorithms.py

index ae129611134ed036b6205dd5409cb20f34958492..ab34c37b8f229a469783f67f3e70e6daa0f2726b 100644 (file)
@@ -26,13 +26,13 @@ import adaoBuilder, numpy
 def test1():
     """Verification de la disponibilite de l'ensemble des algorithmes"""
     Xa = {}
-    for algo in ("3DVAR", "Blue", "ExtendedBlue", "LinearLeastSquares", "NonLinearLeastSquares", ):
+    for algo in ("3DVAR", "Blue", "ExtendedBlue", "LinearLeastSquares", "NonLinearLeastSquares", "DerivativeFreeOptimization"):
         print
         msg = "Algorithme en test : %s"%algo
-        print msg+"\n"+"="*len(msg)
+        print msg+"\n"+"-"*len(msg)
         #
         adaopy = adaoBuilder.New()
-        adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10, })
+        adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10, "Bounds":[[-1,10.],[-1,10.],[-1,10.]]})
         adaopy.setBackground         (Vector = [0,1,2])
         adaopy.setBackgroundError    (ScalarSparseMatrix = 1.)
         adaopy.setObservation        (Vector = [0.5,1.5,2.5])
@@ -46,7 +46,7 @@ def test1():
     for algo in ("ExtendedKalmanFilter", "KalmanFilter", "UnscentedKalmanFilter", "4DVAR"):
         print
         msg = "Algorithme en test : %s"%algo
-        print msg+"\n"+"="*len(msg)
+        print msg+"\n"+"-"*len(msg)
         #
         adaopy = adaoBuilder.New()
         adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10, })
@@ -54,9 +54,9 @@ def test1():
         adaopy.setBackgroundError    (ScalarSparseMatrix = 1.)
         adaopy.setObservation        (Vector = [0.5,1.5,2.5])
         adaopy.setObservationError   (DiagonalSparseMatrix = "1 1 1")
-        adaopy.setObservationOperator(Matrix = "1 0 0;0 1 0;0 0 1")
-        adaopy.setEvolutionModel     (Matrix = "1 0 0;0 1 0;0 0 1")
+        adaopy.setObservationOperator(Matrix = "1 0 0;0 2 0;0 0 3")
         adaopy.setEvolutionError     (ScalarSparseMatrix = 1.)
+        adaopy.setEvolutionModel     (Matrix = "1 0 0;0 1 0;0 0 1")
         adaopy.setObserver("Analysis",Template="ValuePrinter")
         adaopy.execute()
         Xa[algo] = adaopy.get("Analysis")[-1]
@@ -65,17 +65,15 @@ def test1():
     for algo in ("ParticleSwarmOptimization", "QuantileRegression", ):
         print
         msg = "Algorithme en test : %s"%algo
-        print msg+"\n"+"="*len(msg)
+        print msg+"\n"+"-"*len(msg)
         #
         adaopy = adaoBuilder.New()
         adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"BoxBounds":3*[[-1,3]], "SetSeed":1000, })
         adaopy.setBackground         (Vector = [0,1,2])
         adaopy.setBackgroundError    (ScalarSparseMatrix = 1.)
         adaopy.setObservation        (Vector = [0.5,1.5,2.5])
-        adaopy.setObservationError   (DiagonalSparseMatrix = "1 1 1")
+        adaopy.setObservationError   (DiagonalSparseMatrix = "1 2 3")
         adaopy.setObservationOperator(Matrix = "1 0 0;0 1 0;0 0 1")
-        adaopy.setEvolutionModel     (Matrix = "1 0 0;0 1 0;0 0 1")
-        adaopy.setEvolutionError     (ScalarSparseMatrix = 1.)
         adaopy.setObserver("Analysis",Template="ValuePrinter")
         adaopy.execute()
         Xa[algo] = adaopy.get("Analysis")[-1]
@@ -84,43 +82,43 @@ def test1():
     for algo in ("EnsembleBlue", ):
         print
         msg = "Algorithme en test : %s"%algo
-        print msg+"\n"+"="*len(msg)
+        print msg+"\n"+"-"*len(msg)
         #
         adaopy = adaoBuilder.New()
         adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"SetSeed":1000, })
         adaopy.setBackground         (VectorSerie = 100*[[0,1,2]])
         adaopy.setBackgroundError    (ScalarSparseMatrix = 1.)
         adaopy.setObservation        (Vector = [0.5,1.5,2.5])
-        adaopy.setObservationError   (DiagonalSparseMatrix = "1 1 1")
+        adaopy.setObservationError   (DiagonalSparseMatrix = "1 2 3")
         adaopy.setObservationOperator(Matrix = "1 0 0;0 1 0;0 0 1")
-        adaopy.setEvolutionModel     (Matrix = "1 0 0;0 1 0;0 0 1")
-        adaopy.setEvolutionError     (ScalarSparseMatrix = 1.)
         adaopy.setObserver("Analysis",Template="ValuePrinter")
         adaopy.execute()
+        Xa[algo] = adaopy.get("Analysis")[-1]
         del adaopy
     #
     print
-    msg = "Tests des ecarts"
+    msg = "Tests des ecarts attendus :"
     print msg+"\n"+"="*len(msg)
-    verify_similarity_of_algo_results(("3DVAR", "Blue", "ExtendedBlue"), Xa)
+    verify_similarity_of_algo_results(("3DVAR", "Blue", "ExtendedBlue", "4DVAR", "DerivativeFreeOptimization"), Xa)
     verify_similarity_of_algo_results(("LinearLeastSquares", "NonLinearLeastSquares"), Xa)
     verify_similarity_of_algo_results(("ExtendedKalmanFilter", "KalmanFilter", "UnscentedKalmanFilter"), Xa)
+    print "  Les resultats obtenus sont corrects."
     print
     #
     return 0
 
 def almost_equal_vectors(v1, v2, precision = 1.e-15, msg = ""):
     """Comparaison de deux vecteurs"""
-    print "  Difference maximale %s: %.2e"%(msg, max(abs(v2 - v1)))
+    print "    Difference maximale %s: %.2e"%(msg, max(abs(v2 - v1)))
     return max(abs(v2 - v1)) < precision
 
 def verify_similarity_of_algo_results(serie = [], Xa = {}):
-    print "Camparaisons :"
+    print "  Comparaisons :"
     for algo1 in serie:
         for algo2 in serie:
             if algo1 is algo2: break
-            assert almost_equal_vectors( Xa[algo1], Xa[algo2], 1.e-5, "entre %s et %s "%(algo1, algo2) )
-    print "Algorithmes dont les resultats sont similaires : %s\n"%(serie,)
+            assert almost_equal_vectors( Xa[algo1], Xa[algo2], 5.e-5, "entre %s et %s "%(algo1, algo2) )
+    print "  Algorithmes dont les resultats sont similaires : %s\n"%(serie,)
 
 #===============================================================================
 if __name__ == "__main__":