Skip to main content

PAC Bayes Bound toolset

Project description

PAC Bayes Bounds Framework - A Toolkit for PAC-Bayes Analysis

Docs PyPI GitHub release License Archive

About

The pacbb repository provides a collection of handy tools for PAC Bayes bounds evaluation. It is designed to simplify the work of PAC Bayes enthusiasts by offering various utilities and resources for easier implementation and experimentation.

We have prepared an arXiv paper that outlines the structure of pacbb, demonstrates its usage, structure, and presents a series of experiments conducted using the toolkit.

Links

Installation

To install the pacbb package, use the following command:

pip install pacbb

Example

For a complete example, please refer to the full script in scripts/generic_train.py.

Here is a part of this script showing how to convert a standard model to a Probabilistic Neural Network (ProbNN), which can be used for PAC Bayes boundaries calculation:

from core.model import dnn_to_probnn
from core.distribution import GaussianVariable
from core.distribution.utils import from_random, from_zeros

# Initialize prior
prior_reference = from_zeros(model=model, 
                             rho=torch.log(torch.exp(torch.Tensor([sigma])) - 1), 
                             distribution=GaussianVariable, 
                             requires_grad=False)

prior = from_random(model=model, 
                    rho=torch.log(torch.exp(torch.Tensor([sigma])) - 1), 
                    distribution=GaussianVariable, 
                    requires_grad=True)

# Convert the model to ProbNN
dnn_to_probnn(model, prior, prior_reference)

Distributions creation and model conversion are explained in details in the arXive paper.

Experiments

To run the experiments from the arXiv paper, follow these steps:

  1. Clone the repository:
git clone https://github.com/Yauhenii/pacbb.git
  1. Set up the environment:
conda create --prefix=./conda_env python=3.11 pip install -r requirements.txt
  1. Create your desired experiment configuration:
./config
  1. Run the configuration using the Python script directly:
export PYTHONPATH="${PYTHONPATH}:$(pwd)" 
python scripts/ivon_generic_train.py --config ./config/ivon_generic_configs/best_ivon.yaml

Alternatively, run multiple configuration files using a bash script wrapper:

export PYTHONPATH="${PYTHONPATH}:$(pwd)" 
bash jobs/runnig_ivon_configs_in_the_folder.sh ./config/ivon_generic_configs

Contribution

Contributions to pacbb are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch from main.
  3. Make your changes.
  4. Submit a pull request to the main branch.

Please use the following naming conventions for your branches:

  • feature/short-description for new feature proposals.
  • bugfix/short-description for bug fixes.
  • experiments/short-description for changes related to the scripts module.

Acknowledgments

Special thanks to Vincent Fortuin and Alex Immer for their supervision, support, and contributions to this project. Their guidance has been invaluable throughout the development of pacbb.

Authors

  • Yauhenii (Yauheni Mardan)

  • maxtretiakov (Maksym Tretiakov)

Citing

If you use this code, please cite as:

@software{mardan2025pacbbframework,
  author       = {Yauheni Mardan and Maksym Tretiakov and Alexander Immer and Vincent Fortuin},               
  title        = {pacbb: PAC-Bayes Bounds Evaluation Framework},
  month        = {march},
  year         = {2025},
  doi          = {10.5281/zenodo.15082669},
  url          = {https://doi.org/10.5281/zenodo.15082670}
  howpublished = {https://github.com/fortuinlab/pacbb}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pacbb-0.1.2.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pacbb-0.1.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file pacbb-0.1.2.tar.gz.

File metadata

  • Download URL: pacbb-0.1.2.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pacbb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 44c3bb18eb7e48b10d288072b3aeabd50ffcbde0bacb4a4f1a7c876c747d6e56
MD5 af5d4085ecca09e3f9e06288090730ff
BLAKE2b-256 5a786885fa3b124df921b52f9f1525c797d16e607f29a89d244de6d94ff420a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pacbb-0.1.2.tar.gz:

Publisher: publish.yml on fortuinlab/pacbb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pacbb-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pacbb-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pacbb-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8f87624d8ebea4673319b6f012def4c4b087e71e09815a4d2e001f16a5ae64bc
MD5 1c68972695af0a60cc4b0e5560d4a7fc
BLAKE2b-256 bf5d584eb9149accdc0cd7b8b54cad3f6bc0ff7b499050d1aa9d20ac5a1a7004

See more details on using hashes here.

Provenance

The following attestation bundles were made for pacbb-0.1.2-py3-none-any.whl:

Publisher: publish.yml on fortuinlab/pacbb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page