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 details)

Uploaded Source

Built Distribution

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

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

File details

Details for the file sortedness-0.230501.8.tar.gz.

File metadata

  • Download URL: sortedness-0.230501.8.tar.gz
  • Upload date:
  • Size: 633.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-58-generic

File hashes

Hashes for sortedness-0.230501.8.tar.gz
Algorithm Hash digest
SHA256 6d5fb828863b0f945caf65b189fdb327d959b7fffdbb93b5c0974b7d0e955b65
MD5 8eede804c85c8d9ecc4104787017700c
BLAKE2b-256 024be113a52b2952c271e6b5dfb9c51144103bbb57290849eb95d5fdbc9f94a5

See more details on using hashes here.

File details

Details for the file sortedness-0.230501.8-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for sortedness-0.230501.8-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 19f1619ffd75ff9c4c58bdfd33922d8730f73b68e893b73e2eae963c43d4d2df
MD5 66ba0bce0f3c83544eba5caf80d99bb0
BLAKE2b-256 48b173a38881d14ac1db8f4b41f63c39f48b3b0351b4460a7047c8a2ebe2e07e

See more details on using hashes here.

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