From a47bab7913b44e482fd2ebf14fba216b413ce1f1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Wed, 22 Feb 2023 20:53:45 +0100 Subject: [PATCH] Extending location selection and documentation review --- doc/en/bibliography.rst | 6 +- ...thm_MeasurementsOptimalPositioningTask.rst | 5 ++ doc/en/snippets/ExcludeLocations.rst | 19 ++++-- doc/en/snippets/ExcludedPoints.rst | 9 +++ doc/en/snippets/ModuleCompatibility.rst | 2 +- doc/en/snippets/NameOfLocations.rst | 14 +++++ doc/en/versions.rst | 6 ++ doc/fr/bibliography.rst | 6 +- ...thm_MeasurementsOptimalPositioningTask.rst | 5 ++ doc/fr/snippets/ExcludeLocations.rst | 20 ++++-- doc/fr/snippets/ExcludedPoints.rst | 10 +++ doc/fr/snippets/ModuleCompatibility.rst | 2 +- doc/fr/snippets/NameOfLocations.rst | 15 +++++ doc/fr/versions.rst | 6 ++ src/daComposant/daAlgorithms/Atoms/ecweim.py | 17 ++++- .../daAlgorithms/Atoms/lbfgsb19hlt.py | 6 +- .../daAlgorithms/ExtendedKalmanFilter.py | 3 - .../MeasurementsOptimalPositioningTask.py | 13 ++-- src/daComposant/daCore/BasicObjects.py | 1 + src/daComposant/daCore/NumericObjects.py | 62 +++++++++++++++++++ 20 files changed, 199 insertions(+), 28 deletions(-) create mode 100644 doc/en/snippets/ExcludedPoints.rst create mode 100644 doc/en/snippets/NameOfLocations.rst create mode 100644 doc/fr/snippets/ExcludedPoints.rst create mode 100644 doc/fr/snippets/NameOfLocations.rst diff --git a/doc/en/bibliography.rst b/doc/en/bibliography.rst index 0209a3d..8d887ae 100644 --- a/doc/en/bibliography.rst +++ b/doc/en/bibliography.rst @@ -109,11 +109,13 @@ exhaustive bibliography. .. [Nelder65] Nelder J. A., Mead R., *A simplex method for function minimization*, The Computer Journal, 7, pp.308-313, 1965 +.. [NumPy20] Harris C.R. et al., *Array programming with NumPy*, Nature 585, pp.357–362, 2020, https://numpy.org/ + .. [Powell64] Powell M. J. D., *An efficient method for finding the minimum of a function of several variables without calculating derivatives*, Computer Journal, 7(2), pp.155-162, 1964 .. [Powell94] Powell M. J. D., *A direct search optimization method that models the objective and constraint functions by linear interpolation*, in Advances in Optimization and Numerical Analysis, eds. S. Gomez and J-P Hennart, Kluwer Academic (Dordrecht), pp. 51-67, 1994 -.. [Powell98] Powell M. J. D., *Direct search algorithms for optimization calculations*, Acta Numerica 7, 287-336, 1998 +.. [Powell98] Powell M. J. D., *Direct search algorithms for optimization calculations*, Acta Numerica 7, pp.287-336, 1998 .. [Powell04] Powell M. J. D., *The NEWUOA software for unconstrained optimization without derivatives*, Proc. 40th Workshop on Large Scale Nonlinear Optimization, Erice, Italy, 2004 @@ -135,6 +137,8 @@ exhaustive bibliography. .. [SalomeMeca] *Salome_Meca and Code_Aster, Analysis of Structures and Thermomechanics for Studies & Research*, http://www.code-aster.org/ +.. [SciPy20] Virtanen P. et al., *SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python*, Nature Methods, 17(3), pp.261-272, 2020, https://scipy.org/ + .. [Storn97] Storn R., Price, K., *Differential Evolution – A Simple and Efficient Heuristic for global Optimization over Continuous Spaces*, Journal of Global Optimization, 11(1), pp.341-359, 1997 .. [Tarantola87] Tarantola A., *Inverse Problem: Theory Methods for Data Fitting and Parameter Estimation*, Elsevier, 1987 diff --git a/doc/en/ref_algorithm_MeasurementsOptimalPositioningTask.rst b/doc/en/ref_algorithm_MeasurementsOptimalPositioningTask.rst index 0d305c9..cbab474 100644 --- a/doc/en/ref_algorithm_MeasurementsOptimalPositioningTask.rst +++ b/doc/en/ref_algorithm_MeasurementsOptimalPositioningTask.rst @@ -91,6 +91,8 @@ search. .. include:: snippets/MaximumNumberOfLocations.rst +.. include:: snippets/NameOfLocations.rst + .. include:: snippets/SampleAsExplicitHyperCube.rst .. include:: snippets/SampleAsIndependantRandomVariables.rst @@ -118,6 +120,7 @@ StoreSupplementaryCalculations algorithm*"): [ "EnsembleOfSimulations", "EnsembleOfStates", + "ExcludedPoints", "OptimalPoints", "ReducedBasis", "Residus", @@ -140,6 +143,8 @@ StoreSupplementaryCalculations .. include:: snippets/EnsembleOfStates.rst +.. include:: snippets/ExcludedPoints.rst + .. include:: snippets/OptimalPoints.rst .. include:: snippets/ReducedBasis.rst diff --git a/doc/en/snippets/ExcludeLocations.rst b/doc/en/snippets/ExcludeLocations.rst index 0ccad27..f46a99e 100644 --- a/doc/en/snippets/ExcludeLocations.rst +++ b/doc/en/snippets/ExcludeLocations.rst @@ -1,11 +1,18 @@ .. index:: single: ExcludeLocations ExcludeLocations - *List of integers*. This key specifies the list of points in the state vector - excluded from the optimal search. The default value is an empty list. - Important: the numbering of these excluded points must be identical to the - one implicitly adopted in the states provided by the "*EnsembleOfSnapshots*" - key. + *List of integers or names*. This key specifies the list of points in the + state vector excluded from the optimal search. The default value is an empty + list. The list can contain either **indices of points** (in the implicit + internal order of a state vector) or **names of points** (which must exist in + the list of position names indicated by the keyword "*NameOfLocations*" in + order to be excluded). By default, if the elements of the list are strings + that can be assimilated to indices, then these strings are indeed considered + as indices and not names. + + Important notice: the numbering of these excluded points must be identical to + that adopted, implicitly and imperatively, by the variables constituting a + state considered arbitrarily in one-dimensional form. Example : - ``{"ExcludeLocations":[3, 125, 286]}`` + ``{"ExcludeLocations":[3, 125, 286]}`` or ``{"ExcludeLocations":["Point3", "XgTaC"]}`` diff --git a/doc/en/snippets/ExcludedPoints.rst b/doc/en/snippets/ExcludedPoints.rst new file mode 100644 index 0000000..5a9a6ad --- /dev/null +++ b/doc/en/snippets/ExcludedPoints.rst @@ -0,0 +1,9 @@ +.. index:: single: ExcludedPoints + +ExcludedPoints + *List of integer series*. Each element is a series, containing the indices of + the points excluded from the optimal search, according to the order of the + variables of a state vector considered arbitrarily in one-dimensional form. + + Example : + ``mp = ADD.get("ExcludedPoints")[-1]`` diff --git a/doc/en/snippets/ModuleCompatibility.rst b/doc/en/snippets/ModuleCompatibility.rst index 1fb912a..1138bf9 100644 --- a/doc/en/snippets/ModuleCompatibility.rst +++ b/doc/en/snippets/ModuleCompatibility.rst @@ -15,6 +15,6 @@ guarantee). Python, 3.6.5, 3.10.9 Numpy, 1.14.3, 1.24.2 Scipy, 1.1.0, 1.10.0 - MatplotLib, 2.2.2, 3.6.3 + MatplotLib, 2.2.2, 3.7.0 GnuplotPy, 1.8, 1.8 NLopt, 2.4.2, 2.7.1 diff --git a/doc/en/snippets/NameOfLocations.rst b/doc/en/snippets/NameOfLocations.rst new file mode 100644 index 0000000..9684913 --- /dev/null +++ b/doc/en/snippets/NameOfLocations.rst @@ -0,0 +1,14 @@ +.. index:: single: NameOfLocations + +NameOfLocations + *List of names*. This key indicates an explicit list of variable names or + positions, positioned as in a state vector considered arbitrarily in + one-dimensional form. The default value is an empty list. To be used, this + list must have the same length as that of a physical state. + + Important notice: the order of the names is, implicitly and imperatively, the + same as that of the variables constituting a state considered arbitrarily in + one-dimensional form. + + Example : + ``{"NameOfLocations":["Point3", "Location42", "Position125", "XgTaC"]}`` diff --git a/doc/en/versions.rst b/doc/en/versions.rst index 997b8d3..552ae86 100644 --- a/doc/en/versions.rst +++ b/doc/en/versions.rst @@ -171,6 +171,12 @@ operator script files has to be modified. Versions of ADAO compatibility with support tools ------------------------------------------------- +The module benefits greatly from the **Python environment** [Python]_ and the +multiple features of this language, from the scientific calculation tools +included in **NumPy** [NumPy20]_, **SciPy** [SciPy20]_, **NLopt** [Johnson08]_ +or in the tools that can be reached with them, and from the numerous +capabilities of **SALOME** [Salome]_ when used in combination. + .. include:: snippets/ModuleValidation.rst .. include:: snippets/ModuleCompatibility.rst diff --git a/doc/fr/bibliography.rst b/doc/fr/bibliography.rst index cfa505a..9479d74 100644 --- a/doc/fr/bibliography.rst +++ b/doc/fr/bibliography.rst @@ -109,11 +109,13 @@ néanmoins d'intention de constituer une bibliographie exhaustive. .. [Nelder65] Nelder J. A., Mead R., *A simplex method for function minimization*, The Computer Journal, 7, pp.308-313, 1965 +.. [NumPy20] Harris C.R. et al., *Array programming with NumPy*, Nature 585, pp.357–362, 2020, https://numpy.org/ + .. [Powell64] Powell M. J. D., *An efficient method for finding the minimum of a function of several variables without calculating derivatives*, Computer Journal, 7(2), pp.155-162, 1964 .. [Powell94] Powell M. J. D., *A direct search optimization method that models the objective and constraint functions by linear interpolation*, in Advances in Optimization and Numerical Analysis, eds. S. Gomez and J-P Hennart, Kluwer Academic (Dordrecht), pp. 51-67, 1994 -.. [Powell98] Powell M. J. D., *Direct search algorithms for optimization calculations*, Acta Numerica 7, 287-336, 1998 +.. [Powell98] Powell M. J. D., *Direct search algorithms for optimization calculations*, Acta Numerica 7, pp.287-336, 1998 .. [Powell04] Powell M. J. D., *The NEWUOA software for unconstrained optimization without derivatives*, Proc. 40th Workshop on Large Scale Nonlinear Optimization, Erice, Italy, 2004 @@ -135,6 +137,8 @@ néanmoins d'intention de constituer une bibliographie exhaustive. .. [SalomeMeca] *Salome_Meca et Code_Aster, Analyse des Structures et Thermomécanique pour les Etudes et la Recherche*, http://www.code-aster.org/ +.. [SciPy20] Virtanen P. et al., *SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python*, Nature Methods, 17(3), pp.261-272, 2020, https://scipy.org/ + .. [Storn97] Storn R., Price, K., *Differential Evolution – A Simple and Efficient Heuristic for global Optimization over Continuous Spaces*, Journal of Global Optimization, 11(1), pp.341-359, 1997 .. [Tarantola87] Tarantola A., *Inverse Problem: Theory Methods for Data Fitting and Parameter Estimation*, Elsevier, 1987 diff --git a/doc/fr/ref_algorithm_MeasurementsOptimalPositioningTask.rst b/doc/fr/ref_algorithm_MeasurementsOptimalPositioningTask.rst index b862906..5fcdc3f 100644 --- a/doc/fr/ref_algorithm_MeasurementsOptimalPositioningTask.rst +++ b/doc/fr/ref_algorithm_MeasurementsOptimalPositioningTask.rst @@ -93,6 +93,8 @@ recherche de positionnement contraint. .. include:: snippets/MaximumNumberOfLocations.rst +.. include:: snippets/NameOfLocations.rst + .. include:: snippets/SampleAsExplicitHyperCube.rst .. include:: snippets/SampleAsIndependantRandomVariables.rst @@ -120,6 +122,7 @@ StoreSupplementaryCalculations "*Informations et variables disponibles à la fin de l'algorithme*") : [ "EnsembleOfSimulations", "EnsembleOfStates", + "ExcludedPoints", "OptimalPoints", "ReducedBasis", "Residus", @@ -142,6 +145,8 @@ StoreSupplementaryCalculations .. include:: snippets/EnsembleOfStates.rst +.. include:: snippets/ExcludedPoints.rst + .. include:: snippets/OptimalPoints.rst .. include:: snippets/ReducedBasis.rst diff --git a/doc/fr/snippets/ExcludeLocations.rst b/doc/fr/snippets/ExcludeLocations.rst index 47cf1b2..b35564a 100644 --- a/doc/fr/snippets/ExcludeLocations.rst +++ b/doc/fr/snippets/ExcludeLocations.rst @@ -1,11 +1,19 @@ .. index:: single: ExcludeLocations ExcludeLocations - *Liste d'entiers*. Cette clé indique la liste des points du vecteur d'état - exclus de la recherche optimale. La valeur par défaut est une liste vide. - Important : la numérotation de ces points exclus doit être identique à celle - qui est adoptée implicitement dans les états fournis par la clé - "*EnsembleOfSnapshots*". + *Liste d'entiers ou de noms*. Cette clé indique la liste des points du + vecteur d'état exclus de la recherche optimale. La valeur par défaut est une + liste vide. La liste peut contenir soit des **indices de points** (dans + l'ordre interne implicite d'un vecteur d'état), soit des **noms des points** + (qui doivent exister dans la liste des noms de positions indiquées par le + mot-clé "*NameOfLocations*" pour pouvoir être exclus). Par défaut, si les + éléments de la liste sont des chaînes de caractères assimilables à des + indices, alors ces chaînes sont bien considérées comme des indices et pas des + noms. + + Rappel important : la numérotation de ces points exclus doit être identique à + celle qui est adoptée, implicitement et impérativement, par les variables + constituant un état considéré arbitrairement sous forme unidimensionnelle. Exemple : - ``{"ExcludeLocations":[3, 125, 286]}`` + ``{"ExcludeLocations":[3, 125, 286]}`` ou ``{"ExcludeLocations":["Point3", "XgTaC"]}`` diff --git a/doc/fr/snippets/ExcludedPoints.rst b/doc/fr/snippets/ExcludedPoints.rst new file mode 100644 index 0000000..280c8a2 --- /dev/null +++ b/doc/fr/snippets/ExcludedPoints.rst @@ -0,0 +1,10 @@ +.. index:: single: ExcludedPoints + +ExcludedPoints + *Liste de série d'entiers*. Chaque élément est une série, contenant les + indices des points exclus de la recherche optimale, selon l'ordre des + variables d'un vecteur d'état considéré arbitrairement sous forme + unidimensionnelle. + + Exemple : + ``mp = ADD.get("ExcludedPoints")[-1]`` diff --git a/doc/fr/snippets/ModuleCompatibility.rst b/doc/fr/snippets/ModuleCompatibility.rst index cbe7325..b9adf27 100644 --- a/doc/fr/snippets/ModuleCompatibility.rst +++ b/doc/fr/snippets/ModuleCompatibility.rst @@ -15,6 +15,6 @@ la version atteinte (mais cela reste sans garantie). Python, 3.6.5, 3.10.9 Numpy, 1.14.3, 1.24.2 Scipy, 1.1.0, 1.10.0 - MatplotLib, 2.2.2, 3.6.3 + MatplotLib, 2.2.2, 3.7.0 GnuplotPy, 1.8, 1.8 NLopt, 2.4.2, 2.7.1 diff --git a/doc/fr/snippets/NameOfLocations.rst b/doc/fr/snippets/NameOfLocations.rst new file mode 100644 index 0000000..e9d4a1c --- /dev/null +++ b/doc/fr/snippets/NameOfLocations.rst @@ -0,0 +1,15 @@ +.. index:: single: NameOfLocations + +NameOfLocations + *Liste de noms*. Cette clé indique une liste explicite de noms des variables + ou de positions, positionnées comme dans un vecteur d'état considéré + arbitrairement sous forme unidimensionnelle. La valeur par défaut est une + liste vide. Pour être utilisée, cette liste doit avoir la même longueur que + celle d'un état physique. + + Rappel important : l'ordre des noms est, implicitement et impérativement, le + même que celui des variables constituant un état considéré arbitrairement + sous forme unidimensionnelle. + + Exemple : + ``{"NameOfLocations":["Point3", "Location42", "Position125", "XgTaC"]}`` diff --git a/doc/fr/versions.rst b/doc/fr/versions.rst index faa1d90..ec9f305 100644 --- a/doc/fr/versions.rst +++ b/doc/fr/versions.rst @@ -181,6 +181,12 @@ doivent être modifiés. Versions de compatibilité d'ADAO avec les outils support -------------------------------------------------------- +Le module ADAO bénéficie largement de l'**environnement Python** [Python]_ et +des nombreuses possibilités de ce langage, des outils de calcul scientifique +inclus dans **NumPy** [NumPy20]_, **SciPy** [SciPy20]_, **NLopt** [Johnson08]_ +ou dans les outils atteignables grâce à eux, et des nombreuses capacités de +**SALOME** [Salome]_ lorsqu'il est utilisé en association. + .. include:: snippets/ModuleValidation.rst .. include:: snippets/ModuleCompatibility.rst diff --git a/src/daComposant/daAlgorithms/Atoms/ecweim.py b/src/daComposant/daAlgorithms/Atoms/ecweim.py index 01734c1..6f5dadf 100644 --- a/src/daComposant/daAlgorithms/Atoms/ecweim.py +++ b/src/daComposant/daAlgorithms/Atoms/ecweim.py @@ -21,12 +21,13 @@ # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D __doc__ = """ - EIM + EIM & lcEIM """ __author__ = "Jean-Philippe ARGAUD" import numpy import daCore.Persistence +from daCore.NumericObjects import FindIndexesFromNames # ============================================================================== def EIM_offline(selfA, EOS = None, Verbose = False): @@ -43,6 +44,7 @@ def EIM_offline(selfA, EOS = None, Verbose = False): # __EOS = numpy.asarray(EOS).T else: raise ValueError("EnsembleOfSnapshots has to be an array/matrix (each column being a vector) or a list/tuple (each element being a vector).") + __dimS, __nbmS = __EOS.shape # if selfA._parameters["ErrorNorm"] == "L2": MaxNormByColumn = MaxL2NormByColumn @@ -56,8 +58,16 @@ def EIM_offline(selfA, EOS = None, Verbose = False): if __LcCsts and "ExcludeLocations" in selfA._parameters: __ExcludedMagicPoints = selfA._parameters["ExcludeLocations"] else: - __ExcludedMagicPoints = [] + __ExcludedMagicPoints = () + if __LcCsts and "NameOfLocations" in selfA._parameters: + if isinstance(selfA._parameters["NameOfLocations"], (list, numpy.ndarray, tuple)) and len(selfA._parameters["NameOfLocations"]) == __dimS: + __NameOfLocations = selfA._parameters["NameOfLocations"] + else: + __NameOfLocations = () + else: + __NameOfLocations = () if __LcCsts and len(__ExcludedMagicPoints) > 0: + __ExcludedMagicPoints = FindIndexesFromNames( __NameOfLocations, __ExcludedMagicPoints ) __ExcludedMagicPoints = numpy.ravel(numpy.asarray(__ExcludedMagicPoints, dtype=int)) __IncludedMagicPoints = numpy.setdiff1d( numpy.arange(__EOS.shape[0]), @@ -67,7 +77,6 @@ def EIM_offline(selfA, EOS = None, Verbose = False): else: __IncludedMagicPoints = [] # - __dimS, __nbmS = __EOS.shape if "MaximumNumberOfLocations" in selfA._parameters and "MaximumRBSize" in selfA._parameters: selfA._parameters["MaximumRBSize"] = min(selfA._parameters["MaximumNumberOfLocations"],selfA._parameters["MaximumRBSize"]) elif "MaximumNumberOfLocations" in selfA._parameters: @@ -148,6 +157,8 @@ def EIM_offline(selfA, EOS = None, Verbose = False): selfA.StoredVariables["ReducedBasis"].store( __Q ) if selfA._toStore("Residus"): selfA.StoredVariables["Residus"].store( __errors ) + if selfA._toStore("ExcludedPoints"): + selfA.StoredVariables["ExcludedPoints"].store( __ExcludedMagicPoints ) # return __mu, __I, __Q, __errors diff --git a/src/daComposant/daAlgorithms/Atoms/lbfgsb19hlt.py b/src/daComposant/daAlgorithms/Atoms/lbfgsb19hlt.py index d8d7b6c..be191ad 100644 --- a/src/daComposant/daAlgorithms/Atoms/lbfgsb19hlt.py +++ b/src/daComposant/daAlgorithms/Atoms/lbfgsb19hlt.py @@ -1,4 +1,4 @@ -# Modification de la version 1.9.1 +# Modification de la version 1.9.1 et 1.10.1 """ Functions --------- @@ -241,7 +241,9 @@ def _minimize_lbfgsb(fun, x0, args=(), jac=None, bounds=None, If `jac is None` the absolute step size used for numerical approximation of the jacobian via forward differences. maxfun : int - Maximum number of function evaluations. + Maximum number of function evaluations. Note that this function + may violate the limit because of evaluating gradients by numerical + differentiation. maxiter : int Maximum number of iterations. iprint : int, optional diff --git a/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py b/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py index ea38ea5..89f73f5 100644 --- a/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py +++ b/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py @@ -107,13 +107,10 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q) # #-------------------------- - # Default EKF - #-------------------------- if self._parameters["Variant"] == "EKF": exkf.exkf(self, Xb, Y, U, HO, EM, CM, R, B, Q) # #-------------------------- - # Default CEKF elif self._parameters["Variant"] == "CEKF": cekf.cekf(self, Xb, Y, U, HO, EM, CM, R, B, Q) # diff --git a/src/daComposant/daAlgorithms/MeasurementsOptimalPositioningTask.py b/src/daComposant/daAlgorithms/MeasurementsOptimalPositioningTask.py index 9e45bf6..df67567 100644 --- a/src/daComposant/daAlgorithms/MeasurementsOptimalPositioningTask.py +++ b/src/daComposant/daAlgorithms/MeasurementsOptimalPositioningTask.py @@ -22,8 +22,7 @@ import numpy from daCore import BasicObjects -from daAlgorithms.Atoms import ecweim -from daAlgorithms.Atoms import eosg +from daAlgorithms.Atoms import ecweim, eosg # ============================================================================== class ElementaryAlgorithm(BasicObjects.Algorithm): @@ -56,8 +55,13 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): name = "ExcludeLocations", default = [], typecast = tuple, - message = "Liste des positions exclues selon la numérotation interne d'un snapshot", - minval = -1, + message = "Liste des indices ou noms de positions exclues selon l'ordre interne d'un snapshot", + ) + self.defineRequiredParameter( + name = "NameOfLocations", + default = [], + typecast = tuple, + message = "Liste des noms de positions selon l'ordre interne d'un snapshot", ) self.defineRequiredParameter( name = "ErrorNorm", @@ -111,6 +115,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): listval = [ "EnsembleOfSimulations", "EnsembleOfStates", + "ExcludedPoints", "OptimalPoints", "ReducedBasis", "Residus", diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index acddc35..6c8666d 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -748,6 +748,7 @@ class Algorithm(object): self.StoredVariables["EnsembleOfSimulations"] = Persistence.OneMatrix(name = "EnsembleOfSimulations") self.StoredVariables["EnsembleOfSnapshots"] = Persistence.OneMatrix(name = "EnsembleOfSnapshots") self.StoredVariables["EnsembleOfStates"] = Persistence.OneMatrix(name = "EnsembleOfStates") + self.StoredVariables["ExcludedPoints"] = Persistence.OneVector(name = "ExcludedPoints") self.StoredVariables["ForecastCovariance"] = Persistence.OneMatrix(name = "ForecastCovariance") self.StoredVariables["ForecastState"] = Persistence.OneVector(name = "ForecastState") self.StoredVariables["GradientOfCostFunctionJ"] = Persistence.OneVector(name = "GradientOfCostFunctionJ") diff --git a/src/daComposant/daCore/NumericObjects.py b/src/daComposant/daCore/NumericObjects.py index 9005366..87b6895 100644 --- a/src/daComposant/daCore/NumericObjects.py +++ b/src/daComposant/daCore/NumericObjects.py @@ -914,6 +914,68 @@ def Apply3DVarRecentringOnEnsemble(__EnXn, __EnXf, __Ynpu, __HO, __R, __B, __Sup # return Xa + EnsembleOfAnomalies( __EnXn ) +# ============================================================================== +def FindIndexesFromNames( __NameOfLocations = None, __ExcludeLocations = None, ForceArray = False): + "Exprime les indices des noms exclus, en ignorant les absents" + if __ExcludeLocations is None: + __ExcludeIndexes = () + elif isinstance(__ExcludeLocations, (list, numpy.ndarray, tuple)) and len(__ExcludeLocations)==0: + __ExcludeIndexes = () + # ---------- + elif __NameOfLocations is None: + try: + __ExcludeIndexes = numpy.asarray(__ExcludeLocations, dtype=int) + except ValueError as e: + if "invalid literal for int() with base 10:" in str(e): + raise ValueError("to exclude named locations, initial location name list can not be void and has to have the same length as one state") + else: + raise ValueError(str(e)) + elif isinstance(__NameOfLocations, (list, numpy.ndarray, tuple)) and len(__NameOfLocations)==0: + try: + __ExcludeIndexes = numpy.asarray(__ExcludeLocations, dtype=int) + except ValueError as e: + if "invalid literal for int() with base 10:" in str(e): + raise ValueError("to exclude named locations, initial location name list can not be void and has to have the same length as one state") + else: + raise ValueError(str(e)) + # ---------- + else: + try: + __ExcludeIndexes = numpy.asarray(__ExcludeLocations, dtype=int) + except ValueError as e: + if "invalid literal for int() with base 10:" in str(e): + if len(__NameOfLocations) < 1.e6+1 and len(__ExcludeLocations) > 1500: + __Heuristic = True + else: + __Heuristic = False + if ForceArray or __Heuristic: + # Recherche par array permettant des noms invalides, peu efficace + __NameToIndex = dict(numpy.array(( + __NameOfLocations, + range(len(__NameOfLocations)) + )).T) + __ExcludeIndexes = numpy.asarray([__NameToIndex.get(k, -1) for k in __ExcludeLocations], dtype=int) + # + else: + # Recherche par liste permettant des noms invalides, très efficace + def __NameToIndex_get( cle, default = -1 ): + if cle in __NameOfLocations: + return __NameOfLocations.index(cle) + else: + return default + __ExcludeIndexes = numpy.asarray([__NameToIndex_get(k, -1) for k in __ExcludeLocations], dtype=int) + # + # Recherche par liste interdisant des noms invalides, mais encore un peu plus efficace + # __ExcludeIndexes = numpy.asarray([__NameOfLocations.index(k) for k in __ExcludeLocations], dtype=int) + # + # Ignore les noms absents + __ExcludeIndexes = numpy.compress(__ExcludeIndexes > -1, __ExcludeIndexes) + if len(__ExcludeIndexes)==0: __ExcludeIndexes = () + else: + raise ValueError(str(e)) + # ---------- + return __ExcludeIndexes + # ============================================================================== def BuildComplexSampleList( __SampleAsnUplet, -- 2.39.2