mo.mo_mm
mo.mo_mm
Functions
| Name | Description |
|---|---|
| mo_mm_desirability_function | Calculates the negative combined desirability for a candidate point x. Can be used by the mo_mm_desirability_optimizer. |
| mo_mm_desirability_optimizer | Optimizes the multi-objective function to find the next best point. |
| mo_xy_desirability_plot | Generates a plot of the desirability landscape. |
mo_mm_desirability_function
mo.mo_mm.mo_mm_desirability_function(
x,
models,
X_base,
J_base,
d_base,
phi_base,
D_overall,
mm_objective=True,
verbose=False,
)Calculates the negative combined desirability for a candidate point x. Can be used by the mo_mm_desirability_optimizer. For each objective, a model is used to predict the objective value at x. If mm_objective is True, the Morris-Mitchell improvement is also calculated and included as an additional objective. The combined desirability, which uses the predictions from the models and optionally the Morris-Mitchell improvement, is then computed using the provided DOverall object.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | np.ndarray | Candidate point (1D array). | required |
| models | list | List of trained models. One model per objective. | required |
| X_base | np.ndarray | Existing design points. Used for computing Morris-Mitchell improvement. | required |
| J_base | np.ndarray | Multiplicities of distances for X_base. Used for Morris-Mitchell improvement. | required |
| d_base | np.ndarray | Unique distances for X_base. Used for Morris-Mitchell improvement. | required |
| phi_base | float | Base Morris-Mitchell metric for X_base. Used for Morris-Mitchell improvement. | required |
| D_overall | DOverall |
The overall desirability function. Must include desirability functions for each objective and optionally for Morris-Mitchell. | required |
| mm_objective | bool | Whether to include space-filling improvement as an objective. Defaults to True. | True |
| verbose | bool | Whether to print Morris-Mitchell improvement values. Defaults to False. | False |
Returns
| Name | Type | Description |
|---|---|---|
| Tuple[float, List[float]] | Tuple[float, List[float]]: A tuple containing: - Negative geometric mean of desirabilities (for minimization). - List of individual objective values. |
Examples
>>> from spotoptim.mo import mo_mm_desirability_function
>>> from spotdesirability import DOverall, DMax
>>> import numpy as np
>>> from spotoptim.function.mo import mo_conv2_max
>>> from sklearn.ensemble import RandomForestRegressor
>>> from spotoptim.sampling.mm import mmphi_intensive
>>> # X_base in the range [0,1]
>>> X_base = np.random.rand(500, 2)
>>> y = mo_conv2_max(X_base)
>>> models = []
>>> for i in range(y.shape[1]):
... model = RandomForestRegressor(n_estimators=100, random_state=42)
... model.fit(X_base, y[:, i])
... models.append(model)
>>> # calculate base Morris-Mitchell stats
>>> phi_base, J_base, d_base = mmphi_intensive(X_base, q=2, p=2)
>>> d_funcs = []
>>> for i in range(y.shape[1]):
... d_func = DMax(low=np.min(y[:, i]), high=np.max(y[:, i]))
... d_funcs.append(d_func)
>>> D_overall = DOverall(*d_funcs)
>>> x_test = np.random.rand(2) # Example test point
>>> neg_D, objectives = mo_mm_desirability_function(x_test, models, X_base, J_base, d_base, phi_base, D_overall, mm_objective=False)
>>> print(f"Negative Desirability: {neg_D}")
Negative Desirability: ...
>>> print(f"Objectives: {objectives}")
Objectives: ...mo_mm_desirability_optimizer
mo.mo_mm.mo_mm_desirability_optimizer(
X_base,
models,
bounds,
obj_func,
**kwargs,
)Optimizes the multi-objective function to find the next best point. Returns the best point, its desirability, and the history of objective values.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X_base | np.ndarray | Existing design points. | required |
| models | list | List of trained surrogate models for each objective. | required |
| bounds | list | Bounds for each dimension. | required |
| obj_func | callable | Objective function to compute desirability and objectives. | required |
| **kwargs | Any | Additional arguments for the objective function. | {} |
Returns
| Name | Type | Description |
|---|---|---|
| Tuple[np.ndarray, float, np.ndarray] | Tuple[np.ndarray, float, np.ndarray]: A tuple containing: - Best point (np.ndarray) - Best desirability (float) - History of objective values (np.ndarray) |
mo_xy_desirability_plot
mo.mo_mm.mo_xy_desirability_plot(
models,
X_base,
J_base,
d_base,
phi_base,
D_overall,
bounds=None,
mm_objective=True,
resolution=50,
feature_names=None,
**kwargs,
)Generates a plot of the desirability landscape. Plots the 2-dim X values as points in the plane and colors them according to their desirability values. For each pair of inputs, x_i and x_j (with i < j), one plot is generated.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| models | list | List of trained models (one per objective). | required |
| X_base | np.ndarray | Existing design points. | required |
| J_base | np.ndarray | Multiplicities of distances for X_base. | required |
| d_base | np.ndarray | Unique distances for X_base. | required |
| phi_base | float | Base Morris-Mitchell metric. | required |
| D_overall | DOverall |
The overall desirability function. | required |
| bounds | list | List of tuples (min, max) for each dimension. If None, derived from X_base. | None |
| mm_objective | bool | Whether to include space-filling improvement. Defaults to True. | True |
| resolution | int | Grid resolution for the plot. Defaults to 50. | 50 |
| feature_names | list | List of names for the input variables. Defaults to None. | None |
| **kwargs | Any | Additional arguments for plt.subplots (e.g., figsize). | {} |
Returns
| Name | Type | Description |
|---|---|---|
| None | None |
Examples
>>> from spotoptim.mo.mo_mm import mo_xy_desirability_plot
>>> import numpy as np
>>> from spotoptim.function.mo import mo_conv2_max
>>> from sklearn.ensemble import RandomForestRegressor
>>> from spotoptim.sampling.mm import mmphi_intensive
>>> # X_base in the range [0,1]
>>> X_base = np.random.rand(500, 2)
>>> y = mo_conv2_max(X_base)
>>> models = []
>>> for i in range(y.shape[1]):
... model = RandomForestRegressor(n_estimators=100, random_state=42)
... model.fit(X_base, y[:, i])
... models.append(model)
>>> # calculate base Morris-Mitchell stats
>>> phi_base, J_base, d_base = mmphi_intensive(X_base, q=2, p=2)
>>> d_funcs = []
>>> for i in range(y.shape[1]):
... d_func = DMax(low=np.min(y[:, i]), high=np.max(y[:, i]))
... d_funcs.append(d_func)
>>> D_overall = DOverall(*d_funcs)
>>> mo_xy_desirability_plot(models, X_base, J_base, d_base, phi_base, D_overall)