SafeOpt is an algorithm for optimizing black-box functions that converges to the optimal reachable target point under safety constraints.
This repository provides an implementation of the SafeOpt algorithm proposed in the following paper:
Safe Exploration for Optimization with Gaussian Processes
Yanan Sui, Alkis Gotovos, Joel Burdick, Andreas Krause
International Conference on Machine Learning (ICML), 2015
PDF

The safe set (green bar), expanders (blue bar), and maximizers (red bar).
Python = 3.13
pip install -r requirements.txt && pip install -e .To get started, it is recommended to run the interactive notebooks in the examples folder. We provide 1-d and 2-d examples for the algorithm.
An example for 1-d:
import torch
from safeopt import SafeOpt
# Initialization
candidates = torch.linspace(0, 10, 100).unsqueeze(-1)
bounds = torch.tensor([[0.], [10.]])
train_X = candidates[[40, 70]]
train_Y = torch.tensor([[1.0, 0.3], [1.5, 0.8]]) # [objective, constraint]
fmin = torch.tensor([0.2])
lipschitz = torch.tensor([0.5])
algo = SafeOpt(
candidates=candidates,
bounds=bounds,
train_X=train_X,
train_Y=train_Y,
num_objectives=1,
num_constraints=1,
fmin=fmin,
lipschitz=lipschitz,
covar_module=None, # Use default RBF kernel
ci_beta=2.0,
enable_fit=False,
)
# Optimization
for _ in range(20):
x_next = algo.next()
if x_next is None: break
y_next = your_function(x_next) # Return [objective, constraint]
algo.update(x_next, y_next)@InProceedings{pmlr-v37-sui15,
title={Safe Exploration for Optimization with Gaussian Processes},
author={Sui, Yanan and Gotovos, Alkis and Burdick, Joel and Krause, Andreas},
booktitle={Proceedings of the 32nd International Conference on Machine Learning},
year={2015}
}