Code for the paper Generalized Linear Bandits: Almost Optimal Regret with One-Pass Update by Yu-Jie Zhang, Sheng-An Xu, Peng Zhao and Masashi Sugiyama.
Clone the repository and run:
$ pip install -r requirements.txt
This code base implements GLB-OMD (Our main algorithm). Other baseline algorithms include various generalized linear bandit algorithms and algorithms tailored to logistic bandits. The references of the implemented algorithms are as follows:
OFUGLBfrom Lee et al. 2024RS-GLinUCBfrom Sawarni et al. 2024ECOLogfrom Faury et al. 2022OFULogPlusfrom Lee et al. 2023OFULog-rfrom Abeille et al. 2021GLOCfrom Jun et al. 2017GLM-UCBfrom Filippi et al. 2010
The code of the algorithms above is mostly adapted from GLBandit_Limited_Adaptivity and logistic_bandit
The codebase currently supports the following generalized linear models:
- Logistic Bandit: Binary rewards with sigmoid link function
- Poisson Bandit: Count-based rewards with exponential link function
This repository contains comprehensive experiments comparing GLB-OMD with generalized linear bandit algorithms and algorithms tailored to logistic bandits. Experiments can be run using either Jupyter notebooks or the provided Python scripts for better automation and parameter control.
For automated experimentation with configurable parameters, use the provided Python scripts:
# Logistic bandit experiments
python run_experiments.py --model logistic --num-trials 10 -S 3.0 -T 3000
# Poisson bandit experiments
python run_experiments.py --model poisson --num-trials 10 -S 5.0 -T 3000
# Custom configuration
python run_experiments.py --model logistic -d 10 -K 50 --algorithms GLBOMD OFUGLB GLM-UCB# Covertype dataset experiments
python run_covertype_experiments.py --num-trials 10 -T 1000 -K 60
# Different target class and parameters
python run_covertype_experiments.py --target-class 3 -K 80 --num-features 15For detailed usage examples, see:
experiment_examples.md- Synthetic data experimentscovertype_experiments_examples.md- Real data experiments
- Script:
run_experiments.py - Features:
- Configurable parameters: model (logistic/poisson), algorithms, trials, dimension, theta norm, arms, horizon
- Automated result saving and plotting
- Command-line interface for easy automation
- Usage:
python run_experiments.py --model logistic -S 5.0 --num-trials 20 python run_experiments.py --model poisson -d 10 -K 30 -T 5000
- Logistic:
experiments/logb/logb_all.ipynb - Poisson:
experiments/poisson/poisson_all.ipynb - Description: Interactive experiments with various parameter configurations
- Metrics: Cumulative regret and running time comparison
- Results: Stored in
Results/logb/andResults/poisson/
- Script:
run_covertype_experiments.py - Dataset: Forest Cover Type dataset from UCI ML Repository
- Features:
- Configurable parameters: algorithms, trials, horizon, arms, target class, features
- Automatic data preprocessing and K-means clustering
- Multiple output formats (regret, time, combined plots)
- Setup:
- Uses configurable number of numerical features (default: 10)
- Binary classification task (any class vs. others)
- K-means clustering to create configurable number of arms
- Logistic reward model
- Usage:
python run_covertype_experiments.py --target-class 2 -K 60 --num-trials 10 python run_covertype_experiments.py --num-features 20 -T 2000
- Location:
experiments/real_data/covertype.ipynb - Evaluation:
- Cumulative regret over time horizon
- Running time analysis with log-scale plotting
- Error bars showing confidence intervals over multiple trials
- Results: Performance plots and statistics stored in
Results/real_data/
- Location:
experiments/plot_regret_all.ipynb - Purpose: Generates comprehensive regret comparison plots across all algorithms
- Features:
- Multi-algorithm regret curves
- Confidence intervals based on multiple runs
- Publication-ready plots with customizable styling
- Location:
experiments/plot_time_all.ipynbandexperiments/run_time.ipynb - Purpose: Analyzes computational efficiency of different algorithms
- Features:
- Runtime vs. regret scatter plots
- Log-scale time comparison
- Memory usage analysis
Required Parameters:
--model {logistic,poisson}: Model type
Optional Parameters:
--algorithms [ALGO ...]: Algorithm names (default: all for model)--num-trials INT: Number of trials (default: 10)-d, --dimension INT: Parameter vector dimension (default: 5)-S, --theta-norm FLOAT: Parameter norm (default: 3.0)-K, --arms INT: Number of arms (default: 20)-T, --horizon INT: Time horizon (default: 3000)--seed INT: Random seed (default: 109832)--output-dir PATH: Output directory (default: "Results")
Key Parameters:
--data-path PATH: Path to covtype.data file--algorithms [ALGO ...]: Algorithm names (default: all)--num-trials INT: Number of trials (default: 10)-T, --horizon INT: Time horizon (default: 1000)-K, --arms INT: Number of arms/clusters (default: 60)--target-class {1-7}: Forest cover type as positive class (default: 2)--num-features INT: Number of features to use (default: 10)--delta FLOAT: Confidence parameter (default: 0.01)--kappa FLOAT: Regularization parameter (default: 200)--S FLOAT: Maximum parameter norm (default: 6)
Both scripts generate comprehensive outputs:
Result Files:
.pklfiles: Pickle files with regret and timing data for further analysis.pdffiles: Publication-ready plots (regret curves, runtime comparisons)
Synthetic Data:
Results/logistic/orResults/poisson/- Files:
regret_d{d}_K{K}_T{T}_S{S}_trials{trials}.{pkl,pdf}
Real Data:
Results/real_data/- Files:
regret_T{T}_K{K}_class{class}_feat{feat}_trials{trials}.{pkl,pdf} - Additional:
time_*.pdf,combined_*.pdf,metadata_*.pkl
If you find this work useful in your research, please consider citing it.
@misc{zhang2025generalizedlinearbanditsoptimal,
title={Generalized Linear Bandits: Almost Optimal Regret with One-Pass Update},
author={Yu-Jie Zhang and Sheng-An Xu and Peng Zhao and Masashi Sugiyama},
year={2025},
eprint={2507.11847},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2507.11847},
}