Skip to main content

Sequential Parameter Optimization Toolbox

Project description

SpotOptim

Sequential Parameter Optimization

Features

  • Surrogate Model Based Optimization: Uses surrogate models to efficiently optimize expensive black-box functions
  • Multiple Acquisition Functions: Expected Improvement (EI), Predicted Mean (y), Probability of Improvement (PI)
  • Flexible Surrogates: Default Gaussian Process or custom Kriging surrogate
  • Variable Types: Support for continuous, integer, and mixed variable types
  • scipy-compatible: Returns OptimizeResult objects compatible with scipy.optimize

Installation

pip install spotoptim

Quick Start

import numpy as np
from spotoptim import SpotOptim

# Define objective function
def rosenbrock(X):
    X = np.atleast_2d(X)
    x, y = X[:, 0], X[:, 1]
    return (1 - x)**2 + 100 * (y - x**2)**2

# Set up optimization
bounds = [(-2, 2), (-2, 2)]

optimizer = SpotOptim(
    fun=rosenbrock,
    bounds=bounds,
    max_iter=50,
    n_initial=10,
    seed=42
)

# Run optimization
result = optimizer.optimize()

print(f"Best point: {result.x}")
print(f"Best value: {result.fun}")

Using Kriging Surrogate

SpotOptim includes a simplified Kriging (Gaussian Process) surrogate as an alternative to scikit-learn's GaussianProcessRegressor:

from spotoptim import SpotOptim, Kriging

# Create Kriging surrogate
kriging = Kriging(
    noise=1e-6,
    min_theta=-3.0,
    max_theta=2.0,
    seed=42
)

# Use with SpotOptim
optimizer = SpotOptim(
    fun=rosenbrock,
    bounds=bounds,
    surrogate=kriging,  # Use Kriging instead of default GP
    seed=42
)

result = optimizer.optimize()

API Reference

SpotOptim

Parameters:

  • fun (callable): Objective function to minimize
  • bounds (list of tuples): Bounds for each dimension as [(low, high), ...]
  • max_iter (int, default=20): Maximum number of optimization iterations
  • n_initial (int, default=10): Number of initial design points
  • surrogate (object, optional): Surrogate model (default: GaussianProcessRegressor)
  • acquisition (str, default='ei'): Acquisition function ('ei', 'y', 'pi')
  • var_type (list of str, optional): Variable types for each dimension
  • tolerance_x (float, optional): Minimum distance between points
  • seed (int, optional): Random seed for reproducibility
  • verbose (bool, default=False): Print progress information
  • max_surrogate_points (int, optional): Maximum number of points for surrogate fitting (default: None, use all points)
  • selection_method (str, default='distant'): Point selection method ('distant' or 'best')

Methods:

  • optimize(X0=None): Run optimization, optionally with initial design points
  • plot_surrogate(i=0, j=1, show=True, **kwargs): Visualize the fitted surrogate model

Point Selection for Surrogate Training

When optimizing expensive functions with many iterations, the number of evaluated points can become large, making surrogate model training computationally expensive. SpotOptim implements an automatic point selection mechanism to address this:

Usage

optimizer = SpotOptim(
    fun=expensive_function,
    bounds=bounds,
    max_iter=100,
    n_initial=20,
    max_surrogate_points=50,  # Use only 50 points for surrogate training
    selection_method='distant',  # or 'best'
    verbose=True
)

Selection Methods

  1. 'distant' (default): Uses K-means clustering to select points that are maximally distant from each other, ensuring good space-filling properties.

  2. 'best': Clusters points and selects all points from the cluster with the best (lowest) mean objective function value, focusing on promising regions.

Benefits

  • Reduced computational cost: Surrogate training scales with the number of points
  • Maintained accuracy: Carefully selected points preserve model quality
  • Scalability: Enables optimization with hundreds or thousands of function evaluations

See examples/point_selection_example.py for a complete demonstration.

Kriging

Parameters:

  • noise (float, optional): Regularization parameter
  • kernel (str, default='gauss'): Kernel type
  • n_theta (int, optional): Number of theta parameters
  • min_theta (float, default=-3.0): Minimum log10(theta) bound
  • max_theta (float, default=2.0): Maximum log10(theta) bound
  • seed (int, optional): Random seed

Methods:

  • fit(X, y): Fit the model to training data
  • predict(X, return_std=False): Predict at new points

Visualizing Results

SpotOptim includes a plot_surrogate() method to visualize the fitted surrogate model:

# After running optimization
optimizer.plot_surrogate(
    i=0, j=1,                    # Dimensions to plot
    var_name=['x1', 'x2'],       # Variable names
    add_points=True,             # Show evaluated points
    cmap='viridis',              # Colormap
    show=True
)

The plot shows:

  • Top left: 3D surface of predictions
  • Top right: 3D surface of prediction uncertainty
  • Bottom left: Contour plot of predictions with evaluated points
  • Bottom right: Contour plot of prediction uncertainty

For higher-dimensional problems, the method visualizes a 2D slice by fixing other dimensions at their mean values.

Examples

Notebooks

See notebooks/demos.ipynb for interactive examples:

  1. 2D Rosenbrock function optimization
  2. 6D Rosenbrock with budget constraints
  3. Using Kriging surrogate vs default GP
  4. Visualizing surrogate models with plot_surrogate()

Real-World Applications

The examples/ directory contains detailed tutorials:

Aircraft Wing Weight Optimization (AWWE)

  • awwe.qmd - Comprehensive Quarto tutorial teaching surrogate-based optimization
  • awwe_optimization.py - Standalone Python script demonstrating complete workflow
  • 9-dimensional optimization problem from engineering design
  • Includes homework exercise for 10-dimensional extension

Run the example:

cd examples
python awwe_optimization.py

See examples/README.md for more details and additional examples.

Development

# Clone repository
git clone https://github.com/sequential-parameter-optimization/spotoptim.git
cd spotoptim

# Install with uv
uv pip install -e .

# Run tests
uv run pytest tests/

# Build package
uv build

License

See LICENSE file.

References

Based on the SPOT (Sequential Parameter Optimization Toolbox) methodology.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spotoptim-0.0.118.tar.gz (479.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spotoptim-0.0.118-py3-none-any.whl (509.0 kB view details)

Uploaded Python 3

File details

Details for the file spotoptim-0.0.118.tar.gz.

File metadata

  • Download URL: spotoptim-0.0.118.tar.gz
  • Upload date:
  • Size: 479.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for spotoptim-0.0.118.tar.gz
Algorithm Hash digest
SHA256 649cbb92277c68882f15c1ab58ab5249d11420bfb4e93a439e3629f6afcc10f0
MD5 788352e5d7805c5d2ca546728428df79
BLAKE2b-256 c10b00f6e3a9a23e4d9122802573cc96a7b26e40a3f6352d7a3ffb2c8786ccf4

See more details on using hashes here.

File details

Details for the file spotoptim-0.0.118-py3-none-any.whl.

File metadata

  • Download URL: spotoptim-0.0.118-py3-none-any.whl
  • Upload date:
  • Size: 509.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for spotoptim-0.0.118-py3-none-any.whl
Algorithm Hash digest
SHA256 566052221349de22f1012a14647dd92e350679b54005533192f68dc8e9925368
MD5 66406af65284846023303ae7f6f44ad4
BLAKE2b-256 d7ba7141e9d05c10d349c968423cf9fde4fd51a9c75e2af5285f3ae747806e63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page