Skip to main content

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

Project description

Python package

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. We represent by $\eta$ the hyperparameters associated with $\mathcal{M}$ -- for instance, the size $k$ of the neighborhood in neighborhood-based metrics such as trustworthiness, continuity, and neighborhood hit.

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.continuity(X, X_proj, k=21).numpy()
T = trustworthiness.trustworthiness(X, X_proj, k=21).numpy()
print(f"Continuity: {C}")
print(f"Trustworthiness: {T}")

# Compute per-point value of a metric (not all metrics support this)
C_i = continuity.continuity_with_local(X, X_proj, k=21)[1].numpy()
T_i = trustworthiness.trustworthiness_with_local(X, X_proj, k=21)[1].numpy()

print(f"Per-point Continuity: {C_i}")
print(f"Per-point Trustworthiness: {T_i})

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.1.tar.gz (100.1 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.1-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tensorflow_projection_qm-0.1.1.tar.gz
  • Upload date:
  • Size: 100.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for tensorflow_projection_qm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7d9f660e30bf9e3124a98d96730131a50ff590673c00644e644c821e579bb4d4
MD5 886a8a9b701bf79653673393b8285aee
BLAKE2b-256 5f9ba4748f52ac05d91e542d8c90c92b1d818af252ff39f8f8b47562faf0cdbf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorflow_projection_qm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05e8b74bb4353e4b08b81f793d90e2d90d03476b9cc90a0fabbdf66ef6fbad25
MD5 eed9f10e12719de01eae28cf88ada6e5
BLAKE2b-256 b381b6f84c53b51128d7e0762a2667bfee8689e7e3935e7ce9a1194c31a727d2

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