Skip to content

yjzzzzz/One-pass_GLB

Repository files navigation

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.

Installation

Clone the repository and run:

$ pip install -r requirements.txt 

Usage

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:

The code of the algorithms above is mostly adapted from GLBandit_Limited_Adaptivity and logistic_bandit

Supported Models

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

Experiments

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.

Quick Start with Python Scripts

For automated experimentation with configurable parameters, use the provided Python scripts:

Synthetic Data Experiments

# 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

Real Data Experiments

# 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 15

For detailed usage examples, see:

Experiment Categories

1. Synthetic Data Experiments

Python Script (Recommended)

  • 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

Jupyter Notebooks (Original)

  • 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/ and Results/poisson/

2. Real Data Experiments

Python Script (Recommended)

  • 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

Jupyter Notebook (Original)

  • 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/

3. Performance Analysis

Regret Analysis

  • 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

Runtime Analysis

  • Location: experiments/plot_time_all.ipynb and experiments/run_time.ipynb
  • Purpose: Analyzes computational efficiency of different algorithms
  • Features:
    • Runtime vs. regret scatter plots
    • Log-scale time comparison
    • Memory usage analysis

Script Parameters

Synthetic Data Experiments (run_experiments.py)

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")

Real Data Experiments (run_covertype_experiments.py)

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)

Output Files

Both scripts generate comprehensive outputs:

Result Files:

  • .pkl files: Pickle files with regret and timing data for further analysis
  • .pdf files: Publication-ready plots (regret curves, runtime comparisons)

Synthetic Data:

  • Results/logistic/ or Results/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

Reference

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}, 
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors