#
return case.get("Analysis")[-1]
-def almost_equal_vectors(v1, v2):
+def almost_equal_vectors(v1, v2, precision = 1.e-15, msg = ""):
"""Comparaison de deux vecteurs"""
- print "\nMaximum of differences between the two :",max(abs(v2 - v1))
- return max(abs(v2 - v1)) < 1.e-15
+ print " Difference maximale %s: %.2e"%(msg, max(abs(v2 - v1)))
+ return max(abs(v2 - v1)) < precision
# ==============================================================================
if __name__ == "__main__":
"""
xa1 = test1()
xa2 = test2()
- assert almost_equal_vectors( xa1, xa2 )
+ assert almost_equal_vectors( xa1, xa2, msg = "entre les deux" )
import adaoBuilder, numpy
def test1():
"""Verification de la disponibilite de l'ensemble des algorithmes"""
+ Xa = {}
for algo in ("3DVAR", "Blue", "ExtendedBlue", "LinearLeastSquares", "NonLinearLeastSquares", ):
print
msg = "Algorithme en test : %s"%algo
adaopy.setObservationOperator(Matrix = "1 0 0;0 2 0;0 0 3")
adaopy.setObserver("Analysis",Template="ValuePrinter")
adaopy.execute()
+ Xa[algo] = adaopy.get("Analysis")[-1]
del adaopy
#
for algo in ("ExtendedKalmanFilter", "KalmanFilter", "UnscentedKalmanFilter", "4DVAR"):
adaopy.setEvolutionError (ScalarSparseMatrix = 1.)
adaopy.setObserver("Analysis",Template="ValuePrinter")
adaopy.execute()
+ Xa[algo] = adaopy.get("Analysis")[-1]
del adaopy
#
for algo in ("ParticleSwarmOptimization", "QuantileRegression", ):
adaopy.setEvolutionError (ScalarSparseMatrix = 1.)
adaopy.setObserver("Analysis",Template="ValuePrinter")
adaopy.execute()
+ Xa[algo] = adaopy.get("Analysis")[-1]
del adaopy
#
for algo in ("EnsembleBlue", ):
adaopy.execute()
del adaopy
#
+ print
+ msg = "Tests des ecarts"
+ print msg+"\n"+"="*len(msg)
+ verify_similarity_of_algo_results(("3DVAR", "Blue", "ExtendedBlue"), Xa)
+ verify_similarity_of_algo_results(("LinearLeastSquares", "NonLinearLeastSquares"), Xa)
+ verify_similarity_of_algo_results(("ExtendedKalmanFilter", "KalmanFilter", "UnscentedKalmanFilter"), Xa)
+ 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)))
+ return max(abs(v2 - v1)) < precision
+
+def verify_similarity_of_algo_results(serie = [], Xa = {}):
+ print "Camparaisons :"
+ 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,)
+
#===============================================================================
if __name__ == "__main__":
print '\n AUTODIAGNOSTIC \n'