Skip to content
A library for doing Bayesian Optimization using Gaussian Processes (blackbox optimizer) in Go/Golang.
Branch: master
Clone or download
d4l3k Merge pull request #9 from c-bata/use-go-modules
Use go modules + fix build
Latest commit 65bb2b1 Jul 22, 2019

go-bayesopt Build Status GoDoc

A library for doing Bayesian Optimization using Gaussian Processes (blackbox optimizer) in Go/Golang.

This project is under active development, if you find a bug, or anything that needs correction, please let me know.

Simple Example

package main

import (


func main() {
  X := bayesopt.UniformParam{
    Max: 10,
    Min: -10,
  o := bayesopt.New(
  // minimize x^2+1
  x, y, err := o.Optimize(func(params map[Param]float64) float64 {
    return math.Pow(params[X], 2) + 1
  if err != nil {
  log.Println(x, y)

How does it work?


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.


go-bayesopt is licensed under the MIT license.

You can’t perform that action at this time.