Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
PyPI

bayesian-optimization 3.0.1

pip install bayesian-optimization

Latest version

Released:

Bayesian Optimization package

Verified details

These details have beenverified by PyPI
Maintainers
Avatar for bwheelz36 from gravatar.combwheelz36Avatar for fmfnogueira from gravatar.comfmfnogueiraAvatar for till-m from gravatar.comtill-m

Unverified details

These details havenot been verified by PyPI
Meta
  • License: MIT License (The MIT License (MIT))
  • Author:Fernando Nogueira
  • Requires: Python <4.0, >=3.9

Project description



Bayesian Optimization

testsdocs - stableCodecovPypiPyPI - Python Version

Pure Python implementation of bayesian global optimization with gaussianprocesses.

This is a constrained global optimization package built upon bayesian inferenceand gaussian processes, that attempts to find the maximum value of an unknownfunction in as few iterations as possible. This technique is particularlysuited for optimization of high cost functions and situations where the balancebetween exploration and exploitation is important.

Installation

  • pip (via PyPI):
$pipinstallbayesian-optimization
  • Conda (via conda-forge):
$condainstall-cconda-forgebayesian-optimization

How does it work?

See thedocumentation for how to use this package.

Bayesian optimization works by constructing a posterior distribution of functions (gaussian process) that best describes the function you want to optimize. As the number of observations grows, the posterior distribution improves, and the algorithm becomes more certain of which regions in parameter space are worth exploring and which are not, as seen in the picture below.

BayesianOptimization in action

As you iterate over and over, the algorithm balances its needs of exploration and exploitation taking into account what it knows about the target function. At each step a Gaussian Process is fitted to the known samples (points previously explored), and the posterior distribution, combined with a exploration strategy (such as UCB (Upper Confidence Bound), or EI (Expected Improvement)), are used to determine the next point that should be explored (see the gif below).

BayesianOptimization in action

This process is designed to minimize the number of steps required to find a combination of parameters that are close to the optimal combination. To do so, this method uses a proxy optimization problem (finding the maximum of the acquisition function) that, albeit still a hard problem, is cheaper (in the computational sense) and common tools can be employed. Therefore Bayesian Optimization is most adequate for situations where sampling the function to be optimized is a very expensive endeavor. See the references for a proper discussion of this method.

This project is under active development. If you run into trouble, find a bug or noticeanything that needs correction, please let us know by filing an issue.

Basic tour of the Bayesian Optimization package

1. Specifying the function to be optimized

This is a function optimization package, therefore the first and most important ingredient is, of course, the function to be optimized.

DISCLAIMER: We know exactly how the output of the function below depends on its parameter. Obviously this is just an example, and you shouldn't expect to know it in a real scenario. However, it should be clear that you don't need to. All you need in order to use this package (and more generally, this technique) is a functionf that takes a known set of parameters and outputs a real number.

defblack_box_function(x,y):"""Function with unknown internals we wish to maximize.    This is just serving as an example, for all intents and    purposes think of the internals of this function, i.e.: the process    which generates its output values, as unknown.    """return-x**2-(y-1)**2+1

2. Getting Started

All we need to get started is to instantiate aBayesianOptimization object specifying a function to be optimizedf, and its parameters with their corresponding bounds,pbounds. This is a constrained optimization technique, so you must specify the minimum and maximum values that can be probed for each parameter in order for it to work

frombayes_optimportBayesianOptimization# Bounded region of parameter spacepbounds={'x':(2,4),'y':(-3,3)}optimizer=BayesianOptimization(f=black_box_function,pbounds=pbounds,random_state=1,)

The BayesianOptimization object will work out of the box without much tuning needed. The main method you should be aware of ismaximize, which does exactly what you think it does.

There are many parameters you can pass to maximize, nonetheless, the most important ones are:

  • n_iter: How many steps of bayesian optimization you want to perform. The more steps the more likely to find a good maximum you are.
  • init_points: How many steps ofrandom exploration you want to perform. Random exploration can help by diversifying the exploration space.
optimizer.maximize(init_points=2,n_iter=3,)
|   iter    |  target   |     x     |     y     |-------------------------------------------------|  1        | -7.135    |  2.834    |  1.322    ||  2        | -7.78     |  2.0      | -1.186    ||  3        | -19.0     |  4.0      |  3.0      ||  4        | -16.3     |  2.378    | -2.413    ||  5        | -4.441    |  2.105    | -0.005822 |=================================================

