Supervised Quadratic Feature Analysis: Task specific second order feature extraction
Project description
SQFA
Supervised Quadratic Feature Analysis (SQFA) is a supervised dimensionality
reduction technique. It learns a set of linear features that
maximize the differences in first- and second-order statistics between
classes, in a way that supports quadratic classifiers (e.g. QDA).
The sqfa package implements SQFA.
For detailed information on the method and the package, see the sqfa package tutorials and the SQFA preprint, "Supervised Quadratic Feature Analysis: An Information Geometry Approach to Dimensionality Reduction".
Overview
The package provides the class SQFA that can be used to train the
model. The class has an API similar to sklearn.
An example of how to use the SQFA class is shown below:
import sqfa
import torchvision
### DOWNLOAD DATASET
trainset = torchvision.datasets.MNIST(
root="./data", train=True, download=True
)
X = trainset.data.reshape(-1, 28 * 28).float()
y = trainset.targets
# Scale X
X = X / (X.std() * 28.0)
X = X - X.mean(dim=0, keepdim=True)
### INITIALIZE SQFA MODEL
model = sqfa.model.SQFA(
n_dim=X.shape[-1],
n_filters=4,
feature_noise=0.01,
)
### FIT MODEL. TWO OPTIONS:
# 1) Give data and labels as input
model.fit_pca(X) # Optional: PCA initialization to speed up convergence
model.fit(X=X, y=y)
# 2) Give dictionary with data statistics as input
data_stats = sqfa.statistics.class_statistics(X, y)
model.fit_pca(data_statistics=data_stats) # Optional: PCA initialization to speed up convergence
model.fit(data_statistics=data_stats)
### TRANSFORM DATA AND SECOND MOMENTS TO THE LEARNED FEATURE SPACE
X_transformed = model.transform(X).detach()
second_moments_transformed = model.transform_scatters(
data_stats["second_moments"],
).detach()
Installation
Virtual environment
We recommend installing the package in a virtual environment. For this,
you can first install miniconda
(install instructions link),
and then create a virtual environment with Python 3.11 using the following
shell command:
conda create -n my-sqfa python=3.11
You can then activate the virtual environment with the following command:
conda activate my-sqfa
You should activate the my-sqfa environment to install the package, and every
time you want to use it.
Install package from PyPI
The easiest way to install the package is form the PyPI repository. To install the package and the dependencies needed to run the tutorials, use the following command:
pip install sqfa[dev]
To install the lighter version without the tutorials dependencies, use
pip install sqfa
Install package from source
To install the package from source (e.g., if you want to modify the code), you can clone the repository and install the package in editable mode with the following commands:
git clone https://github.com/dherrera1911/sqfa.git
cd sqfa
pip install -e .[dev]
Citation
Please cite the SQFA preprint if you use the package:
@misc{herreraesposito2025supervisedquadraticfeatureanalysis,
title={Supervised Quadratic Feature Analysis: An Information Geometry Approach to Dimensionality Reduction},
author={Daniel Herrera-Esposito and Johannes Burge},
year={2025},
eprint={2502.00168},
archivePrefix={arXiv},
primaryClass={stat.ML},
url={https://arxiv.org/abs/2502.00168},
}
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 sqfa-0.2.0.tar.gz.
File metadata
- Download URL: sqfa-0.2.0.tar.gz
- Upload date:
- Size: 115.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be06c7f02b056235538e337ffc4744c3a4f93dbb53d60e1ebfb8206cd27f5934
|
|
| MD5 |
2cb169e55752bd7f16043e95512f451d
|
|
| BLAKE2b-256 |
3a998a258dd19e35691fb180b0b8fcbdba7ef14c42613dc36437e3666911fc9f
|
Provenance
The following attestation bundles were made for sqfa-0.2.0.tar.gz:
Publisher:
publish-to-pypi.yml on dherrera1911/sqfa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqfa-0.2.0.tar.gz -
Subject digest:
be06c7f02b056235538e337ffc4744c3a4f93dbb53d60e1ebfb8206cd27f5934 - Sigstore transparency entry: 169141114
- Sigstore integration time:
-
Permalink:
dherrera1911/sqfa@05297fbdb26da7425b9862c0838be93f7d9d08b7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dherrera1911
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@05297fbdb26da7425b9862c0838be93f7d9d08b7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sqfa-0.2.0-py3-none-any.whl.
File metadata
- Download URL: sqfa-0.2.0-py3-none-any.whl
- Upload date:
- Size: 20.4 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 |
179778ecad538a543e09b7a692c23ca6f1ed8613ee47ec5fa13f6d7543154f21
|
|
| MD5 |
56ed08dc629f9496445cd24d0a52a71c
|
|
| BLAKE2b-256 |
7a3a9810c42d34a92356ada25d2afa0bcabc0035abcfa29823ca27b85a09f807
|
Provenance
The following attestation bundles were made for sqfa-0.2.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on dherrera1911/sqfa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqfa-0.2.0-py3-none-any.whl -
Subject digest:
179778ecad538a543e09b7a692c23ca6f1ed8613ee47ec5fa13f6d7543154f21 - Sigstore transparency entry: 169141118
- Sigstore integration time:
-
Permalink:
dherrera1911/sqfa@05297fbdb26da7425b9862c0838be93f7d9d08b7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dherrera1911
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@05297fbdb26da7425b9862c0838be93f7d9d08b7 -
Trigger Event:
release
-
Statement type: