How david-cortes/contextualbandits works
Project type and purpose
• This is an open-source Python library for implementing and experimenting with contextual bandit algorithms (online learning, off-policy evaluation, policy evaluation).
• It provides research-grade implementations of many algorithms (LinUCB, Thompson Sampling variants, OffsetTree, Doubly-Robust estimators, etc.), with performance-critical parts in Cython/C++.
File structure
Top-level:
• setup.py, pyproject.toml, setup.cfg, requirements.txt – packaging and build scripts (PEP 517, setuptools configuration, Cython compilation flags).
• LICENSE, MANIFEST(.in), .gitignore, .gitattributes – repository metadata and packaging manifests.
• README.md – project overview, usage, algorithms list, dependency notes.
• docs/ – Sphinx documentation (conf.py, index.rst, Makefile, ReadTheDocs config).
• example/ – Jupyter notebooks demonstrating typical workflows (online, off-policy, evaluation).
• plots/ – PNG figures used in README or docs.
Package “contextualbandits/”:
• __init__.py – package entry point and metadata.
• _cy_utils.pyx & cy_cpp_helpers.cpp – Cython wrappers and helper C++ code for performance-critical linear algebra.
• linreg/ – incremental linear regression implementation with Cython kernels (linreg_double.pyx, linreg_float.pyx, untyped .pxi).
• online.py – online learning policies (UCB, Thompson Sampling, Epsilon-Greedy, etc.).
• offpolicy.py – counterfactual learning algorithms (Offset Tree, Doubly-Robust).
• evaluation.py – policy evaluation methods (Rejection Sampling, NCIS, Doubly-Robust evaluation).
• utils.py – shared utilities (matrix conversions, CSR handling, hyperparameter smoothing).
README for additional insights
• Core use-cases: prototyping algorithms, reproducing research, learning about contextual bandits.
• Highlights extensibility via any classifier with predict_proba/decision_function.
• Notes on Cython compilation flags (-march=native), cross-machine compatibility, pickling via cloudpickle/dill.
• References to academic papers and performance notes.