Fast computation of possibly centered/scaled training set kernel matrices in a cross-validation setting.
Project description
CVMatrix
The cvmatrix package implements the fast cross-validation algorithms by Engstrøm [1] for computation of training set $\mathbf{X}^{\mathbf{T}}\mathbf{X}$ and $\mathbf{X}^{\mathbf{T}}\mathbf{Y}$ in a cross-validation setting. In addition to correctly handling arbitrary row-wise pre-processing, the algorithms allow for and efficiently and correctly handle any combination of column-wise centering and scaling of X and Y based on training set statistical moments.
For an implementation of the fast cross-validation algorithms combined with Improved Kernel Partial Least Squares [2], see the Python package ikpls.
Installation
-
Install the package for Python3 using the following command:
pip3 install cvmatrix
-
Now you can import the class implementing all the algorithms with:
from cvmatrix.cvmatrix import CVMatrix
Quick Start
Use the cvmatrix package for fast computation of training set kernel matrices
import numpy as np from cvmatrix.cvmatrix import CVMatrix N = 100 # Number of samples. K = 50 # Number of features. M = 10 # Number of targets. X = np.random.uniform(size=(N, K)) # Random X data Y = np.random.uniform(size=(N, M)) # Random Y data folds = np.arange(100) % 5 # 5-fold cross-validation # Instantiate CVMatrix cvm = CVMatrix( folds=folds, center_X=True, center_Y=True, scale_X=True, scale_Y=True, ) # Fit on X and Y cvm.fit(X=X, Y=Y) # Compute training set XTX and/or XTY for each fold for fold in cvm.folds_dict.keys(): # Get both XTX and XTY training_XTX, training_XTY = cvm.training_XTX_XTY(fold) # Get only XTX training_XTX = cvm.training_XTX(fold) # Get only XTY training_XTY = cvm.training_XTY(fold)
Examples
In examples, you will find:
Benchmarks
In benchmarks, we have benchmarked cross-validation of the fast algorithms in cvmatrix against the baseline algorithms implemented in NaiveCVMatrix.
Left: Benchmarking cross-validation with the CVMatrix implementation versus the baseline implementation using three common combinations of (column-wise) centering and scaling. Right: Benchmarking cross-validation with the CVMatrix implementation for all possible combinations of (column-wise) centering and scaling. Here, most of the graphs lie on top of eachother. In general, no preprocessing is faster than centering which, in turn, is faster than scaling.
Contribute
To contribute, please read the Contribution Guidelines.
References
- Engstrøm, O.-C. G. (2024). Shortcutting Cross-Validation: Efficiently Deriving Column-Wise Centered and Scaled Training Set $\mathbf{X}^\mathbf{T}\mathbf{X}$ and $\mathbf{X}^\mathbf{T}\mathbf{Y}$ Without Full Recomputation of Matrix Products or Statistical Moments
- Dayal, B. S., & MacGregor, J. F. (1997). Improved PLS algorithms. Journal of Chemometrics, 11(1), 73-85.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cvmatrix-1.1.0.tar.gz.
File metadata
- Download URL: cvmatrix-1.1.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
045a62b8ba6438019b59634548746807dd80c8c30a270de63f258798a603d7d6
|
|
| MD5 |
9be86e090a807fd44a139e26ef99d665
|
|
| BLAKE2b-256 |
493a690be84520cf0658b5e22fd58261334db9c71b591a4904f7fdeff37f585e
|
Provenance
The following attestation bundles were made for cvmatrix-1.1.0.tar.gz:
Publisher:
package_workflow.yml on sm00thix/cvmatrix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cvmatrix-1.1.0.tar.gz -
Subject digest:
045a62b8ba6438019b59634548746807dd80c8c30a270de63f258798a603d7d6 - Sigstore transparency entry: 170577730
- Sigstore integration time:
-
Permalink:
sm00thix/cvmatrix@e027330e02cc7a1d68530c72a4b08c84a71366c2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sm00thix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package_workflow.yml@e027330e02cc7a1d68530c72a4b08c84a71366c2 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file cvmatrix-1.1.0-py3-none-any.whl.
File metadata
- Download URL: cvmatrix-1.1.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a90ccc3251a86a1c0e7418d74bbc3563ead8bdf67f00b5834eaca6db076d61f
|
|
| MD5 |
e875c22257fac83c720225be21419f98
|
|
| BLAKE2b-256 |
3b50a05b0b8af96bdca72c5818495deeb65199fae70d6947d70376e6c64d02d3
|
Provenance
The following attestation bundles were made for cvmatrix-1.1.0-py3-none-any.whl:
Publisher:
package_workflow.yml on sm00thix/cvmatrix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cvmatrix-1.1.0-py3-none-any.whl -
Subject digest:
2a90ccc3251a86a1c0e7418d74bbc3563ead8bdf67f00b5834eaca6db076d61f - Sigstore transparency entry: 170577732
- Sigstore integration time:
-
Permalink:
sm00thix/cvmatrix@e027330e02cc7a1d68530c72a4b08c84a71366c2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sm00thix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package_workflow.yml@e027330e02cc7a1d68530c72a4b08c84a71366c2 -
Trigger Event:
workflow_run
-
Statement type: