sampling.mm.mmsort
sampling.mm.mmsort(X3D, p=1.0)Ranks multiple sampling plans stored in a 3D array according to the Morris-Mitchell criterion, using a simple bubble sort.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X3D | np.ndarray | A 3D NumPy array of shape (n, d, m), where m is the number of sampling plans, and each plan is an (n, d) matrix of points. | required |
| p | float | The distance metric to use. p=1 for Manhattan (L1), p=2 for Euclidean (L2). Defaults to 1.0. | 1.0 |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | np.ndarray: A 1D integer array of length m that holds the plan indices in ascending order of space-filling quality. The first index in the returned array corresponds to the most space-filling plan. |
Notes
Many thanks to the original author of this code, A Sobester, for providing the original Matlab code under the GNU Licence. Original Matlab Code: Copyright 2007 A Sobester: “This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.”
Examples
>>> import numpy as np
>>> from spotoptim.sampling.mm import mmsort
>>> # Suppose we have two 3-point sampling plans in 2D, stored in X3D:
>>> X1 = np.array([[0.0, 0.0],
... [0.5, 0.5],
... [1.0, 1.0]])
>>> X2 = np.array([[0.2, 0.2],
... [0.6, 0.4],
... [0.9, 0.9]])
>>> # Stack them along the third dimension: shape will be (3, 2, 2)
>>> X3D = np.stack([X1, X2], axis=2)
>>> # Sort them using the Morris-Mitchell criterion with p=2
>>> ranking = mmsort(X3D, p=2.0)
>>> print(ranking)
# It might print [2 1] or [1 2], depending on which plan is more space-filling.