Package: qrpca
QRPCAqrpca  works similarly to sklean.decomposition, but employs a QR-based PCA decomposition and supports CUDA acceleration via torch.How to installqrpcaTheqrpcacan be installed by the PyPI and pip:pip install qrpcaIf you download the repository, you can also install it in theqrpcadirectory:git clone https://github.com/xuquanfeng/qrpca
cd qrpca
python setup.py installYou can access it by clicking onGithub-qrpca.UsageHere is a demo for the use ofqrpca.The following are the results of retaining principal components containing 95% of the information content by principal component analysis.You can set the parametern_componentsto a value between 0 and 1 to execute the PCA on the corresponding proportion of the entire data, or set it to an integer number to reserve then_omponentscomponents.import torch
import numpy as np
from qrpca.decomposition import qrpca
from qrpca.decomposition import svdpca

# Generate the random data
demo_data = torch.rand(60000,2000)
n_com = 0.95

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# qrpca
pca = qrpca(n_component_ratio=n_com,device=device) # The percentage of information retained.
# pca = qrpca(n_component_ratio=10,device=device) # n principal components are reserved.
demo_qrpca = pca.fit_transform(demo_data)
print(demo_pca)

# SVDPCA
pca = svdpca(n_component_ratio=n_com,device=device)
demo_svdpca = pca.fit_transform(demo_data)
print(demo_svdpca)Comparision with sklearnThe methods and usage ofqrpcaare almost identical to those ofsklearn.decomposition.PCA. If you want to switch fromsklearntoqrpca, all you have to do is change the import and declare the device if you have a GPU, and that's it.And here's an illustration of how minimal the change is when differentPCAis used:qrpca.decomposition.qrpcafrom qrpca.decomposition import qrpca    
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
pca = qrpca(n_component_ratio=n_com,device=device)
demo_qrpca = pca.fit_transform(demo_data)qrpca.decomposition.svdpcafrom qrpca.decomposition import svdpca
pca = svdpca(n_component_ratio=n_com)
demo_svdpca = pca.fit_transform(demo_data)sklearn.decomposition.PCAfrom sklearn.decomposition import PCA
pca = PCA(n_components=n_com)
demo_pca = pca.fit_transform(demo_data)Performance benchmark sklearnWith the acceleration of GPU computation, the speed of both QR decomposition and singular value decomposition inqrpcais much higher than that insklearnWe run the different PCA methods on data with different numbers of rows and columns, and then we compare their PCA degradation times and plotted the distribution of the times. Here are the two plots.Comparison of PCA degradation time with different number of rows and different methods for the case of 1000 columns.Comparison of PCA reduction time with different number of columns and different methods for the case of 30000 rows.We can see from the above two facts thatqrpcamay considerably cut program run time by using GPU acceleration, while also having a very cheap migration cost and a guaranteed impact.Requirementsnumpy>=1.21.1pandas>=1.3.5torch>=1.8.1torchvision>=0.8.0cudatoolkit>=0.7.1scikit-learn>=1.0.2Copyright & License2022 Xu Quanfeng (xuquanfeng@shao.ac.cn) & Rafael S. de Souza (drsouza@shao.ac.cn) & Shen Shiyin (ssy@shao.ac.cn) & Peng Chen (pengchzn@gmail.com)This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.ReferencesSharma, Alok and Paliwal, Kuldip K. and Imoto, Seiya and Miyano, Satoru 2013, International Journal of Machine Learning and Cybernetics, 4, 6, doi:10.1007/s13042-012-0131-7.CitingqrpcaIf you want to citeqrpca, please use the following citations.Software Citation: Xu Quanfeng, & Rafael S. de Souza. (2022). PCA algorithm of QR accelerated SVD decomposition (1.5). Zenodo.https://doi.org/10.5281/zenodo.6555926