utils.boundaries
utils.boundaries
Functions
| Name | Description |
|---|---|
| get_boundaries | Calculates the minimum and maximum values for each column in a NumPy array. |
| map_to_original_scale | Maps the values in X_search from the range [0, 1] to the original scale defined by x_min and x_max. |
get_boundaries
utils.boundaries.get_boundaries(data)Calculates the minimum and maximum values for each column in a NumPy array.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | np.ndarray | A NumPy array of shape (n, k), where n is the number of rows and k is the number of columns. | required |
Returns
| Name | Type | Description |
|---|---|---|
| tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray]: A tuple containing two NumPy arrays: - The first array contains the minimum values for each column, with shape (k,). - The second array contains the maximum values for each column, with shape (k,). |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If the input array has shape (1, 0) (empty array). |
Examples
>>> from spotoptim.utils.boundaries import get_boundaries
>>> import numpy as np
>>> data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> min_values, max_values = get_boundaries(data)
>>> print("Minimum values:", min_values)
Minimum values: [1 2 3]
>>> print("Maximum values:", max_values)
Maximum values: [7 8 9]map_to_original_scale
utils.boundaries.map_to_original_scale(X_search, x_min, x_max)Maps the values in X_search from the range [0, 1] to the original scale defined by x_min and x_max.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X_search | Union[pd.DataFrame, np.ndarray] | A Pandas DataFrame or NumPy array containing the search points in the range [0, 1]. | required |
| x_min | np.ndarray | A NumPy array containing the minimum values for each feature in the original scale. | required |
| x_max | np.ndarray | A NumPy array containing the maximum values for each feature in the original scale. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Union[pd.DataFrame, np.ndarray] | Union[pd.DataFrame, np.ndarray]: A Pandas DataFrame or NumPy array with the values mapped to the original scale. |
Examples
>>> from spotoptim.utils.boundaries import map_to_original_scale
>>> import numpy as np
>>> import pandas as pd
>>> X_search = pd.DataFrame([[0.5, 0.5], [0.25, 0.75]], columns=['x', 'y'])
>>> x_min = np.array([0, 0])
>>> x_max = np.array([10, 20])
>>> X_search_scaled = map_to_original_scale(X_search, x_min, x_max)
>>> print(X_search_scaled)
x y
0 5.0 10.0
1 2.5 15.0