Skip to main content

A package with fast, TensorFlow-based implementations of projection (i.e., dimensionality reduction) quality metrics.

Project description

Accelerated Projection Quality Metrics

When evaluating Dimensionality Reduction (AKA Projection) techniques, a number of quality metrics are usually employed.

These quality metrics are numeric ways of evaluating a projection, and might be useful to determine whether a sane projection has been produced by an algorithm (e.g, t-SNE, or UMAP).

In this repository, I aim to provide a comprehensive set of implementations of projection quality metrics that are fast and use idiomatic TensorFlow in their implementation.

Quality Metrics

A quality metric is a function $\mathcal{M}_\eta$ with two arguments: a dataset $\mathbf{X} \in \mathbb{R}^{n\times D}$ of $D$-dimensional data points, and a corresponding projection $\mathbf{Y} = \mathcal{P}(\mathbb{X}) \in \mathbb{R}^{n\times d}$ where $d$ is usually 2 or 3.

Projection algorithms can generate $\mathbf{Y}$ in many ways. Of course, not all such projections are equally useful and/or truthful to the data they are based on. While some techniques might be better at representing global aspects of the original dataset $\mathbf{X}$, others might instead favor local neighborhood preservation.

Each $\mathcal{M}_\eta(\mathbf{X}, \mathbf{Y})$ returns a single score representing the quality of $\mathbf{Y}$ as a projection for $\mathbb{X}$. Different quality metrics aim to evaluate different aspects of data pattern preservation. For example, Trustworthiness is a metric that aims to evaluate the amount of false neighbors introduced in a projection -- that is to say, points that were not close in $D$-dimensional space and have been wrongfully brought together by $\mathcal{P}$. Stress is another metric, aimed at measuring discrepancies in pairwise distances in $\mathbf{X}$ when compared to pairwise distances in $\mathbf{Y}$.

Installation

Installation is possible using pip directly:

pip install tensorflow-projection-qm

Using

The functions that calculate the quality metrics all sit in the tensorflow_projection_qm.metrics package.

from tensorflow_projection_qm.metrics import continuity, trustworthiness

# Set up some fake data
import numpy as np
X = np.random.randn(100, 5)  # 100 data points with 5 dimensions.

# Project to 2-D with TSNE
from sklearn.manifold import TSNE
X_proj = TSNE(n_components=2).fit_transform(X).astype(X.dtype)

# Evaluate the projection:
C = continuity(X, X_proj, k=21).numpy()
T = trustworthiness(X, X_proj, k=21).numpy()
print(f"Continuity: {C}")
print(f"Trustworthiness: {T}")

Why this package?

I have a recurring need in my research (see About Me below) to evaluate different projection algorithms with respect to different quality metrics. While there are some libraries for this, and I am grateful for their authors' work in gathering and implementing different quality metrics (see, for example, ZADU), I have found some implementations to not be as performant as I need them to be (keep in mind I evaluate thousands of projections at a time), and sometimes buggy.

At some point I noticed I had been re-implementing the same quality metrics over and over again, sometimes introducing bugs myself due to mistakes when copying and adapting code from a public source, such as Espadoto's comprehensive survey.

Instead, I have chosen to start this package with the goals of:

  1. Having easy access to standard implementations of projection quality metrics;
  2. Implementing quality metrics in vectorized manners as often as possible, taking advantage of parallel execution for speeding up calculations;
  3. Sharing this code openly as my first package to be published on PyPi.org;
  4. Using an easily-available framework (TensorFlow) to back up my implementations and seamlessly take advantage of GPUs when available.

About

This package is under active development, and is very much in its early stages. Please feel free to report bugs, but also be mindful that this is a best-effort attempt to generalize/speed up my own implementations of quality metrics.

About Me

My name is Alister Machado, I am a PhD Candidate researching Data Visualization (more specifically focused in dimensionality reduction and explainable AI). I am the person behind ShaRP and the Differentiable DBMs. You can check out my research here. I am currently in the 4th year of my PhD (out of 5 total), and am expected to graduate in 2026. Feel free to reach out!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tensorflow_projection_qm-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tensorflow_projection_qm-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file tensorflow_projection_qm-0.1.0.tar.gz.

File metadata

  • Download URL: tensorflow_projection_qm-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.5 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for tensorflow_projection_qm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bf4c7ded6d2443243b3aa17432d749c7fa6352c2b5325e7a8c94efa793555f8c
MD5 adb778e952f839280074e8352a8edcd7
BLAKE2b-256 4701c60c824d4ac60a9b84d2a68578056adfbeb2a36311c7f9dd927cb2bff5ad

See more details on using hashes here.

File details

Details for the file tensorflow_projection_qm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tensorflow_projection_qm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.5 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for tensorflow_projection_qm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4853c2e0a8e7c6d598ad120b3c9a1b403db57c570ff4b5449a101a4943f20e6d
MD5 e7dae457cf40fc69af163cf3cc926d7a
BLAKE2b-256 6d56e46ad5e91e3099116414f998e32c995ed79fdde30c9d602df3a0c9a6951d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page