Skip to main content

Probabilistic Principal Component Analysis (PPCA) model

PyPI version Crates.io version Docs.rs version

This project implements a PPCA model implemented in Rust for Python using pyO3 and maturin.

Installing

This package is available in PyPI!

pip install ppca-rs

And you can also use it natively in Rust:

cargo add ppca

Why use PPCA?

Glad you asked!

  • The PPCA is a simples extension of the PCA (principal component analysis), but can be overall more robust to train.
  • The PPCA is a proper statistical model. It doesn't spit out only the mean. You get standard deviations, covariances, and all the goodies that come from thre realm of probability and statistics.
  • The PPCA model can handle missing values. If there is data missing from your dataset, it can extrapolate it with reasonable values and even give you a confidence interval.
  • The training converges quickly and will always tend to a global maxima. No metaparameters to dabble with and no local maxima.

Why use ppca-rs?

That's an easy one!

  • It's written in Rust, with only a bit of Python glue on top. You can expect a performance in the same leage as of C code.
  • It uses rayon to paralellize computations evenly across as many CPUs as you have.
  • It also uses fancy Linear Algebra Trickery Technology to reduce computational complexity in key bottlenecks.
  • Battle-tested at Vio.com with some ridiculously huge datasets.

Quick example

import numpy as np
from ppca_rs import Dataset, PPCATrainer, PPCA

samples: np.ndarray

# Create your dataset from a rank 2 np.ndarray, where each line is a sample.
# Use non-finite values (`inf`s and `nan`) to signal masked values
dataset = Dataset(samples)

# Train the model (convenient edition!):
model: PPCAModel = PPCATrainer(dataset).train(state_size=10, n_iters=10)


# And now, here is a free sample of what you can do:

# Extrapolates the missing values with the most probable values:
extrapolated: Dataset = model.extrapolate(dataset)

# Smooths (removes noise from) samples and fills in missing values:
extrapolated: Dataset = model.filter_extrapolate(dataset)

# ... go back to numpy:
eextrapolated_np = extrapolated.numpy()

Juicy extras!

  • Tired of the linear? We have support for PPCA mixture models. Make the most of your data with clustering and dimensionality reduction in a single tool!
  • Support for adaptation of DataFrames using either pandas or polars. Never juggle those dfs in your code again.

Building from soure

Prerequisites

You will need Rust, which can be installed locally (i.e., without sudo) and you will also need maturin, which can be installed by

pip install maturin

pipenv is also a good idea if you are going to mess around with it locally. At least, you need a venv set, otherwise, maturin will complain with you.

Installing it locally

Check the Makefile for the available commands (or just type make). To install it locally, do

make install    # optional: i=python.version (e.g, `i=3.9`)

Messing around and testing

To mess around, inside a virtual environment (a Pipfile is provided for the pipenv lovers), do

maturin develop  # use the flag --release to unlock superspeed!

This will install the package locally as is from source.

How do I use this stuff?

See the examples in the examples folder. Also, all functions are type hinted and commented. If you are using pylance or mypy, it should be easy to navigate.

Is it faster than the pure Python implemetation you made?

You bet!

Metadata

Release files for ppca-rs 0.5.1

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

Source distribution (sdist)

Source distribution for ppca-rs 0.5.1
File Size Uploaded
ppca_rs-0.5.1.tar.gz 49.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for ppca-rs 0.5.1
File
ppca_rs-0.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
ppca_rs-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
ppca_rs-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
ppca_rs-0.5.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
ppca_rs-0.5.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details

Total release size: 3.2 MB

Release files / ppca_rs-0.5.1.tar.gz

Download URL ppca_rs-0.5.1.tar.gz
Size 49.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3157ed75400a4911749c24bd9547991c2722c61efc0ddd4480b2d2453f432d77
BLAKE2b-256 checksum
How to use checksums
e77127710bc6a8ac2915b650adb599859f3a11e5639b8c99ce0f16236153b71d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.16

Release files / ppca_rs-0.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ppca_rs-0.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 635.7 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
965cabb83b651a2a113bd1ae82fc8b519e88019b1fc43acd0dc160a4dd4a390d
BLAKE2b-256 checksum
How to use checksums
997601b81206dbe36f9a09df039bef72985067fe71749ddf90dd773c0786d129
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.16

Release files / ppca_rs-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ppca_rs-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 635.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
77c195c135761d06546a270495c7e9e27744639e27772ddbb6e5ef70204a34f8
BLAKE2b-256 checksum
How to use checksums
9119b2da9e7c78dbe803f52b676e2adf9b8ffb445926438ef0982d95da15b830
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.16

Release files / ppca_rs-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ppca_rs-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 635.9 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
cb37052ec9ec88d5df2c0e9d9a5e4988fd376fc291d32ac5c7ca6df91d032947
BLAKE2b-256 checksum
How to use checksums
25516940e30240938c8a6a1aa0d93734d389d48b2dc82eff9440aff00a52607c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.16

Release files / ppca_rs-0.5.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ppca_rs-0.5.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 636.6 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
86a622b5fe2fdcac4324ecd3cf133815dc95ee66acb6cd48d41016b65b26ee8a
BLAKE2b-256 checksum
How to use checksums
776e0c658ab5ad9291ecece7763634a013d41b3b9ffbf4c1cacdc5ea1e70b74d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.16

Release files / ppca_rs-0.5.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ppca_rs-0.5.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 636.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
101d85c9b3a7ff6f99280f9620db991b39a5ffa66760383ae89246aaf1fd88b7
BLAKE2b-256 checksum
How to use checksums
e9986d39c827a41a4b9f8a161afc4dc32d218cfa253fdfc1df6c3d5374fab2e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.14.16

Release history Release notifications | RSS feed

This release

0.5.1 This release

6 release files

0.4.1

10 release files

0.4.0

3 release files

0.3.2

9 release files

0.3.1

9 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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