The best combination of parameters and target value found can be accessed via the propertyoptimizer.max.

print(optimizer.max)>>>{'target':-4.441293113411222,'params':{'y':-0.005822117636089974,'x':2.104665051994087}}

While the list of all parameters probed and their corresponding target values is available via the propertyoptimizer.res.

fori,resinenumerate(optimizer.res):print("Iteration{}:\n\t{}".format(i,res))>>>Iteration0:>>>{'target':-7.135455292718879,'params':{'y':1.3219469606529488,'x':2.8340440094051482}}>>>Iteration1:>>>{'target':-7.779531005607566,'params':{'y':-1.1860045642089614,'x':2.0002287496346898}}>>>Iteration2:>>>{'target':-19.0,'params':{'y':3.0,'x':4.0}}>>>Iteration3:>>>{'target':-16.29839645063864,'params':{'y':-2.412527795983739,'x':2.3776144540856503}}>>>Iteration4:>>>{'target':-4.441293113411222,'params':{'y':-0.005822117636089974,'x':2.104665051994087}}

Minutiae

Citation

If you used this package in your research, please cite it:

@Misc{,    author = {Fernando Nogueira},    title = {{Bayesian Optimization}: Open source constrained global optimization tool for {Python}},    year = {2014--},    url = " https://github.com/bayesian-optimization/BayesianOptimization"}

If you used any of the advanced functionalities, please additionally cite the corresponding publication:

For theSequentialDomainTransformer:

@article{    author = {Stander, Nielen and Craig, Kenneth},    year = {2002},    month = {06},    pages = {},    title = {On the robustness of a simple domain reduction scheme for simulation-based optimization},    volume = {19},    journal = {International Journal for Computer-Aided Engineering and Software (Eng. Comput.)},    doi = {10.1108/02644400210430190}}

For constrained optimization:

@inproceedings{gardner2014bayesian,    title={Bayesian optimization with inequality constraints.},    author={Gardner, Jacob R and Kusner, Matt J and Xu, Zhixiang Eddie and Weinberger, Kilian Q and Cunningham, John P},    booktitle={ICML},    volume={2014},    pages={937--945},    year={2014}}

For optimization over non-float parameters:

@article{garrido2020dealing,  title={Dealing with categorical and integer-valued variables in bayesian optimization with gaussian processes},  author={Garrido-Merch{\'a}n, Eduardo C and Hern{\'a}ndez-Lobato, Daniel},  journal={Neurocomputing},  volume={380},  pages={20--35},  year={2020},  publisher={Elsevier}}

Project details

Verified details

These details have beenverified by PyPI
Maintainers
Avatar for bwheelz36 from gravatar.combwheelz36Avatar for fmfnogueira from gravatar.comfmfnogueiraAvatar for till-m from gravatar.comtill-m

Unverified details

These details havenot been verified by PyPI
Meta
  • License: MIT License (The MIT License (MIT))
  • Author:Fernando Nogueira
  • Requires: Python <4.0, >=3.9

Download files

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

Source Distribution

bayesian_optimization-3.0.1.tar.gz (34.4 kBview details)

UploadedSource

Built Distribution

bayesian_optimization-3.0.1-py3-none-any.whl (36.8 kBview details)

UploadedPython 3

File details

Details for the filebayesian_optimization-3.0.1.tar.gz.

File metadata

  • Download URL:bayesian_optimization-3.0.1.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.1 Linux/6.11.0-1015-azure

File hashes

Hashes for bayesian_optimization-3.0.1.tar.gz
AlgorithmHash digest
SHA256549599e422c66d225f8737593b7bc477488c8e4a786628c146df17878cc270e6
MD530ca0eecaebdd3ce32390f4aedded1f6
BLAKE2b-25673ccb6368067e20d2d8c4e8d49d3dc3640e45b743363ebab463f5092384da7e9

See more details on using hashes here.

File details

Details for the filebayesian_optimization-3.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bayesian_optimization-3.0.1-py3-none-any.whl
AlgorithmHash digest
SHA2567277a227037cad15416f223b9307f17108e7a70845ca81eac55c68cb7ed68038
MD5d9cb76255d51546551ca61f1a0484372
BLAKE2b-2560a3cba4ecd25955f35f07629bae4f91427cf5e8bb2af90e716643ce90aef2c4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security SponsorDatadog MonitoringFastly CDNGoogle Download AnalyticsPingdom MonitoringSentry Error loggingStatusPage Status page

[8]ページ先頭

©2009-2025 Movatter.jp