This repository contains the code for the paper Adaptive Prior Selection in Gaussian Process Bandits with Thompson Sampling.
All commands below are run from the repository root.
The Python virtual environment is created with uv. The experiment scripts activate the environment .venv_$(uname -m), i.e. .venv_x86_64 or .venv_aarch64 (the experiments were run on clusters with different CPU architectures). Create it on each architecture with:
UV_PROJECT_ENVIRONMENT=.venv_$(uname -m) uv sync
The plotting scripts use SciencePlots to style the plots and may require LaTeX to be installed locally.
The preprocessing scripts in data_scripts/ write the train/test splits used by the experiments to data/.
Intel: The Intel Berkeley Research lab data was collected by Peter Bodik, Wei Hong, Carlos Guestrin, Sam Madden, Mark Paskin and Romain Thibaux. Download data.txt.gz from that page, extract it to data/intel.txt and run python data_scripts/intel.py.
PNW precipitation: Daily precipitation on a 50 km grid over the Pacific Northwest, 1949–1994, from M. Widmann and C. S. Bretherton, "Validation of mesoscale precipitation in the NCEP reanalysis using a new gridcell dataset for the northwestern United States", Journal of Climate 13(11), 1936–1950, 2000. The data could previously be downloaded here and is included in data/ with the permission of the authors. Run python data_scripts/pnwrain.py.
PeMS: Traffic speeds from the Caltrans Performance Measurement System (PeMS), California Department of Transportation. The data can be downloaded after creating an account. Once logged in, navigate to the data clearinghouse and select Type: Station 5-Minute and District 4. After pressing submit, you can now select data from 2023 by pressing 23. The data has to be downloaded manually one day at a time. To speed up this process, open the developer tools in your browser and download data for the first day. Under the network tab, right click the download and copy the curl header into a file called curl_config. Then run python data_scripts/pems_download.py curl_config to automatically download the data from 2023 to data/pems/all2023/. To preprocess the data, run python data_scripts/pems_parse.py.
The experiment scripts assume you are running SLURM on a cluster. To run the scripts with SLURM, you have to run commands in the following way:
sbatch --array=1-500 experiment_scripts/kernels.sh
The scalinglengthscales.sh and subspace.sh scripts require you to provide the number of priors via the flag -P:
sbatch --array=1-500 experiment_scripts/scalinglengthscales.sh -P 8
If your cluster requires an account or partition, pass them to sbatch, e.g. sbatch -A <account> -p <partition> --array=1-500 experiment_scripts/kernels.sh.
The experiments can be run without SLURM by passing the variable SLURM_ARRAY_TASK_ID manually:
SLURM_ARRAY_TASK_ID=1 experiment_scripts/kernels.sh
The scripts in experiment_scripts/ and their output directories in experiment_output/:
| Script | Experiment | Output |
|---|---|---|
kernels.sh |
Kernel | kernels/ |
scalinglengthscales.sh -P {8,16,32,64,128} |
Lengthscale | scalinglengthscales<P>/ |
subspace.sh -P {5,8,12,16} |
Subspace | subspace-ol-16-4-3-<P>/ |
intel.sh, pems.sh, pnwrain.sh |
Real-world data | intel/, pems/, pnwrain/ |
misspeclengthscales_hyperprior.sh |
Misspecified prior probabilities | misspecifiedlengthscales8/ |
long/kernels.sh, long/scalinglengthscales.sh -P 8, long/subspace.sh -P 5 |
Horizon 1500 (HP-GP-TS and EEI) | <experiment>_long1500/ |
The specifications experiment_specfiles/scalinglengthscales<P>.yml and experiment_specfiles/subspace/overlapping/*.yml are generated by python experiment_specfiles/create_lengthscale_specs.py and python experiment_specfiles/subspace/create_subspace_specs.py.
The kernels-optvar/, scalinglengthscales8-optvar/ and subspace-ol-16-4-3-5-optvar/ directories used by plot/optvar.py are reruns of kernels.sh, scalinglengthscales.sh -P 8 and subspace.sh -P 5 with the same settings and extra logging of the posterior variance at the optimum for PE-GP-TS. They were run on an aarch64 cluster, whereas the main runs were run on x86_64. Since the random numbers differed between the architectures, the runs are kept separate.
Run the plot scripts from the repository root, e.g. python plot/cumulative_regret.py. Figures and tables are written to wip_figures/. Parsed experiment logs are cached in plot_data/; pass --refresh-cache to re-read the logs after (re-)running experiments. Intel seed 74 is excluded from all Intel results since it is an extreme outlier in terms of regret that skews the results (see INTEL_EXCLUDED_SEED_PATTERN in plot/utils.py).
| Script | Experiments | Outputs |
|---|---|---|
plot/information_gain.py |
None, run before plot/entropy.py |
migs.pdf, mig_kernel.pdf |
plot/cumulative_regret.py |
Kernel, Lengthscale (P=8), Subspace (P=5), their _long1500 runs and real-world |
syntheticregret*.pdf, realworldregret.pdf, joint_final_regret.tex, long_regret.tex |
plot/scaling.py |
All Lengthscale and Subspace runs | regret_final_scaling.pdf, regret_lengthscale.tex, regret_subspace.tex |
plot/confusion_matrices.py |
Kernel, Lengthscale (P=8), Subspace (P=5) | confmats_*.pdf |
plot/elimination.py |
Kernel, Lengthscale (P=8), Subspace (P=5) and real-world | elimination_*.pdf |
plot/entropy.py |
Kernel, Lengthscale (P=8), Subspace (P=5) and real-world | entropy*.pdf, elim_entropy_kernel.pdf, mig_elim_entropy_kernel.pdf |
plot/misspec_regret.py |
Misspecified prior probabilities | misspecification_regret.pdf, misspec_regret.{md,tex} |
plot/optvar.py |
*-optvar runs |
optvar.pdf, optvarsum.md |
The illustrations made by visualizations/DiscretePriorVisualization.py (run from the repository root), visualizations/DiscretePriorViz.ipynb and visualizations/EliminationVisualization.ipynb are saved in subdirectories of wip_figures/ and use the prior specifications in visualization_specfiles/.
@inproceedings{sandberg2026adaptive,
title = {Adaptive Prior Selection in {G}aussian Process Bandits with {T}hompson Sampling},
author = {Sandberg, Jack and Haghir Chehreghani, Morteza},
booktitle = {Advances in Neural Information Processing Systems},
year = {2026},
note = {To appear},
url = {https://arxiv.org/abs/2502.01226}
}The code is released under the MIT License. The datasets belong to their respective owners, see Data.