From: Jean-Philippe ARGAUD Date: Thu, 28 Dec 2017 18:18:45 +0000 (+0100) Subject: Minor source coherency corrections X-Git-Tag: V8_5_0rc1~38 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c5cb518ea800079e0ca1744f73a21385709972d7;p=modules%2Fadao.git Minor source coherency corrections --- diff --git a/src/daComposant/daAlgorithms/3DVAR.py b/src/daComposant/daAlgorithms/3DVAR.py index 852a2a0..e968200 100644 --- a/src/daComposant/daAlgorithms/3DVAR.py +++ b/src/daComposant/daAlgorithms/3DVAR.py @@ -72,7 +72,33 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): default = [], typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", - listval = ["APosterioriCorrelations", "APosterioriCovariance", "APosterioriStandardDeviations", "APosterioriVariances", "BMA", "OMA", "OMB", "CostFunctionJ", "CostFunctionJb", "CostFunctionJo", "CurrentState", "CurrentOptimum", "IndexOfOptimum", "Innovation", "InnovationAtCurrentState", "CostFunctionJAtCurrentOptimum", "SigmaObs2", "MahalanobisConsistency", "SimulationQuantiles", "SimulatedObservationAtBackground", "SimulatedObservationAtCurrentState", "SimulatedObservationAtOptimum", "SimulatedObservationAtCurrentOptimum"] + listval = [ + "APosterioriCorrelations", + "APosterioriCovariance", + "APosterioriStandardDeviations", + "APosterioriVariances", + "BMA", + "OMA", + "OMB", + "CostFunctionJ", + "CostFunctionJb", + "CostFunctionJo", + "CurrentState", + "CurrentOptimum", + "IndexOfOptimum", + "Innovation", + "InnovationAtCurrentState", + "CostFunctionJAtCurrentOptimum", + "CostFunctionJbAtCurrentOptimum", + "CostFunctionJoAtCurrentOptimum", + "SigmaObs2", + "MahalanobisConsistency", + "SimulationQuantiles", + "SimulatedObservationAtBackground", + "SimulatedObservationAtCurrentState", + "SimulatedObservationAtOptimum", + "SimulatedObservationAtCurrentOptimum", + ] ) self.defineRequiredParameter( name = "Quantiles", @@ -165,6 +191,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if "IndexOfOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "CurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ + "CostFunctionJbAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ + "CostFunctionJoAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "SimulatedObservationAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: IndexMin = numpy.argmin( self.StoredVariables["CostFunctionJ"][nbPreviousSteps:] ) + nbPreviousSteps if "IndexOfOptimum" in self._parameters["StoreSupplementaryCalculations"]: @@ -174,9 +202,11 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if "SimulatedObservationAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( self.StoredVariables["SimulatedObservationAtCurrentState"][IndexMin] ) if "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: + self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) + if "CostFunctionJbAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJb"][IndexMin] ) + if "CostFunctionJoAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJo"][IndexMin] ) - self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) return J # def GradientOfCostFunction(x): diff --git a/src/daComposant/daAlgorithms/4DVAR.py b/src/daComposant/daAlgorithms/4DVAR.py index ca35410..48de48d 100644 --- a/src/daComposant/daAlgorithms/4DVAR.py +++ b/src/daComposant/daAlgorithms/4DVAR.py @@ -86,7 +86,18 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): default = [], typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", - listval = ["BMA", "CurrentState", "CostFunctionJ", "CostFunctionJb", "CostFunctionJo", "IndexOfOptimum", "CurrentOptimum", "CostFunctionJAtCurrentOptimum"] + listval = [ + "BMA", + "CurrentState", + "CostFunctionJ", + "CostFunctionJb", + "CostFunctionJo", + "IndexOfOptimum", + "CurrentOptimum", + "CostFunctionJAtCurrentOptimum", + "CostFunctionJbAtCurrentOptimum", + "CostFunctionJoAtCurrentOptimum", + ] ) self.defineRequiredParameter( # Pas de type name = "Bounds", @@ -199,16 +210,20 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self.StoredVariables["CostFunctionJ" ].store( J ) if "IndexOfOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "CurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ - "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: + "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ + "CostFunctionJbAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ + "CostFunctionJoAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: IndexMin = numpy.argmin( self.StoredVariables["CostFunctionJ"][nbPreviousSteps:] ) + nbPreviousSteps if "IndexOfOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["IndexOfOptimum"].store( IndexMin ) if "CurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CurrentOptimum"].store( self.StoredVariables["CurrentState"][IndexMin] ) if "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: + self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) + if "CostFunctionJbAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJb"][IndexMin] ) + if "CostFunctionJoAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJo"][IndexMin] ) - self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) return J # def GradientOfCostFunction(x): diff --git a/src/daComposant/daAlgorithms/Blue.py b/src/daComposant/daAlgorithms/Blue.py index 8ffcdfb..5c2e761 100644 --- a/src/daComposant/daAlgorithms/Blue.py +++ b/src/daComposant/daAlgorithms/Blue.py @@ -39,7 +39,27 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): default = [], typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", - listval = ["APosterioriCorrelations", "APosterioriCovariance", "APosterioriStandardDeviations", "APosterioriVariances", "BMA", "OMA", "OMB", "CurrentState", "CostFunctionJ", "CostFunctionJb", "CostFunctionJo", "Innovation", "SigmaBck2", "SigmaObs2", "MahalanobisConsistency", "SimulationQuantiles", "SimulatedObservationAtBackground", "SimulatedObservationAtCurrentState", "SimulatedObservationAtOptimum"] + listval = [ + "APosterioriCorrelations", + "APosterioriCovariance", + "APosterioriStandardDeviations", + "APosterioriVariances", + "BMA", + "OMA", + "OMB", + "CurrentState", + "CostFunctionJ", + "CostFunctionJb", + "CostFunctionJo", + "Innovation", + "SigmaBck2", + "SigmaObs2", + "MahalanobisConsistency", + "SimulationQuantiles", + "SimulatedObservationAtBackground", + "SimulatedObservationAtCurrentState", + "SimulatedObservationAtOptimum", + ] ) self.defineRequiredParameter( name = "Quantiles", @@ -80,8 +100,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): Ha = HO["Adjoint"].asMatrix(Xb) Ha = Ha.reshape(Xb.size,Y.size) # ADAO & check shape # - # Utilisation éventuelle d'un vecteur H(Xb) précalculé (sans cout) - # ---------------------------------------------------------------- + # Utilisation éventuelle d'un vecteur H(Xb) précalculé + # ---------------------------------------------------- if HO["AppliedInX"] is not None and "HXb" in HO["AppliedInX"]: HXb = HO["AppliedInX"]["HXb"] else: @@ -128,11 +148,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if self._parameters["StoreInternalVariables"] or \ "CostFunctionJ" in self._parameters["StoreSupplementaryCalculations"] or \ "MahalanobisConsistency" in self._parameters["StoreSupplementaryCalculations"]: - # Jb = float( 0.5 * (Xa - Xb).T * BI * (Xa - Xb) ) Jo = float( 0.5 * oma.T * RI * oma ) J = Jb + Jo - # self.StoredVariables["CostFunctionJb"].store( Jb ) self.StoredVariables["CostFunctionJo"].store( Jo ) self.StoredVariables["CostFunctionJ" ].store( J ) diff --git a/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py b/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py index 548c25f..e54e4c8 100644 --- a/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py +++ b/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py @@ -83,7 +83,25 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): default = [], typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", - listval = ["CurrentState", "CostFunctionJ", "CostFunctionJb", "CostFunctionJo", "CostFunctionJAtCurrentOptimum", "CurrentOptimum", "IndexOfOptimum", "InnovationAtCurrentState", "BMA", "OMA", "OMB", "SimulatedObservationAtBackground", "SimulatedObservationAtCurrentOptimum", "SimulatedObservationAtCurrentState", "SimulatedObservationAtOptimum"] + listval = [ + "CurrentState", + "CostFunctionJ", + "CostFunctionJb", + "CostFunctionJo", + "CostFunctionJAtCurrentOptimum", + "CostFunctionJbAtCurrentOptimum", + "CostFunctionJoAtCurrentOptimum", + "CurrentOptimum", + "IndexOfOptimum", + "InnovationAtCurrentState", + "BMA", + "OMA", + "OMB", + "SimulatedObservationAtBackground", + "SimulatedObservationAtCurrentOptimum", + "SimulatedObservationAtCurrentState", + "SimulatedObservationAtOptimum", + ] ) self.defineRequiredParameter( # Pas de type name = "Bounds", @@ -151,6 +169,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if "IndexOfOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "CurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ + "CostFunctionJbAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ + "CostFunctionJoAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "SimulatedObservationAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: IndexMin = numpy.argmin( self.StoredVariables["CostFunctionJ"][nbPreviousSteps:] ) + nbPreviousSteps if "IndexOfOptimum" in self._parameters["StoreSupplementaryCalculations"]: @@ -160,9 +180,11 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if "SimulatedObservationAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( self.StoredVariables["SimulatedObservationAtCurrentState"][IndexMin] ) if "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: + self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) + if "CostFunctionJbAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJb"][IndexMin] ) + if "CostFunctionJoAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJo"][IndexMin] ) - self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) return J # # Point de démarrage de l'optimisation : Xini = Xb diff --git a/src/daComposant/daAlgorithms/EnsembleBlue.py b/src/daComposant/daAlgorithms/EnsembleBlue.py index 1cc80cd..e74223f 100644 --- a/src/daComposant/daAlgorithms/EnsembleBlue.py +++ b/src/daComposant/daAlgorithms/EnsembleBlue.py @@ -39,7 +39,13 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): default = [], typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", - listval = ["CurrentState", "Innovation", "SimulatedObservationAtBackground", "SimulatedObservationAtCurrentState", "SimulatedObservationAtOptimum"] + listval = [ + "CurrentState", + "Innovation", + "SimulatedObservationAtBackground", + "SimulatedObservationAtCurrentState", + "SimulatedObservationAtOptimum", + ] ) self.defineRequiredParameter( name = "SetSeed", @@ -47,7 +53,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): message = "Graine fixée pour le générateur aléatoire", ) self.requireInputArguments( - mandatory= ("Xb", "Y", "HO", "R", "B" ), + mandatory= ("Xb", "Y", "HO", "R", "B"), ) def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None): diff --git a/src/daComposant/daAlgorithms/ExtendedBlue.py b/src/daComposant/daAlgorithms/ExtendedBlue.py index 5dbfd80..0755e25 100644 --- a/src/daComposant/daAlgorithms/ExtendedBlue.py +++ b/src/daComposant/daAlgorithms/ExtendedBlue.py @@ -39,7 +39,27 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): default = [], typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", - listval = ["APosterioriCorrelations", "APosterioriCovariance", "APosterioriStandardDeviations", "APosterioriVariances", "BMA", "OMA", "OMB", "CurrentState", "CostFunctionJ", "CostFunctionJb", "CostFunctionJo", "Innovation", "SigmaBck2", "SigmaObs2", "MahalanobisConsistency", "SimulationQuantiles", "SimulatedObservationAtBackground", "SimulatedObservationAtCurrentState", "SimulatedObservationAtOptimum"] + listval = [ + "APosterioriCorrelations", + "APosterioriCovariance", + "APosterioriStandardDeviations", + "APosterioriVariances", + "BMA", + "OMA", + "OMB", + "CurrentState", + "CostFunctionJ", + "CostFunctionJb", + "CostFunctionJo", + "Innovation", + "SigmaBck2", + "SigmaObs2", + "MahalanobisConsistency", + "SimulationQuantiles", + "SimulatedObservationAtBackground", + "SimulatedObservationAtCurrentState", + "SimulatedObservationAtOptimum", + ] ) self.defineRequiredParameter( name = "Quantiles", @@ -69,7 +89,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): listval = ["Linear", "NonLinear"] ) self.requireInputArguments( - mandatory= ("Xb", "Y", "HO", "R", "B" ), + mandatory= ("Xb", "Y", "HO", "R", "B"), ) def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None): @@ -88,6 +108,10 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): else: HXb = H( Xb ) HXb = numpy.asmatrix(numpy.ravel( HXb )).T + if Y.size != HXb.size: + raise ValueError("The size %i of observations Y and %i of observed calculation H(X) are different, they have to be identical."%(Y.size,HXb.size)) + if max(Y.shape) != max(HXb.shape): + raise ValueError("The shapes %s of observations Y and %s of observed calculation H(X) are different, they have to be identical."%(Y.shape,HXb.shape)) # # Précalcul des inversions de B et R # ---------------------------------- @@ -96,10 +120,6 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # # Calcul de l'innovation # ---------------------- - if Y.size != HXb.size: - raise ValueError("The size %i of observations Y and %i of observed calculation H(X) are different, they have to be identical."%(Y.size,HXb.size)) - if max(Y.shape) != max(HXb.shape): - raise ValueError("The shapes %s of observations Y and %s of observed calculation H(X) are different, they have to be identical."%(Y.shape,HXb.shape)) d = Y - HXb # # Calcul de la matrice de gain et de l'analyse diff --git a/src/daComposant/daAlgorithms/NonLinearLeastSquares.py b/src/daComposant/daAlgorithms/NonLinearLeastSquares.py index 7cd98ae..f246d55 100644 --- a/src/daComposant/daAlgorithms/NonLinearLeastSquares.py +++ b/src/daComposant/daAlgorithms/NonLinearLeastSquares.py @@ -72,7 +72,26 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): default = [], typecast = tuple, message = "Liste de calculs supplémentaires à stocker et/ou effectuer", - listval = ["BMA", "OMA", "OMB", "CostFunctionJ", "CostFunctionJb", "CostFunctionJo", "CurrentState", "CurrentOptimum", "IndexOfOptimum", "Innovation", "InnovationAtCurrentState", "CostFunctionJAtCurrentOptimum", "SimulatedObservationAtBackground", "SimulatedObservationAtCurrentState", "SimulatedObservationAtOptimum", "SimulatedObservationAtCurrentOptimum"] + listval = [ + "BMA", + "OMA", + "OMB", + "CostFunctionJ", + "CostFunctionJb", + "CostFunctionJo", + "CurrentState", + "CurrentOptimum", + "IndexOfOptimum", + "Innovation", + "InnovationAtCurrentState", + "CostFunctionJAtCurrentOptimum", + "CostFunctionJbAtCurrentOptimum", + "CostFunctionJoAtCurrentOptimum", + "SimulatedObservationAtBackground", + "SimulatedObservationAtCurrentState", + "SimulatedObservationAtOptimum", + "SimulatedObservationAtCurrentOptimum", + ] ) self.defineRequiredParameter( # Pas de type name = "Bounds", @@ -139,6 +158,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if "IndexOfOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "CurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ + "CostFunctionJbAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ + "CostFunctionJoAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"] or \ "SimulatedObservationAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: IndexMin = numpy.argmin( self.StoredVariables["CostFunctionJ"][nbPreviousSteps:] ) + nbPreviousSteps if "IndexOfOptimum" in self._parameters["StoreSupplementaryCalculations"]: @@ -148,9 +169,11 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if "SimulatedObservationAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( self.StoredVariables["SimulatedObservationAtCurrentState"][IndexMin] ) if "CostFunctionJAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: + self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) + if "CostFunctionJbAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CostFunctionJbAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJb"][IndexMin] ) + if "CostFunctionJoAtCurrentOptimum" in self._parameters["StoreSupplementaryCalculations"]: self.StoredVariables["CostFunctionJoAtCurrentOptimum"].store( self.StoredVariables["CostFunctionJo"][IndexMin] ) - self.StoredVariables["CostFunctionJAtCurrentOptimum" ].store( self.StoredVariables["CostFunctionJ" ][IndexMin] ) return J # def GradientOfCostFunction(x):