VariationalSparseBayes
A PyTorch library for stochastic variational inference with sparsity inducing priors.
A comparison plot for sparse Bayesian regression with a half-cauchy prior (L), support vector regression (C), and the relevance vector machine (R). We see the half-cauchy prior provides a more sparse solution and better error bars.
What is VariationalSparseBayes?
This package provides an implementation of the algorithm described in Louizos et. al. (2017) for use on a broad class of machine learning problems.
Installation
pip install variationalsparsebayes
Usage
The library provides a high-level interface with some prebuilt sparse Bayesian models and a low-level interface for building custom sparse Bayesian models.
High-level interface
The library provides a few sparse Bayesian models:
- sparse polynomial regression
- sparse Bayesian neural networks.
- sparse learning with precomputed features
To implement your own linear model, you can inherit from the SparseFeaturesLibrary class. Note that I haven't implemented the "group" sparsity idea presented in Louizos et. al. (2017). Sparsification is performed at the parameter level (meaning far less computational savings).
Low-level interface
The most important class provided by the library is the SVIHalfCauchyPrior. The class inherits from nn.Module. The user is responsible for (i) transforming a batch of weights from the variational posterior into a batch of predictions and (ii) adding the KL-divergence provided by the prior onto the negative ELBO.
from torch import nn
from variationalsparsebayes import SVIHalfCauchyPrior
class MyModel(nn.Module):
def __init__(self, num_params: int):
super().__init__()
# we initialize the prior with tau=1e-5 (see https://arxiv.org/pdf/1705.08665.pdf)
self.prior = SVIHalfCauchyPrior(num_params, 1e-5)
...
def forward(self, x, num_reparam_samples):
w_samples = self.prior.get_reparam_weights(num_reparam_samples)
sparse_index = self.prior.sparse_index
# user transforms weights and inputs into predictions
...
def elbo(self, x, y):
return log_like(x, y) - self.prior.kl_divergence()
model = MyModel(num_params)
...
When it comes time to sparsify the approximate posterior run:
model.prior.update_sparse_index()
# get the index of all weights which remain after sparsification
model.prior.sparse_index
Metadata
Release files for variationalsparsebayes 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| variationalsparsebayes-0.3.1.tar.gz | 22.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| variationalsparsebayes-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.9 kB
Release files / variationalsparsebayes-0.3.1.tar.gz
| Download URL | variationalsparsebayes-0.3.1.tar.gz |
|---|---|
| Size | 22.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e683a3b48f520d288a3446a6f4bed93a4d1be88fb421a1aa8bb90b7eef1d8a9e
|
|
BLAKE2b-256 checksum How to use checksums |
f611344b5cc117a66602cd01b28ecd5d657c7b7a151469bce12f6ebf0f5d668f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.13 Darwin/23.2.0
|
Release files / variationalsparsebayes-0.3.1-py3-none-any.whl
| Download URL | variationalsparsebayes-0.3.1-py3-none-any.whl |
|---|---|
| Size | 23.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6db4e45a65700f8a5a7cbf635b1bf850b3d2a684968749b4759d7eb15b582ae7
|
|
BLAKE2b-256 checksum How to use checksums |
6b026ecd8dcd277f951613f4b7a3e8673b5d917cfce83252805fc47f481f3ac1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.13 Darwin/23.2.0
|
Security for variationalsparsebayes 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.