sampling.mm.perturb
sampling.mm.perturb(X, PertNum=1)Performs a specified number of random element swaps on a sampling plan. If the plan is a Latin hypercube, the result remains a valid Latin hypercube.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | np.ndarray | A 2D array (sampling plan) of shape (n, k), where each row is a point and each column is a dimension. | required |
| PertNum | int | The number of element swaps (perturbations) to perform. Defaults to 1. | 1 |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | np.ndarray: The perturbed sampling plan, identical in shape to the input, with one or more random column swaps executed. |
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 perturb
>>> # Create a simple 4x2 sampling plan
>>> X_original = np.array([
... [1, 3],
... [2, 4],
... [3, 1],
... [4, 2]
... ])
>>> # Perturb it once
>>> X_perturbed = perturb(X_original, PertNum=1)
>>> print(X_perturbed)
# The output may differ due to random swaps, but each column is still a permutation of [1,2,3,4].
[[1 3]
[2 2]
[3 1]
[4 4]]