Skip to main content

Spectral mixture kernel for Bayesian Optimization

Project description

SMKBO: Spectral Mixture Kernel for Bayesian Optimization

This repo contains implementation of the SMKBO algorithm for mixed input variables.

Installation

Dependencies

Python>=3.9
gpytorch>=1.14
pytorch==2.5.1
botorch>=0.14.0
numpy==1.16.4

Option 1: Installing the latest release

The latest release of SMKBO is easily installed via pip:

pip install smkbo

Option 2: Editable install

If you want to contribute to SMKBO, you will want to install editably so that you can change files and have the changes reflected in your local install.

git clone https://github.com/YyyyyyiZ/SMKBO.git

Getting Started

Here's a quick run down of the main components of a Bayesian optimization loop.

  1. Import packages

    from SMKBO.test_func import *
    from SMKBO.bo import SpectralBO
    
  2. Define your optimization problem

    Option 2a: Mixed problem

    f = Func2C(lamda=1e-6, normalize=False)
    max_iters = 30
    batch_size = 1
    bo = SpectralBO(problem_type=f.problem_type, cat_vertices=f.config, cont_lb=f.lb, cont_ub=f.ub,
                    cat_dims=f.categorical_dims, cont_dims=f.continuous_dims, continuous_kern_type='smk', 
                    n_Cauchy=5, n_Gaussian=4, n_init=20, acq_func='ei', noise_variance=None, ard=True)
    

    Option 2b: Categorical problem

    f = QUBO()
    max_iters = 23
    batch_size = 1
    bo = SpectralBO(problem_type=f.problem_type, cat_vertices=f.config,  n_init=20, acq_func='ei', noise_variance=None, ard=True)
    

    Option 2c: Continuous problem

    f = Hartmann3()
    max_iters = 23
    batch_size = 1
    bo = SpectralBO(problem_type=f.problem_type, cont_lb=f.lb, cont_ub=f.ub,
                    continuous_kern_type='smk', n_Cauchy=9, n_Gaussian=0, n_init=20, acq_func='ucb',
                     noise_variance=None, ard=True)
    
  3. Optimization loop

    for i in range(max_iters):
        x_next = bo.optim.suggest(batchsize=batch_size)
        y_next = f.compute(x_next)
        bo.optim.observe(x_next, y_next)
        Y = np.array(bo.optim.fX)
        if Y[:i].shape[0]:
            argmin = np.argmin(Y[:i * batch_size])
            print('Iter %d, Last X %s; \n fX:  %.4f. fX_best: %.4f'
                  % (i, x_next, float(Y[-1]), Y[:i * batch_size][argmin]))
    

Customize a New Optimization Problem

  1. Go to ./test_func/base.py for the implementation of the base class. A new problem should be a derived class that properly implements all the required methods of the base class.

  2. For different types of optimization problem, see examples in ./test_func/mixed.py, ./test_func/categorical.py, ./test_func/continuous.py, respectively

  3. Edit the appropriate imports and other specifications and run from test.py as usual.

Citing SMKBO

If you use SMKBO, please cite the following paper:

@misc{zhang2025spectralmixturekernelsbayesian,
      title={Spectral Mixture Kernels for Bayesian Optimization}, 
      author={Yi Zhang and Cheng Hua},
      year={2025},
      eprint={2505.17393},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2505.17393}, 
}

License

SMKBO is MIT licensed, as found in the LICENSE file.

Acknowledgements

This code repository uses materials from the following public repositories. The authors thank the respective repository maintainers

  1. CASMOPOLITAN: Wan, X., Nguyen, V., Ha, H., Ru, B., Lu, C. & Osborne, M.A.. (2021). Think Global and Act Local: Bayesian Optimisation over High-Dimensional Categorical and Mixed Search Spaces. Proceedings of the 38th International Conference on Machine Learning (ICML). Code repo: https://github.com/xingchenwan/Casmopolitan.
  2. BoTorch: M. Balandat, B. Karrer, D. R. Jiang, S. Daulton, B. Letham, A. G. Wilson, and E. Bakshy. (2020). BoTorch: A Framework for Efficient Monte-Carlo Bayesian Optimization. Advances in Neural Information Processing Systems 33 (NIPS 33). Code repo: https://github.com/pytorch/botorch.

Project details


Download files

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

Source Distribution

smkbo-0.0.1.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

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

smkbo-0.0.1-py3-none-any.whl (46.7 kB view details)

Uploaded Python 3

File details

Details for the file smkbo-0.0.1.tar.gz.

File metadata

  • Download URL: smkbo-0.0.1.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for smkbo-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f85fd690597f4044381921eb9dab3eed2193439951eb9ca8c723e9de99390d0b
MD5 ed9d8d70e4aaef13bead053ca82b1657
BLAKE2b-256 04d29d43c22a5b22b1d8f867d885e69efa781fcd28573cb97848020e602c02c9

See more details on using hashes here.

File details

Details for the file smkbo-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: smkbo-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 46.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for smkbo-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db28dcf0b1f80895e014ae96d5e4a8a9c5ea098414c83f7508acc4f994840255
MD5 288e236a9cf76340d62f8f9085acca34
BLAKE2b-256 9649068c39b273bbb5503f2830e5384c19bb2d2335198468784acb5b16bb4b9f

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