# SQFA
[![Build Status](https://github.com/dherrera1911/sqfa/actions/workflows/install.yml/badge.svg)](https://github.com/dherrera1911/sqfa/actions/workflows/install.yml)
[![Tests Status](https://github.com/dherrera1911/sqfa/actions/workflows/tests.yml/badge.svg)](https://github.com/dherrera1911/sqfa/actions/workflows/tests.yml)
[![Documentation Status](https://readthedocs.org/projects/sqfa/badge/?version=latest)](https://sqfa.readthedocs.io/en/latest/?badge=latest)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/dherrera1911/sqfa?tab=MIT-1-ov-file)
![Python version](https://img.shields.io/badge/python-3.9|3.10|3.11|3.12-blue.svg)
[![codecov](https://codecov.io/gh/dherrera1911/sqfa/graph/badge.svg?token=NN44R5G18I)](https://codecov.io/gh/dherrera1911/sqfa)
[![PyPI version](https://badge.fury.io/py/sqfa.svg)](https://badge.fury.io/py/sqfa)
Supervised Quadratic Feature Analysis (SQFA) is a supervised dimensionality
reduction technique. It learns a set of linear features that
maximize the differences in second-order statistics between
classes. The `sqfa` package implements SQFA.
For detailed information on the method and the package, see the
[sqfa package tutorials](https://sqfa.readthedocs.io/en/latest/tutorials/spd_geometry.html).
## 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:
```python
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
# Normalize 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(X=x, y=y)
# 2) Give scatter matrices as input
data_stats = sqfa.statistics.class_statistics(x, y)
model.fit(data_scatters=data_stats["second_moments"])
### Transform data to the learned feature space
x_transformed = model.transform(x).detach()
```
## Installation
### Virtual environment
We recommend installing the package in a virtual environment. For this,
you can first install `miniconda`
([install instructions link](https://docs.anaconda.com/miniconda/install/#quick-command-line-install)),
and then create a virtual environment with Python 3.11 using the following
shell command:
```bash
conda create -n my-sqfa python=3.11
```
You can then activate the virtual environment with the following command:
```bash
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:
```bash
pip install sqfa[dev]
```
To install the lighter version without the tutorials dependencies, use
```bash
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:
```bash
git clone git@github.com:dherrera1911/sqfa.git
cd sqfa
pip install -e .[dev]
```
Raw data
{
"_id": null,
"home_page": null,
"name": "sqfa",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "covariance matrices, dimensionality reduction, information geometry, machine learning, manifold, pytorch, second moments",
"author": null,
"author_email": "Daniel Herrera-Esposito <dherrera1911@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/97/72/6e967f47efbda3755df855536d12bd95e62e69a55fdc8c7682b8a89d6dff/sqfa-0.1.1.tar.gz",
"platform": null,
"description": "# SQFA\n\n[![Build Status](https://github.com/dherrera1911/sqfa/actions/workflows/install.yml/badge.svg)](https://github.com/dherrera1911/sqfa/actions/workflows/install.yml)\n[![Tests Status](https://github.com/dherrera1911/sqfa/actions/workflows/tests.yml/badge.svg)](https://github.com/dherrera1911/sqfa/actions/workflows/tests.yml)\n[![Documentation Status](https://readthedocs.org/projects/sqfa/badge/?version=latest)](https://sqfa.readthedocs.io/en/latest/?badge=latest)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/dherrera1911/sqfa?tab=MIT-1-ov-file)\n![Python version](https://img.shields.io/badge/python-3.9|3.10|3.11|3.12-blue.svg)\n[![codecov](https://codecov.io/gh/dherrera1911/sqfa/graph/badge.svg?token=NN44R5G18I)](https://codecov.io/gh/dherrera1911/sqfa)\n[![PyPI version](https://badge.fury.io/py/sqfa.svg)](https://badge.fury.io/py/sqfa)\n\n\nSupervised Quadratic Feature Analysis (SQFA) is a supervised dimensionality\nreduction technique. It learns a set of linear features that\nmaximize the differences in second-order statistics between\nclasses. The `sqfa` package implements SQFA.\n\nFor detailed information on the method and the package, see the\n[sqfa package tutorials](https://sqfa.readthedocs.io/en/latest/tutorials/spd_geometry.html).\n\n## Overview\n\nThe package provides the class `SQFA` that can be used to train the\nmodel. The class has an API similar to `sklearn`.\nAn example of how to use the `SQFA` class is shown below:\n\n```python\nimport sqfa\nimport torchvision\n\n### Download dataset\n\ntrainset = torchvision.datasets.MNIST(\n root=\"./data\", train=True, download=True\n)\nx = trainset.data.reshape(-1, 28 * 28).float()\ny = trainset.targets\n# Normalize x\nx = x / (x.std() * 28.0)\nx = x - x.mean(dim=0, keepdim=True)\n\n### Initialize SQFA model\n\nmodel = sqfa.model.SQFA(\n n_dim=x.shape[-1],\n n_filters=4,\n feature_noise=0.01,\n)\n\n### Fit model. Two options:\n\n# 1) Give data and labels as input\nmodel.fit(X=x, y=y)\n\n# 2) Give scatter matrices as input\ndata_stats = sqfa.statistics.class_statistics(x, y)\nmodel.fit(data_scatters=data_stats[\"second_moments\"])\n\n### Transform data to the learned feature space\n\nx_transformed = model.transform(x).detach()\n```\n\n## Installation\n\n### Virtual environment\n\nWe recommend installing the package in a virtual environment. For this,\nyou can first install `miniconda` \n([install instructions link](https://docs.anaconda.com/miniconda/install/#quick-command-line-install)),\nand then create a virtual environment with Python 3.11 using the following\nshell command:\n\n```bash\nconda create -n my-sqfa python=3.11\n```\n\nYou can then activate the virtual environment with the following command:\n\n```bash\nconda activate my-sqfa\n```\n\nYou should activate the `my-sqfa` environment to install the package, and every\ntime you want to use it.\n\n### Install package from PyPI\n\nThe easiest way to install the package is form the PyPI\nrepository. To install the package and the dependencies\nneeded to run the tutorials, use the following command:\n\n```bash\npip install sqfa[dev]\n```\n\nTo install the lighter version without the tutorials dependencies, use\n\n```bash\npip install sqfa\n```\n\n### Install package from source\n\nTo install the package from source (e.g., if you want to modify the\ncode), you can clone the repository and install the package\nin editable mode with the following commands:\n\n```bash\ngit clone git@github.com:dherrera1911/sqfa.git\ncd sqfa\npip install -e .[dev]\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Supervised Quadratic Feature Analysis: Task specific second order feature extraction",
"version": "0.1.1",
"project_urls": {
"Bug Reports": "https://github.com/dherrera1911/sqfa/issues",
"Documentation": "https://sqfa.readthedocs.io/en/latest/",
"Repository": "https://github.com/dherrera1911/sqfa",
"Source": "https://github.com/dherrera1911/sqfa"
},
"split_keywords": [
"covariance matrices",
" dimensionality reduction",
" information geometry",
" machine learning",
" manifold",
" pytorch",
" second moments"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a3d653bf0e4f7b7a281e972814fc5ee6d930fc3664a91a6b6f640e30a10d02ae",
"md5": "5182838fd648928430812083891c4fcc",
"sha256": "305c218ed99b6560a23f07dd8ab2435880a0fc25581f0f0310d45e6e27313175"
},
"downloads": -1,
"filename": "sqfa-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5182838fd648928430812083891c4fcc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 17897,
"upload_time": "2024-12-17T13:26:25",
"upload_time_iso_8601": "2024-12-17T13:26:25.910076Z",
"url": "https://files.pythonhosted.org/packages/a3/d6/53bf0e4f7b7a281e972814fc5ee6d930fc3664a91a6b6f640e30a10d02ae/sqfa-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "97726e967f47efbda3755df855536d12bd95e62e69a55fdc8c7682b8a89d6dff",
"md5": "d35c160ed1bb78f0537e8fecace45b9a",
"sha256": "8e466a258cad5439b0ff128910ab430c3a02792236a1e4dbf8734aad6ab01e55"
},
"downloads": -1,
"filename": "sqfa-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "d35c160ed1bb78f0537e8fecace45b9a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 69594,
"upload_time": "2024-12-17T13:26:27",
"upload_time_iso_8601": "2024-12-17T13:26:27.895723Z",
"url": "https://files.pythonhosted.org/packages/97/72/6e967f47efbda3755df855536d12bd95e62e69a55fdc8c7682b8a89d6dff/sqfa-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-17 13:26:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dherrera1911",
"github_project": "sqfa",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sqfa"
}