Package: ppca-rs
ProbabilisticPrincipal Component Analysis (PPCA) modelThis project implements a PPCA model implemented in Rust for Python usingpyO3andmaturin.InstallingThis package is available in PyPI!pipinstallppca-rsAnd you can also use it natively in Rust:cargoaddppcaWhy 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 aproper 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 handlemissing 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 useppca-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 usesrayonto 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 exampleimportnumpyasnpfromppca_rsimportDataset,PPCATrainer,PPCAsamples: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 valuesdataset=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 eitherpandasorpolars. Never juggle thosedfs in your code again.Building from sourePrerequisitesYou will needRust, which can be installed locally (i.e., withoutsudo) and you will also needmaturin, which can be installed bypipinstallmaturinpipenvis also a good idea if you are going to mess around with it locally. At least, you need avenvset, otherwise,maturinwill complain with you.Installing it locallyCheck theMakefilefor the available commands (or just typemake). To install it locally, domakeinstall# optional: i=python.version (e.g, `i=3.9`)Messing around and testingTo mess around,inside a virtual environment(aPipfileis provided for thepipenvlovers), domaturindevelop# use the flag --release to unlock superspeed!This will install the package locallyas isfrom source.How do I use this stuff?See the examples in theexamplesfolder. Also, all functions are type hinted and commented. If you are usingpylanceormypy, it should be easy to navigate.Is it faster than the pure Python implemetation you made?You bet!