Skip to main content

Measures of projection quality

Project description

test codecov github Python version license: GPL v3

API documentation Downloads

sortedness

sortedness is a measure of quality of data transformation, often dimensionality reduction. It is less sensitive to irrelevant distortions and return values in a more meaningful interval than Kruskal stress formula I.
This Python library / code provides a reference implementation for the stress function presented here (link broken until the paper is published).

Overview

Python installation

from package through pip

# Set up a virtualenv. 
python3 -m venv venv
source venv/bin/activate

# Install from PyPI
pip install -U sortedness

from source

git clone https://github.com/sortedness/sortedness
cd sortedness
poetry install

Examples

Sortedness

import numpy as np
from numpy.random import permutation
from sklearn.decomposition import PCA

from sortedness.local import sortedness

mean = (1, 2)
cov = np.eye(2)
rng = np.random.default_rng(seed=0)
original = rng.multivariate_normal(mean, cov, size=12)
projected2 = PCA(n_components=2).fit_transform(original)
projected1 = PCA(n_components=1).fit_transform(original)
np.random.seed(0)
projectedrnd = permutation(original)

s = sortedness(original, original)
print(min(s), max(s), s)
"""
1.0 1.0 [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
"""
s = sortedness(original, projected2)
print(min(s), max(s), s)
"""
1.0 1.0 [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
"""
s = sortedness(original, projected1)
print(min(s), max(s), s)
"""
0.432937128932 0.944810120534 [0.43293713 0.53333015 0.88412753 0.94481012 0.81485109 0.81330052
 0.76691474 0.91169619 0.88998817 0.90102615 0.61372341 0.86996213]
"""
s = sortedness(original, projectedrnd)

Pairwise sortedness

import numpy as np
from numpy.random import permutation
from sklearn.decomposition import PCA

from sortedness.local import pwsortedness

mean = (1, 2)
cov = np.eye(2)
rng = np.random.default_rng(seed=0)
original = rng.multivariate_normal(mean, cov, size=12)
projected2 = PCA(n_components=2).fit_transform(original)
projected1 = PCA(n_components=1).fit_transform(original)
np.random.seed(0)
projectedrnd = permutation(original)

s = pwsortedness(original, original)
print(min(s), max(s), s)
"""
1.0 1.0 [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
"""
s = pwsortedness(original, projected2)
print(min(s), max(s), s)
"""
1.0 1.0 [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
"""
s = pwsortedness(original, projected1)
print(min(s), max(s), s)
"""
0.730078995423 0.837310352695 [0.75892647 0.730079   0.83496865 0.73161226 0.75376525 0.83301104
 0.76695755 0.74759156 0.81434161 0.74067221 0.74425225 0.83731035]
"""
s = pwsortedness(original, projectedrnd)
print(min(s), max(s), s)

"""
-0.198780473657 0.147224384381 [-0.19878047 -0.14125391  0.03276727 -0.092844   -0.0866695   0.14722438
 -0.07603536 -0.08916877 -0.1373848  -0.10933483 -0.07774488  0.05404383]
"""

** Copyright (c) 2022. Davi Pereira dos Santos and Tacito Neves**

Grants

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

sortedness-0.230501.8.tar.gz (633.4 kB view hashes)

Uploaded Source

Built Distribution

sortedness-0.230501.8-cp310-cp310-manylinux_2_35_x86_64.whl (644.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

Supported by

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