Measures of projection quality
Project description
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 functions presented here (paper unavailable until publication).
Overview
Local variants return a value for each provided point. The global variant returns a single value for all points. Any local variant can be used as a global measure by taking the mean value.
Local variants: sortedness(X, X_)
, pwsortedness(X, X_)
, rsortedness(X, X_)
.
Global variant: global_sortedness(X, X_)
.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sortedness-0.230501.9.tar.gz
.
File metadata
- Download URL: sortedness-0.230501.9.tar.gz
- Upload date:
- Size: 633.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c010501ae3a91b7fc7ff228fb93f4d70e53ab816fc904c5da7ab5492c993229 |
|
MD5 | d47b273078c7c1b1b64e796c611262e4 |
|
BLAKE2b-256 | 78fcaf48317a9f8d83b94e02591da8a59d1fd8b565cb3d39c433389bfc1a0cb4 |
File details
Details for the file sortedness-0.230501.9-cp310-cp310-manylinux_2_35_x86_64.whl
.
File metadata
- Download URL: sortedness-0.230501.9-cp310-cp310-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 645.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-58-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3829323b598728df3f0795582fbb53a69b3f5c88b8e2597efc3ac76e5617c9b0 |
|
MD5 | 0ff31ef1f12d9e71ceb1ffa1b9047452 |
|
BLAKE2b-256 | e297ff4697f05a009af9a9ff284443490bd2c87b43423625a880824cefb1686e |