From 1c355401c5031b1edac8de3ad164fdd4c1b0ab08 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Thu, 1 Apr 2021 06:44:18 +0200 Subject: [PATCH] Minor improvements and fixes for internal variables --- src/daComposant/daAlgorithms/Blue.py | 7 +++++++ src/daComposant/daAlgorithms/ExtendedBlue.py | 7 +++++++ src/daComposant/daCore/BasicObjects.py | 2 ++ src/daComposant/daCore/ExtendedLogging.py | 4 ++-- src/daComposant/daCore/NumericObjects.py | 5 ++--- src/daComposant/daCore/PlatformInfo.py | 6 ++++++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/daComposant/daAlgorithms/Blue.py b/src/daComposant/daAlgorithms/Blue.py index 5c95446..c6284da 100644 --- a/src/daComposant/daAlgorithms/Blue.py +++ b/src/daComposant/daAlgorithms/Blue.py @@ -58,6 +58,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): "MahalanobisConsistency", "OMA", "OMB", + "SampledStateForQuantiles", "SigmaBck2", "SigmaObs2", "SimulatedObservationAtBackground", @@ -215,19 +216,23 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self.StoredVariables["MahalanobisConsistency"].store( float( 2.*J/d.size ) ) if self._toStore("SimulationQuantiles"): nech = self._parameters["NumberOfSamplesForQuantiles"] + EXr = None YfQ = None for i in range(nech): if self._parameters["SimulationForQuantiles"] == "Linear": dXr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A) - Xa.A1).T dYr = numpy.matrix(numpy.ravel( Hm * dXr )).T Yr = HXa + dYr + if selfA._toStore("SampledStateForQuantiles"): Xr = Xa+dXr elif self._parameters["SimulationForQuantiles"] == "NonLinear": Xr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A)).T Yr = numpy.matrix(numpy.ravel( Hm * Xr )).T if YfQ is None: YfQ = Yr + if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.ravel(Xr) else: YfQ = numpy.hstack((YfQ,Yr)) + if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.vstack((EXr,numpy.ravel(Xr))) YfQ.sort(axis=-1) YQ = None for quantile in self._parameters["Quantiles"]: @@ -236,6 +241,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if YQ is None: YQ = YfQ[:,indice] else: YQ = numpy.hstack((YQ,YfQ[:,indice])) self.StoredVariables["SimulationQuantiles"].store( YQ ) + if selfA._toStore("SampledStateForQuantiles"): + selfA.StoredVariables["SampledStateForQuantiles"].store( EXr.T ) if self._toStore("SimulatedObservationAtBackground"): self.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) ) if self._toStore("SimulatedObservationAtCurrentState"): diff --git a/src/daComposant/daAlgorithms/ExtendedBlue.py b/src/daComposant/daAlgorithms/ExtendedBlue.py index 10fadc2..c0f9892 100644 --- a/src/daComposant/daAlgorithms/ExtendedBlue.py +++ b/src/daComposant/daAlgorithms/ExtendedBlue.py @@ -58,6 +58,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): "MahalanobisConsistency", "OMA", "OMB", + "SampledStateForQuantiles", "SigmaBck2", "SigmaObs2", "SimulatedObservationAtBackground", @@ -218,19 +219,23 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): nech = self._parameters["NumberOfSamplesForQuantiles"] HtM = HO["Tangent"].asMatrix(ValueForMethodForm = Xa) HtM = HtM.reshape(Y.size,Xa.size) # ADAO & check shape + EXr = None YfQ = None for i in range(nech): if self._parameters["SimulationForQuantiles"] == "Linear": dXr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A) - Xa.A1).T dYr = numpy.matrix(numpy.ravel( HtM * dXr )).T Yr = HXa + dYr + if selfA._toStore("SampledStateForQuantiles"): Xr = Xa+dXr elif self._parameters["SimulationForQuantiles"] == "NonLinear": Xr = numpy.matrix(numpy.random.multivariate_normal(Xa.A1,A)).T Yr = numpy.matrix(numpy.ravel( H( Xr ) )).T if YfQ is None: YfQ = Yr + if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.ravel(Xr) else: YfQ = numpy.hstack((YfQ,Yr)) + if selfA._toStore("SampledStateForQuantiles"): EXr = numpy.vstack((EXr,numpy.ravel(Xr))) YfQ.sort(axis=-1) YQ = None for quantile in self._parameters["Quantiles"]: @@ -239,6 +244,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if YQ is None: YQ = YfQ[:,indice] else: YQ = numpy.hstack((YQ,YfQ[:,indice])) self.StoredVariables["SimulationQuantiles"].store( YQ ) + if selfA._toStore("SampledStateForQuantiles"): + selfA.StoredVariables["SampledStateForQuantiles"].store( EXr.T ) if self._toStore("SimulatedObservationAtBackground"): self.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) ) if self._toStore("SimulatedObservationAtCurrentState"): diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 1a37c00..a4867f9 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -624,6 +624,7 @@ class Algorithm(object): - OMB : Observation moins Background : Y - Xb - ForecastState : état prédit courant lors d'itérations - Residu : dans le cas des algorithmes de vérification + - SampledStateForQuantiles : échantillons d'états pour l'estimation des quantiles - SigmaBck2 : indicateur de correction optimale des erreurs d'ébauche - SigmaObs2 : indicateur de correction optimale des erreurs d'observation - SimulatedObservationAtBackground : l'état observé H(Xb) à l'ébauche @@ -681,6 +682,7 @@ class Algorithm(object): self.StoredVariables["OMA"] = Persistence.OneVector(name = "OMA") self.StoredVariables["OMB"] = Persistence.OneVector(name = "OMB") self.StoredVariables["Residu"] = Persistence.OneScalar(name = "Residu") + self.StoredVariables["SampledStateForQuantiles"] = Persistence.OneMatrix(name = "SampledStateForQuantiles") self.StoredVariables["SigmaBck2"] = Persistence.OneScalar(name = "SigmaBck2") self.StoredVariables["SigmaObs2"] = Persistence.OneScalar(name = "SigmaObs2") self.StoredVariables["SimulatedObservationAtBackground"] = Persistence.OneVector(name = "SimulatedObservationAtBackground") diff --git a/src/daComposant/daCore/ExtendedLogging.py b/src/daComposant/daCore/ExtendedLogging.py index c67f030..5349e14 100644 --- a/src/daComposant/daCore/ExtendedLogging.py +++ b/src/daComposant/daCore/ExtendedLogging.py @@ -34,7 +34,7 @@ import ExtendedLogging ; ExtendedLogging.ExtendedLogging(level=20) On peut éventuellement demander à l'objet de sortir aussi les messages dans - un fichier (noms par défaut : Aidsm.log, niveau NOTSET) : + un fichier (noms par défaut : AdaoOutputLogfile.log, niveau NOTSET) : import ExtendedLogging ; ExtendedLogging.ExtendedLogging().setLogfile() Si on veut changer le nom du fichier ou le niveau global de message, il faut @@ -79,7 +79,7 @@ import functools import time from daCore import PlatformInfo -LOGFILE = os.path.join(os.path.abspath(os.curdir),"AssimilationStudy.log") +LOGFILE = os.path.join(os.path.abspath(os.curdir),"AdaoOutputLogfile.log") # ============================================================================== class ExtendedLogging(object): diff --git a/src/daComposant/daCore/NumericObjects.py b/src/daComposant/daCore/NumericObjects.py index 5089c21..e9e274d 100644 --- a/src/daComposant/daCore/NumericObjects.py +++ b/src/daComposant/daCore/NumericObjects.py @@ -599,9 +599,6 @@ def enks(selfA, Xb, Y, U, HO, EM, CM, R, B, Q, VariantM="EnKS16-KalmanFilterForm EnKS """ # - # Initialisations - # --------------- - # # Opérateurs H = HO["Direct"].appliedControledFormTo # @@ -616,6 +613,7 @@ def enks(selfA, Xb, Y, U, HO, EM, CM, R, B, Q, VariantM="EnKS16-KalmanFilterForm # Précalcul des inversions de B et R RIdemi = R.sqrtmI() # + # Durée d'observation et tailles LagL = selfA._parameters["SmootherLagL"] if (not hasattr(Y,"store")) or (not hasattr(Y,"stepnumber")): raise ValueError("Fixed-lag smoother requires a series of observation") @@ -723,6 +721,7 @@ def enks(selfA, Xb, Y, U, HO, EM, CM, R, B, Q, VariantM="EnKS16-KalmanFilterForm raise ValueError("VariantM has to be chosen in the authorized methods list.") # selfA.StoredVariables["CurrentIterationNumber"].store( len(selfA.StoredVariables["Analysis"]) ) + # ---> avec analysis selfA.StoredVariables["Analysis"].store( Xa ) if selfA._toStore("APosterioriCovariance"): selfA.StoredVariables["APosterioriCovariance"].store( EnsembleErrorCovariance(EXn) ) diff --git a/src/daComposant/daCore/PlatformInfo.py b/src/daComposant/daCore/PlatformInfo.py index 45eafee..950e0bb 100644 --- a/src/daComposant/daCore/PlatformInfo.py +++ b/src/daComposant/daCore/PlatformInfo.py @@ -116,6 +116,12 @@ class PlatformInfo(object): __msg += "\n%s%30s : %s" %(__prefix,"sys.getfilesystemencoding",str(sys.getfilesystemencoding())) __msg += "\n%s%30s : %s" %(__prefix,"locale.getdefaultlocale",str(locale.getdefaultlocale())) __msg += "\n" + __msg += "\n%s%30s : %s" %(__prefix,"os.cpu_count",os.cpu_count()) + if hasattr(os, 'sched_getaffinity'): + __msg += "\n%s%30s : %s" %(__prefix,"len(os.sched_getaffinity(0))",len(os.sched_getaffinity(0))) + else: + __msg += "\n%s%30s : %s" %(__prefix,"len(os.sched_getaffinity(0))","Unsupported on this platform") + __msg += "\n" __msg += "\n%s%30s : %s" %(__prefix,"platform.node",platform.node()) __msg += "\n%s%30s : %s" %(__prefix,"os.path.expanduser",os.path.expanduser('~')) return __msg -- 2.39.2