From: Jean-Philippe ARGAUD Date: Thu, 5 Apr 2012 14:20:29 +0000 (+0200) Subject: Allow to set seed in EnsembleBlue and correct object builder X-Git-Tag: V6_5_0~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3aa4a984320eb4d9b1a2d102db24aa8f17c63b46;p=modules%2Fadao.git Allow to set seed in EnsembleBlue and correct object builder --- diff --git a/doc/using.rst b/doc/using.rst index e9417c1..a9b24b6 100644 --- a/doc/using.rst +++ b/doc/using.rst @@ -451,7 +451,12 @@ unused. 10e-5 and it is not recommended to change it. :"EnsembleBlue": - no option + + :SetSeed: + This key allow to give an integer in order to fix the seed of the random + generator used to generate the ensemble. A convenient value is for example + 1000. By default, the seed is left uninitialized, and so use the default + initialization from the computer. :"KalmanFilter": diff --git a/src/daComposant/daAlgorithms/EnsembleBlue.py b/src/daComposant/daAlgorithms/EnsembleBlue.py index 678609a..521060b 100644 --- a/src/daComposant/daAlgorithms/EnsembleBlue.py +++ b/src/daComposant/daAlgorithms/EnsembleBlue.py @@ -42,6 +42,15 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): logging.debug("%s Lancement"%self._name) logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("Mo"))) # + # Paramètres de pilotage + # ---------------------- + # Potentiels : "SetSeed" + if Parameters.has_key("SetSeed"): + numpy.random.seed(int(Parameters["SetSeed"])) + logging.debug("%s Graine fixee pour le generateur aleatoire = %s"%(self._name, int(Parameters["SetSeed"]))) + else: + logging.debug("%s Graine quelconque pour le generateur aleatoire"%(self._name, )) + # # Nombre d'ensemble pour l'ébauche # -------------------------------- nb_ens = Xb.stepnumber() diff --git a/src/daComposant/daCore/AssimilationStudy.py b/src/daComposant/daCore/AssimilationStudy.py index 4d4458a..3a55a04 100644 --- a/src/daComposant/daCore/AssimilationStudy.py +++ b/src/daComposant/daCore/AssimilationStudy.py @@ -120,7 +120,12 @@ class AssimilationStudy: else: self.__Xb = numpy.matrix( asVector, numpy.float ).T elif asPersistentVector is not None: - self.__Xb = asPersistentVector + if type(asPersistentVector) in [type([]),type(()),type(numpy.array([])),type(numpy.matrix([]))]: + self.__Xb = Persistence.OneVector("Background", basetype=numpy.matrix) + for member in asPersistentVector: + self.__Xb.store( numpy.matrix( numpy.asarray(member).flatten(), numpy.float ).T ) + else: + self.__Xb = asPersistentVector else: raise ValueError("Error: improperly defined background") if toBeStored: @@ -533,7 +538,14 @@ class AssimilationStudy: raise ValueError("Shape characteristic of H \"%s\" and R \"%s\" are incompatible"%(__H_shape,__R_shape)) # if self.__B is not None and len(self.__B) > 0 and not( __B_shape[1] == max(__Xb_shape) ): - raise ValueError("Shape characteristic of B \"%s\" and Xb \"%s\" are incompatible"%(__B_shape,__Xb_shape)) + if self.__StoredInputs["AlgorithmName"] in ["EnsembleBlue",]: + asPersistentVector = self.__Xb.reshape((-1,min(__B_shape))) + self.__Xb = Persistence.OneVector("Background", basetype=numpy.matrix) + for member in asPersistentVector: + self.__Xb.store( numpy.matrix( numpy.asarray(member).flatten(), numpy.float ).T ) + __Xb_shape = min(__B_shape) + else: + raise ValueError("Shape characteristic of B \"%s\" and Xb \"%s\" are incompatible"%(__B_shape,__Xb_shape)) # if self.__R is not None and len(self.__R) > 0 and not( __R_shape[1] == max(__Y_shape) ): raise ValueError("Shape characteristic of R \"%s\" and Y \"%s\" are incompatible"%(__R_shape,__Y_shape))