Skip to main content

sbmf

Sparse and semi-binary matrix factorization: binary autoencoder / binary matrix factorization models, their numba-compiled Gibbs E-steps and latent priors, and the simulation and cross-validation utilities.

Module Contents
bae_models SemiBMF, JBMF, BiPCA, SCPD, RRBMF, KernelBMF
bae_weights decoders: affine, Procrustes, CP, reduced-rank, torch
bae_priors LatentPrior, BoltzmannPrior, MRFPrior, temperature schedules
bae_search numba E-step kernels
bae_util cross-validation (impcv, bicv, gabriel_bicv, ...), annealing
df_util latent-structure simulators (UndirectedModel, noisyembed), cut decompositions, permham
util, numba_util internal helpers

Use it from another project

uv add --editable ../concepts                 # local clone; edits show up immediately
uv add git+https://github.com/Kelarion/concepts --branch sbmf-0.1   # or straight from GitHub
pip install -e ../concepts                    # without uv
from sbmf.bae_models import BiPCA, SemiBMF
from sbmf.bae_util import impcv
from sbmf import df_util

Optional extras: sbmf[plot] (matplotlib, for df_util.plotgraph / plotwalk), sbmf[graph] (pydot, for graphviz layouts), sbmf[polytope] (pypoman, for df_util.enumerate_cuts), or sbmf[all].

E-step sampler

Every dense model's E-step is a Gibbs sweep that keeps each row's active latents in a list, so neighbour sums (likelihood field, Boltzmann coupling, tree penalty) cost O(active) rather than O(latents) per site. The tree penalty (tree_reg, off by default) reads the co-occurrence counts StS once per batch of tree_batch rows (default 20) instead of after every flip; tree_batch=0 gives the exact sampler, which draws the same samples as 0.1.0 for a given seed.

model = SemiBMF(50, tree_reg=1.0)                 # batched tree penalty
model = SemiBMF(50, tree_reg=1.0, tree_batch=0)   # exact

Batches of 10-50 rows gave the same recovery, held-out error and stability as the exact sampler in simulations and on real data. Much larger batches can make the sampler oscillate (stale counts switch many latents on at once), so keep it well below the number of rows. Table rebuilds cost O(latents^2) each, so with many rows and latents a larger batch is faster.

tree_reg defaults to 0 because it was not found to help: in simulations with tree- and grid-structured latents, a Boltzmann prior without it recovered the latents as well or better, and tree_reg = 1 made recovery worse. It remains the most expensive part of the E-step when switched on.

Develop

uv sync
uv run pytest
uv run ruff check src tests
uv build

Changes from 0.0.14

0.0.14 shipped only the Cython extension sbmf.sparse (BiMat, GaussianSampler, KernelSampler). 0.1.0 replaces it with the pure-Python + numba package above, so no compiler is needed; the Cython code is in the git history. util.py keeps only the 20 helpers the package uses (of 131).

Not included: mrf_samplers.py and old_bae_search.py. Without them MRFPrior (J_prior='mrf') and ConvOperator raise an error naming the missing file; copy the file into src/sbmf/ (changing import util to from . import util) to enable them.

Known issues (not fixed, they change results)

  • bae_util.impcv, fpcv and multifit do not reset the model between folds or chains, so later folds start from weights trained on held-out entries. bicv and loocv do reset (model.initialized = False).
  • Multi-chain fits are not reproducible from a seed: inside prange each thread has its own numba RNG, and seeding reaches only the calling thread.
  • Procrustes.init_params hot-starts from the uncentered data.
  • numba_util.log_ndtr has a 0.037 jump at x = -5.
  • Unfinished drafts: bae_util.kercv (raises NotImplementedError), df_util.reassign with pi given, ConvOperator / ConvBMF.

Metadata

Release files for sbmf 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sbmf 0.1.0
File Size Uploaded Provenance Actions
sbmf-0.1.0.tar.gz 240.6 kB Without provenance Details for sbmf-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sbmf 0.1.0
File Interpreter ABI Platform Actions
sbmf-0.1.0-py3-none-any.whl Python 3 none any Details for sbmf-0.1.0-py3-none-any.whl

Total release size: 334.3 kB

Release files / sbmf-0.1.0.tar.gz

Download URL sbmf-0.1.0.tar.gz
Size 240.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bb8a9d6ca5a569bcf51c638de0f27a738aa5971357562e198ef5ef6dbfc3c5d2
BLAKE2b-256 checksum
How to use checksums
34beb1da6cd1a9c2f407039698aadc10afdacf5d66adfe5c5c9658e3fab55c1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / sbmf-0.1.0-py3-none-any.whl

Download URL sbmf-0.1.0-py3-none-any.whl
Size 93.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98aaa1bdf86191f9ef629529446c4a7764e0b16ed38324f894afa5fcea442fcc
BLAKE2b-256 checksum
How to use checksums
39a25518bf011aa70c91f9aaf7db82c1b137dd08e4d640dc6f72efe7324243b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for sbmf 0.1.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page