From: Jean-Philippe ARGAUD Date: Wed, 29 May 2024 08:01:16 +0000 (+0200) Subject: Documentation examples corrections and update X-Git-Tag: V9_13_0a1~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1a37214af4654597ea3654955b13ab1b204449c8;p=modules%2Fadao.git Documentation examples corrections and update --- diff --git a/doc/en/ref_algorithm_MeasurementsOptimalPositioningTask.rst b/doc/en/ref_algorithm_MeasurementsOptimalPositioningTask.rst index a61ccd3..e2a66e3 100644 --- a/doc/en/ref_algorithm_MeasurementsOptimalPositioningTask.rst +++ b/doc/en/ref_algorithm_MeasurementsOptimalPositioningTask.rst @@ -232,20 +232,10 @@ StoreSupplementaryCalculations .. include:: snippets/Header2Algo11.rst -.. _simple_MeasurementsOptimalPositioningTask31: -.. image:: scripts/simple_MeasurementsOptimalPositioningTask31.png +.. _simple_MeasurementsOptimalPositioningTask3: +.. image:: scripts/simple_MeasurementsOptimalPositioningTask3.png :align: center - :width: 60% - -.. _simple_MeasurementsOptimalPositioningTask32: -.. image:: scripts/simple_MeasurementsOptimalPositioningTask32.png - :align: center - :width: 60% - -.. _simple_MeasurementsOptimalPositioningTask33: -.. image:: scripts/simple_MeasurementsOptimalPositioningTask33.png - :align: center - :width: 60% + :width: 100% .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.png b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.png new file mode 100644 index 0000000..87e62a1 Binary files /dev/null and b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.png differ diff --git a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.py b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.py index 8878d12..a91213f 100644 --- a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.py +++ b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt np.random.seed(123456789) # dimension = 20 +nbmeasures = 15 # print("Defining a set of artificial physical fields") from Models.TwoDimensionalInverseDistanceCS2010 \ @@ -20,7 +21,7 @@ case.setAlgorithmParameters( Parameters = { "Variant":"DEIM", "SampleAsnUplet":Eq.get_sample_of_mu(15, 15), - "MaximumNumberOfLocations":50, + "MaximumNumberOfLocations":nbmeasures, "ErrorNorm":"Linf", "ErrorNormTolerance":0., "StoreSupplementaryCalculations":[ @@ -34,57 +35,61 @@ case.setBackground(Vector = [1,1] ) case.setObservationOperator(OneFunction = Eq.OneRealisation) case.execute() # +#------------------------------------------------------------------------------- print() print("Graphical display of the results") # sp = case.get("EnsembleOfSimulations")[-1] +sv = case.get("SingularValues")[-1] +op = case.get("OptimalPoints")[-1] +# x1, x2 = Eq.get_x() x1, x2 = np.meshgrid(x1, x2) -name = "Representation of a few snapshots of G out of a total of %i"%sp.shape[1] -print(" -", name) -fig, ax = plt.subplots(subplot_kw={"projection": "3d"}, figsize=(6, 6)) -fig.suptitle(name) -ax.set_xlabel("Position x1", fontweight='bold', color='red') -ax.set_ylabel("Position x2", fontweight='bold', color='red') -ax.set_zlabel("Magnitude of G", fontweight='bold', color='red') -for i in range(sp.shape[1]): - if i % 44 != 0: continue - ax.plot_surface(x1, x2, sp[:,i].reshape((dimension, dimension)), cmap='coolwarm') -fig.savefig("simple_MeasurementsOptimalPositioningTask31.png") -plt.close() +posx1 = [x1.reshape((-1,))[ip] for ip in op] +posx2 = [x2.reshape((-1,))[ip] for ip in op] +Omega = Eq.get_bounds_on_space() # -sv = case.get("SingularValues")[-1] -name = "Singular values of the set of G simulations" +fig = plt.figure(figsize=(18, 6)) +name = "Measurement optimal points search by " +name += '"ADAO/MeasurementsOptimalPositioningTask/DEIM"' +fig.suptitle(name, fontsize=20, fontstyle='italic') +# +ax = fig.add_subplot(1, 3, 1) +name = "Singular values of the set of %i G simulations"%sp.shape[1] print(" -", name) -fig, ax = plt.subplots(figsize=(6, 6)) -fig.suptitle(name) +ax.set_title(name, fontstyle='italic', color='red') ax.set_xlabel("Index of singular values, numbered from 1") ax.set_ylabel("Magnitude of singular values") ax.set_xlim(1, len(sv)) ax.set_yscale("log") ax.grid(True) ax.plot(range(1, 1 + len(sv)), sv) -fig.savefig("simple_MeasurementsOptimalPositioningTask32.png") -plt.tight_layout() -plt.close() # -nbmax = 15 -op = case.get("OptimalPoints")[-1] -posx1 = [x1.reshape((-1,))[ip] for ip in op[:nbmax]] -posx2 = [x2.reshape((-1,))[ip] for ip in op[:nbmax]] -name = "Set of %i first optimal points of measurement"%nbmax -Omega = Eq.get_bounds_on_space() +ax = fig.add_subplot(1, 3, 2, projection = "3d") +name = "A few simulations of G out of a total of %i"%sp.shape[1] print(" -", name) -fig, ax = plt.subplots(figsize=(6, 6)) -fig.suptitle(name) -ax.set_xlabel("Position x1", fontweight='bold', color='red') -ax.set_ylabel("Position x2", fontweight='bold', color='red') +ax.set_title(name, fontstyle='italic', color='red') +ax.set_xlabel("Position x1") +ax.set_ylabel("Position x2") +ax.set_zlabel("Magnitude of G") +for i in range(sp.shape[1]): + if i % 44 != 0: continue + Gfield = sp[:,i].reshape((dimension, dimension)) + ax.plot_surface(x1, x2, Gfield, cmap='coolwarm') +# +ax = fig.add_subplot(1, 3, 3) +name = "Set of %i first optimal points of measurement"%nbmeasures +print(" -", name) +ax.set_title(name, fontstyle='italic', color='red') +ax.set_xlabel("Position x1") +ax.set_ylabel("Position x2") ax.set_xlim(Omega[0][0] - 0.05, Omega[0][1] + 0.05) ax.set_ylim(Omega[1][0] - 0.05, Omega[1][1] + 0.05) ax.grid(True, which='both', linestyle=(0, (1, 5)), linewidth=0.5) ax.plot(posx1, posx2, markersize=6, marker="o", linestyle='') for i in range(len(posx1)): ax.text(posx1[i] + 0.005, posx2[i] + 0.01, str(i + 1), fontweight='bold') -fig.savefig("simple_MeasurementsOptimalPositioningTask33.png") +# plt.tight_layout() +fig.savefig("simple_MeasurementsOptimalPositioningTask3.png") plt.close() diff --git a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.res b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.res index 455a3d3..7945bf1 100644 --- a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.res +++ b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.res @@ -3,6 +3,6 @@ Defining a set of artificial physical fields Search for optimal measurement positions Graphical display of the results - - Representation of a few snapshots of G out of a total of 225 - - Singular values of the set of G simulations + - Singular values of the set of 225 G simulations + - A few simulations of G out of a total of 225 - Set of 15 first optimal points of measurement diff --git a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.rst b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.rst index 9445285..3d57f87 100644 --- a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.rst +++ b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask3.rst @@ -18,9 +18,13 @@ in the 2D plane, and on the parameter The function is represented on a regular :math:`\Omega_G` spatial grid of size 20x20 points. It is available in ADAO built-in test models under the name -`TwoDimensionalInverseDistanceCS2010`. So here we first build a set of -simulations of :math:`G`, then apply the DEIM-type decomposition algorithm to -it, and derive some simple illustrations. +``TwoDimensionalInverseDistanceCS2010``, together with the spatial and +parametric domain default definition. So here we first build a set of +simulations of :math:`G`, then we look for the best locations for measurements +to obtain an DEIM interpolation representation of the fields, by applying the +DEIM-type decomposition algorithm to it, and then derive some simple +illustrations. We choose to look for an arbitrary number ``nbmeasures`` of 15 +measurement locations. It can be seen that the singular values decrease steadily down to numerical noise, indicating that around a hundred basis elements are needed to fully diff --git a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask31.png b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask31.png deleted file mode 100644 index 128980d..0000000 Binary files a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask31.png and /dev/null differ diff --git a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask32.png b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask32.png deleted file mode 100644 index 8c78ab5..0000000 Binary files a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask32.png and /dev/null differ diff --git a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask33.png b/doc/en/scripts/simple_MeasurementsOptimalPositioningTask33.png deleted file mode 100644 index e1aa57a..0000000 Binary files a/doc/en/scripts/simple_MeasurementsOptimalPositioningTask33.png and /dev/null differ diff --git a/doc/en/snippets/ModuleCompatibility.rst b/doc/en/snippets/ModuleCompatibility.rst index ce47ccf..60cf2a5 100644 --- a/doc/en/snippets/ModuleCompatibility.rst +++ b/doc/en/snippets/ModuleCompatibility.rst @@ -16,7 +16,7 @@ versions within the range described below. Python, 3.6.5, 3.12.3 Numpy, 1.14.3, 1.26.4 - Scipy, 0.19.1, 1.13.0 + Scipy, 0.19.1, 1.13.1 MatplotLib, 2.2.2, 3.8.4 GnuplotPy, 1.8, 1.8 NLopt, 2.4.2, 2.7.1 diff --git a/doc/fr/ref_algorithm_MeasurementsOptimalPositioningTask.rst b/doc/fr/ref_algorithm_MeasurementsOptimalPositioningTask.rst index a4adb23..54e2cb1 100644 --- a/doc/fr/ref_algorithm_MeasurementsOptimalPositioningTask.rst +++ b/doc/fr/ref_algorithm_MeasurementsOptimalPositioningTask.rst @@ -235,20 +235,10 @@ StoreSupplementaryCalculations .. include:: snippets/Header2Algo11.rst -.. _simple_MeasurementsOptimalPositioningTask31: -.. image:: scripts/simple_MeasurementsOptimalPositioningTask31.png +.. _simple_MeasurementsOptimalPositioningTask3: +.. image:: scripts/simple_MeasurementsOptimalPositioningTask3.png :align: center - :width: 60% - -.. _simple_MeasurementsOptimalPositioningTask32: -.. image:: scripts/simple_MeasurementsOptimalPositioningTask32.png - :align: center - :width: 60% - -.. _simple_MeasurementsOptimalPositioningTask33: -.. image:: scripts/simple_MeasurementsOptimalPositioningTask33.png - :align: center - :width: 60% + :width: 100% .. ------------------------------------ .. .. include:: snippets/Header2Algo06.rst diff --git a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.png b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.png new file mode 100644 index 0000000..bec4390 Binary files /dev/null and b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.png differ diff --git a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.py b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.py index d9fca5a..2ced825 100644 --- a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.py +++ b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt np.random.seed(123456789) # dimension = 20 +nbmeasures = 15 # print("Définition d'un ensemble artificiel de champs physiques") from Models.TwoDimensionalInverseDistanceCS2010 \ @@ -20,7 +21,7 @@ case.setAlgorithmParameters( Parameters = { "Variant":"DEIM", "SampleAsnUplet":Eq.get_sample_of_mu(15, 15), - "MaximumNumberOfLocations":50, + "MaximumNumberOfLocations":nbmeasures, "ErrorNorm":"Linf", "ErrorNormTolerance":0., "StoreSupplementaryCalculations":[ @@ -34,57 +35,61 @@ case.setBackground(Vector = [1,1] ) case.setObservationOperator(OneFunction = Eq.OneRealisation) case.execute() # +#------------------------------------------------------------------------------- print() print("Affichage graphique des résultats") # sp = case.get("EnsembleOfSimulations")[-1] +sv = case.get("SingularValues")[-1] +op = case.get("OptimalPoints")[-1] +# x1, x2 = Eq.get_x() x1, x2 = np.meshgrid(x1, x2) -name = "Représentation de quelques snapshots de G sur un total de %i"%sp.shape[1] -print(" -", name) -fig, ax = plt.subplots(subplot_kw={"projection": "3d"}, figsize=(6, 6)) -fig.suptitle(name) -ax.set_xlabel("Position x1", fontweight='bold', color='red') -ax.set_ylabel("Position x2", fontweight='bold', color='red') -ax.set_zlabel("Amplitude de G", fontweight='bold', color='red') -for i in range(sp.shape[1]): - if i % 44 != 0: continue - ax.plot_surface(x1, x2, sp[:,i].reshape((dimension, dimension)), cmap='coolwarm') -fig.savefig("simple_MeasurementsOptimalPositioningTask31.png") -plt.close() +posx1 = [x1.reshape((-1,))[ip] for ip in op] +posx2 = [x2.reshape((-1,))[ip] for ip in op] +Omega = Eq.get_bounds_on_space() # -sv = case.get("SingularValues")[-1] -name = "Valeurs singulières de l'ensemble des simulations de G" +fig = plt.figure(figsize=(18, 6)) +name = "Recherche de points optimaux de mesure par " +name += '"ADAO/MeasurementsOptimalPositioningTask/DEIM"' +fig.suptitle(name, fontsize=20, fontstyle='italic') +# +ax = fig.add_subplot(1, 3, 1) +name = "Valeurs singulières de l'ensemble des %i simulations de G"%sp.shape[1] print(" -", name) -fig, ax = plt.subplots(figsize=(6, 6)) -fig.suptitle(name) +ax.set_title(name, fontstyle='italic', color='red') ax.set_xlabel("Index des valeurs singulières, numérotées à partir de 1") ax.set_ylabel("Amplitude des valeurs singulières") ax.set_xlim(1, len(sv)) ax.set_yscale("log") ax.grid(True) ax.plot(range(1, 1 + len(sv)), sv) -fig.savefig("simple_MeasurementsOptimalPositioningTask32.png") -plt.tight_layout() -plt.close() # -nbmax = 15 -op = case.get("OptimalPoints")[-1] -posx1 = [x1.reshape((-1,))[ip] for ip in op[:nbmax]] -posx2 = [x2.reshape((-1,))[ip] for ip in op[:nbmax]] -name = "Ensemble des %i premiers points optimaux de mesure"%nbmax -Omega = Eq.get_bounds_on_space() +ax = fig.add_subplot(1, 3, 2, projection = "3d") +name = "Quelques simulations de G sur un total de %i"%sp.shape[1] print(" -", name) -fig, ax = plt.subplots(figsize=(6, 6)) -fig.suptitle(name) -ax.set_xlabel("Position x1", fontweight='bold', color='red') -ax.set_ylabel("Position x2", fontweight='bold', color='red') +ax.set_title(name, fontstyle='italic', color='red') +ax.set_xlabel("Position x1") +ax.set_ylabel("Position x2") +ax.set_zlabel("Amplitude de G") +for i in range(sp.shape[1]): + if i % 44 != 0: continue + Gfield = sp[:,i].reshape((dimension, dimension)) + ax.plot_surface(x1, x2, Gfield, cmap='coolwarm') +# +ax = fig.add_subplot(1, 3, 3) +name = "Ensemble des %i premiers points optimaux de mesure"%nbmeasures +print(" -", name) +ax.set_title(name, fontstyle='italic', color='red') +ax.set_xlabel("Position x1") +ax.set_ylabel("Position x2") ax.set_xlim(Omega[0][0] - 0.05, Omega[0][1] + 0.05) ax.set_ylim(Omega[1][0] - 0.05, Omega[1][1] + 0.05) ax.grid(True, which='both', linestyle=(0, (1, 5)), linewidth=0.5) ax.plot(posx1, posx2, markersize=6, marker="o", linestyle='') for i in range(len(posx1)): ax.text(posx1[i] + 0.005, posx2[i] + 0.01, str(i + 1), fontweight='bold') -fig.savefig("simple_MeasurementsOptimalPositioningTask33.png") +# plt.tight_layout() +fig.savefig("simple_MeasurementsOptimalPositioningTask3.png") plt.close() diff --git a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.res b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.res index 756b5bf..c43b05b 100644 --- a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.res +++ b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.res @@ -3,6 +3,6 @@ Définition d'un ensemble artificiel de champs physiques Recherche des positions optimales de mesure Affichage graphique des résultats - - Représentation de quelques snapshots de G sur un total de 225 - - Valeurs singulières de l'ensemble des simulations de G + - Valeurs singulières de l'ensemble des 225 simulations de G + - Quelques simulations de G sur un total de 225 - Ensemble des 15 premiers points optimaux de mesure diff --git a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.rst b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.rst index 8225906..6a2d2e0 100644 --- a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.rst +++ b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask3.rst @@ -19,10 +19,12 @@ dans le plan 2D, et du paramètre La fonction est représenté sur une grille spatiale régulière :math:`\Omega_G` de taille 20x20 points. Elle est disponible dans les modèles de tests intégrés -pour ADAO sous le nom `TwoDimensionalInverseDistanceCS2010`. On construit donc -ici tout d'abord un ensemble de simulations de :math:`G`, pour lui appliquer -ensuite l'algorithme de décomposition de type DEIM, et en tirer des -illustrations simples. +pour ADAO sous le nom ``TwoDimensionalInverseDistanceCS2010``. On construit +donc ici tout d'abord un ensemble de simulations de :math:`G`, puis on cherche +les meilleurs positions de mesures pour obtenir une représentation par +interpolation DEIM des champs, en appliquant l'algorithme de décomposition de +type DEIM, et on en tire ensuite des illustrations simples. On choisit de +rechercher un nombre arbitraire ``nbmeasures`` de 15 positions de mesures. On observe ainsi que les valeurs singulières décroissent régulièrement jusqu'au bruit numérique, indiquant qu'il faut environ une centaine d'éléments de base diff --git a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask31.png b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask31.png deleted file mode 100644 index 4e21179..0000000 Binary files a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask31.png and /dev/null differ diff --git a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask32.png b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask32.png deleted file mode 100644 index a84b5bd..0000000 Binary files a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask32.png and /dev/null differ diff --git a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask33.png b/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask33.png deleted file mode 100644 index 296b6ea..0000000 Binary files a/doc/fr/scripts/simple_MeasurementsOptimalPositioningTask33.png and /dev/null differ diff --git a/doc/fr/snippets/ModuleCompatibility.rst b/doc/fr/snippets/ModuleCompatibility.rst index fe333b5..0eecbfd 100644 --- a/doc/fr/snippets/ModuleCompatibility.rst +++ b/doc/fr/snippets/ModuleCompatibility.rst @@ -17,7 +17,7 @@ l'étendue décrite ci-dessous. Python, 3.6.5, 3.12.3 Numpy, 1.14.3, 1.26.4 - Scipy, 0.19.1, 1.13.0 + Scipy, 0.19.1, 1.13.1 MatplotLib, 2.2.2, 3.8.4 GnuplotPy, 1.8, 1.8 NLopt, 2.4.2, 2.7.1 diff --git a/src/daComposant/daNumerics/Models/TwoDimensionalInverseDistanceCS2010.py b/src/daComposant/daNumerics/Models/TwoDimensionalInverseDistanceCS2010.py index 6df69eb..c86e9e0 100644 --- a/src/daComposant/daNumerics/Models/TwoDimensionalInverseDistanceCS2010.py +++ b/src/daComposant/daNumerics/Models/TwoDimensionalInverseDistanceCS2010.py @@ -37,12 +37,14 @@ class TwoDimensionalInverseDistanceCS2010: SIAM Journal on Scientific Computing, 32(5), pp. 2737-2764 (2010). """ def __init__(self, nx: int = 20, ny: int = 20): + "Définition du maillage spatial" self.nx = max(1, nx) self.ny = max(1, ny) self.x = numpy.linspace(0.1, 0.9, self.nx, dtype=float) self.y = numpy.linspace(0.1, 0.9, self.ny, dtype=float) def FunctionH(self, XX ): + "Fonction simulation pour un paramètre donné" __mu1, __mu2 = numpy.ravel(XX) # __x, __y = numpy.meshgrid( self.x, self.y ) @@ -51,15 +53,18 @@ class TwoDimensionalInverseDistanceCS2010: return __sxymu def get_x(self): + "Renvoie le maillage spatial" return self.x, self.y def get_sample_of_mu(self, ns1: int = 20, ns2: int = 20): + "Renvoie l'échantillonnage paramétrique régulier" smu1 = numpy.linspace(-1, -0.01, ns1, dtype=float) smu2 = numpy.linspace(-1, -0.01, ns2, dtype=float) smu = numpy.array([(mu1, mu2) for mu1 in smu1 for mu2 in smu2]) return smu def get_random_sample_of_mu(self, ns1: int = 1, ns2: int = 1): + "Renvoie l'échantillonnage paramétrique aléatoire" smu = [] for i in range(ns1 * ns2): smu1 = numpy.random.uniform(-1, -0.01) @@ -69,9 +74,11 @@ class TwoDimensionalInverseDistanceCS2010: return smu def get_bounds_on_space(self): + "Renvoie les bornes sur le maillage spatial" return [[min(self.x), max(self.x)], [min(self.y), max(self.y)]] def get_bounds_on_parameter(self): + "Renvoie les bornes sur le maillage paramétrique" return [[-1, -0.01]] * 2 OneRealisation = FunctionH