VBPCApy
Variational Bayesian PCA (Ilin & Raiko, 2010) with support for missing data, sparse masks, optional bias terms, and an orthogonal post-rotation to a PCA basis. The implementation follows the original MATLAB reference while adding Python-native APIs, fast C++ extensions, and runtime autotuning.
Documentation · API Reference · Tutorials
Statement of need
Missing values are common in scientific and industrial tabular datasets, but many analysis pipelines either impute first (masking uncertainty) or drop incomplete samples. VBPCApy models missingness directly and exposes posterior uncertainty outputs alongside reconstructions, enabling uncertainty-aware latent-factor analysis in a single reproducible Python API.
Installation
From PyPI (pre-built wheels for Python 3.11–3.14, Linux/macOS/Windows):
pip install vbpca-py
With plotting support:
pip install vbpca-py[plot]
See the installation guide for building from source and Eigen setup.
Quick start
import numpy as np
from vbpca_py import VBPCA
# 50 features, 200 samples
x = np.random.randn(50, 200)
mask = np.ones_like(x) # 1 = observed, 0 = missing
model = VBPCA(n_components=5, maxiters=100)
scores = model.fit_transform(x, mask=mask)
recon = model.reconstruction_
var = model.variance_
More examples: quickstart, dense PCA tutorial, missing data & model selection, genomics dosage data, and sparse data.
Features
- Dense or sparse data with explicit missing-entry masks
- Optional bias estimation and rotation to PCA-aligned solution
- Posterior covariances for scores and loadings; held-out probe RMS
- C++ extensions with runtime autotune for threading and memory
- Missing-aware preprocessing: one-hot, standard/minmax scaling, log, power, winsorize, auto-routing (
AutoEncoder) - Preflight data diagnostics via
check_data()/DataReport - scikit-learn-compatible estimator (
fit/transform/inverse_transform,get_params/set_params, cloning) — scikit-learn is an optional dependency - Model selection via
select_n_componentsandcross_validate_components - Configurable convergence: subspace angle, RMS/cost plateau, ELBO, curvature, composite rules, patience, with per-criterion enable/disable and custom ordering
- Convergence diagnostics (
n_iter_,converged_,convergence_reason_,learning_curve_, best-probe state metadata) and calibratedpredictive_variance_(includes observation noise) recommend_config(n, p, priority)— regime-aware default hyperparameters from a surrogate trade study
See the concept guides and API reference for full details.
Categorical component selection
Dense AutoEncoder and MissingAwareOneHotEncoder fits expose an
encoding_schema_ snapshot (EncodingSchema / EncodedVariable, exported
from vbpca_py). Pass it to CV to hold out whole variable cells and decode
single-binary, dropped-reference, centered and weighted indicators before
categorical scoring:
from vbpca_py import AutoEncoder, CVConfig, cross_validate_components
encoder = AutoEncoder(
column_types=["categorical", "categorical", "continuous"],
drop="first",
block_weighting="equal_variance",
handle_unknown="raise",
)
Z = encoder.fit_transform(X) # samples x encoded features
best_k, results = cross_validate_components(
Z.T,
components=range(5),
config=CVConfig(encoding_schema=encoder.encoding_schema_, metric="brier"),
)
Continuous and ordinal variables contribute to encoded probe RMS, but are
excluded from nominal categorical scores. Gaussian reconstructions are
decoded, clipped at 1e-6 and normalized as approximate category
probabilities; this is not a calibrated categorical likelihood. Equivalent
decoded predictions have equivalent scores; refitting different encodings
can yield different predictions. Schema-free categorical selection requires
full unweighted one-hot blocks and rejects singleton groups and transformed
targets. feature_groups alone cannot identify binary versus numeric columns.
This API splits an already encoded matrix. A schema describes the transform;
use the raw-table API below when learning preprocessing within CV folds.
Unknown categories cannot be distinguished from a dropped reference when
handle_unknown="ignore"; use "raise" when scoring new raw data. See the
model-selection guide and
benchmark validation note.
Raw-table component selection
cross_validate_raw_components accepts samples × original variables, with
NaNs or an explicit observation mask. It holds out original variable cells
before fitting means, scales, categorical centering and block weights. A fresh
AutoEncoder is fitted once per fold and reused across every candidate rank,
including first-minimum early stopping.
from vbpca_py import AutoEncoder, CVConfig, cross_validate_raw_components
def make_encoder():
return AutoEncoder(
column_types=["categorical", "continuous", "ordinal"],
# External codebook; do not derive this from held-out values.
column_levels=[["no", "yes"], None, ["low", "medium", "high"]],
mean_center_ohe=True,
block_weighting="equal_variance",
handle_unknown="raise",
)
best_k, results, folds = cross_validate_raw_components(
X, encoder_factory=make_encoder, components=range(4),
config=CVConfig(n_splits=3, metric="brier", seed=11),
maxiters=200,
)
Declare column kinds explicitly. column_levels=None (or a None entry) learns
levels from training cells; a held-only unknown level raises an error. External
nominal vocabularies and ordinal orders support declared levels absent from
training. Each returned PreprocessedFold exposes original training/holdout
masks, encoded matrices, the fitted encoder and its schema;
prepare_raw_cv_folds constructs these without fitting candidate models.
Results include nominal Brier/log/accuracy scores and rmse_variable_j for each
numeric input column: continuous values in input units, ordinal values in
unrounded level-index units. Numeric summaries report contributing fold counts;
encoded prms is also retained. This predicts cells of the same samples;
sample-wise sklearn CV evaluates new samples. Run the complete mixed-data
example with just example-raw-cv, or
python scripts/example_raw_cell_cv.py after installing the package.
Development
The 0.4.6 release validation describes the paired fitting-compatibility check and package/adoption gates. General scoring and benchmark validation commands are in scripts/benchmark_study.md.
git clone https://github.com/yoavram-lab/VBPCApy.git
cd VBPCApy
uv sync --extra dev --extra plot
just ci # lint + typecheck + test
just docs-serve # local docs preview
See CONTRIBUTING.md for guidelines.
The trade-a-* analysis recipes require a local
trade-study checkout. After syncing
the environment, install its full extras (including adaptive optimisation,
surrogate fitting and sensitivity analysis):
# Default: trade-study is checked out alongside VBPCApy.
just trade-a-install-adaptive
# Override the checkout location, including paths containing spaces.
TRADE_STUDY_PATH="/path/to/trade study" just trade-a-install-adaptive
Citation
If you use this package in your research, please cite:
@software{vbpca_py2026,
author = {Macdonald, Joshua and Naim, Shany and Ram, Yoav},
title = {{VBPCApy}: Variational Bayesian PCA with Missing Data Support},
year = {2026},
url = {https://github.com/yoavram-lab/VBPCApy},
version = {0.4.6},
}
@article{ilin2010practical,
title={Practical Approaches to Principal Component Analysis in the Presence of Missing Values},
author={Ilin, Alexander and Raiko, Tapani},
journal={Journal of Machine Learning Research},
volume={11},
pages={1957--2000},
year={2010}
}
See CITATION.cff for machine-readable metadata.
License
MIT — see LICENSE.
Metadata
Release files for vbpca-py 0.4.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vbpca_py-0.4.6.tar.gz | 336.7 kB | Details |
Built distributions (wheels)
Total release size: 57.0 MB
Release files / vbpca_py-0.4.6.tar.gz
| Download URL | vbpca_py-0.4.6.tar.gz |
|---|---|
| Size | 336.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9f95c3489db7093d5cd5c86d33411e9b65a11fdf90171d74d033ae52d4e0e7a
|
|
BLAKE2b-256 checksum How to use checksums |
78b139585a065d4a7016512c6b1ffd95c254ac15818318c32f5d4c3d49be167a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp314-cp314-win_amd64.whl
| Download URL | vbpca_py-0.4.6-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7a3bd908c96b68b5a642756fdc73f818e51d6173d33716469d2dc0759cb6d11c
|
|
BLAKE2b-256 checksum How to use checksums |
6e7323110ae025623cb6686aaa75662ec80f55e9dca9d4c2d96c262139ffb879
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | vbpca_py-0.4.6-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 12.4 MB |
| Tags | CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
2fd44f1a77208685ec478a4d9f7f00a36d38d5149adab1494b0c047203f8b48c
|
|
BLAKE2b-256 checksum How to use checksums |
616213363003871f543483429be86340b284f8acfb6510826b82ff43610cbf90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | vbpca_py-0.4.6-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 831.7 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
afcd41344ebef7181835302ccb548e44ac7429bd1ebe73ab020456e5d4b9d6f7
|
|
BLAKE2b-256 checksum How to use checksums |
cf3229eb62e6a887bd2a26f811e642f7ec820fe668f154d7f093d6df91f42089
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp313-cp313-win_amd64.whl
| Download URL | vbpca_py-0.4.6-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 996.9 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2e9828e2b0334b39c690430b9c88039d47777461a71da1f3543ab2e302a5b982
|
|
BLAKE2b-256 checksum How to use checksums |
89f4cde8f152771d8099c6e60f390541bf92a153ac9183466048554c6a28623d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | vbpca_py-0.4.6-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 12.4 MB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
eff44d15176133d845be3c84d7e1bb566c66508294e9896fe12c5d79f54c7d25
|
|
BLAKE2b-256 checksum How to use checksums |
ec0f24600ebd2930412100a0b557b6a9d5de38d792ca1c9cbbbf36488468cab5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | vbpca_py-0.4.6-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 831.3 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ee4b7eb0f87cbd6706d7714c01b56afee8890c9d2aa27495afe6c54b7aaae570
|
|
BLAKE2b-256 checksum How to use checksums |
f32d165de63ab075f5f5ba8820bde07b699615524dbd40f8a0815d770ffe793e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp312-cp312-win_amd64.whl
| Download URL | vbpca_py-0.4.6-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 996.5 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
60ddc185c18c55758aa1fbf4dfefcf26f73314029d1bd78c9e7444c336081b3e
|
|
BLAKE2b-256 checksum How to use checksums |
5201a7e8e221225fab86a28cd3d0ea36cea1e9eb8f7e38ba3f77d576363b8c4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | vbpca_py-0.4.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 12.4 MB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
19e5e9ac58c77b94cee3059c17b13e24711ef0f55c25ec91741ea8d0696312ae
|
|
BLAKE2b-256 checksum How to use checksums |
390e5c5751f1d56edfceea18b1e1f0485403a84f214d5c0c2e954709a0daa544
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | vbpca_py-0.4.6-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 830.8 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dc336ce847316d2a4c247bd7d1223079041b87d9323b928b813be39751022f0a
|
|
BLAKE2b-256 checksum How to use checksums |
c4cc7185f166b8819f9bc36b7ee1382410e7c34d5606f2110faba50c4a0a8c2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp311-cp311-win_amd64.whl
| Download URL | vbpca_py-0.4.6-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 980.6 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
50366ab10ad33f10488646870f34889774273d693f01be2d2d301227917374b6
|
|
BLAKE2b-256 checksum How to use checksums |
45cb20087dbd38c02ccbef08cf76e4e8eff080fbbdeeaf7d7898d9f813b99b33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | vbpca_py-0.4.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 12.2 MB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
60dfc0e82bd899728df0be481e48d256411ae3ca76518afea3a17e8d4e4b8efd
|
|
BLAKE2b-256 checksum How to use checksums |
71057b6fe8345ecbb2cc1c4f520d2dc83adbd0255bb14bc757115bad4786f58f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency logRelease files / vbpca_py-0.4.6-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | vbpca_py-0.4.6-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 814.7 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5a0f4a813b33b2c166f3afcc1304bd12cd5307a9130f6d7d3b396ab9cdd74ea2
|
|
BLAKE2b-256 checksum How to use checksums |
330a22e98020b126148d83a46f9143c742af368d211621c376c787453b53f1e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.
Transparency log