Procrustes Similarity with the Reconstructed Space
Project description
PSRS — Procrustes Similarity with Reconstructed Space
This is a PyTorch-based toolkit for PSRS method for quantifying relative information content between two embedding spaces. It works by reconstructing one space from the other with a flexible neural network and then measuring their alignment under Procrustes analysis (rotation, scaling, translation). PSRS can be understood as a generalized form of Procrustes analysis: instead of comparing spaces directly, PSRS first learns a non-linear mapping before alignment, allowing it to capture more complex relationships between representations.
Installation
pip install psrs
Usage
Here is how to use the package.
import numpy as np
from psrs import PSRS
# toy spaces
n_samples, n_dimensions = 100, 16
space_a = np.random.randn(n_samples, n_dimensions)
space_b = np.random.randn(n_samples, n_dimensions)
model = PSRS(space_a=space_a, space_b=space_b)
model.reconstruct(epochs=10)
# similarity after Procrustes alignment (0 to 1)
score = model.calculate_procrustes_similarity()
print(f"PSRS similarity: {score:.3f}")
All configurations at your disposal
psrs = PSRS(space_a, space_b, random_state=0, verbose=True)
# You can leave everything at defaults:
model.reconstruct(
epochs=10, # training steps
learning_rate=5e-3, # Adam lr
hidden_dims_list=None, # None → sensible defaults based on dims of A and B
test_size=0.3, # 70/30 split (scaled to [0,1])
loss_fn="mse", # "procrustes" or "mse" (see note below)
checkpoint_interval=5, # logging cadence when verbose=True
batch_size=50, # mini-batch size
activation_function="ReLU" # 'ReLU' or 'GELU'
)
print("Test PSRS:", model.calculate_procrustes_similarity())
Note on loss choice: loss_fn="procrustes" is usually fast and works well, but in rare cases it can be less stable for backprop. If training diverges, switch to loss_fn="mse"
API at a Glance
PSRS(space_a, space_b, random_state=None, verbose=False)
space_a,space_b:np.ndarrayortorch.Tensorwith the same number of rows (paired observations).random_state: integer seed for reproducibility.verbose: ifTrue, logs training progress during reconstruction.
Internally, inputs are min–max scaled per feature, and data is split into train/test sets.
PSRS.reconstruct(...)
Fit a DeepShallow model to reconstruct space B from space A.
Arguments (all optional, with robust defaults):
epochs(int, default=100) — training iterations.learning_rate(float, default=0.005) — Adam step size.hidden_dims_list(list[int] or None, default=None) — hidden layer widths. IfNone, picks a dimension-aware stack automatically.random_state(int or None, default=None) — seed for reproducibility.test_size(float, default=0.3) — fraction of data held out for testing, the similarity is calculated on test data.loss_fn{"procrustes", "mse"}, default="procrustes" — the choice of loss function.procrustesconverges much faster, but it sometimes is unstable.checkpoint_interval(int, default=50) — logging interval whenverbose=True.loss_reduction_method{"mean", "sum"}, default="mean" — reduction method for the loss.activation_function{"ReLU", "GELU"}, default="ReLU" — non-linear activation in the deep network.batch_size(int, default=128) — mini-batch size. If length of the training data is smaller than thebatch_size, the size is adjusted to the length of the training data.optimizer(torch.optim.Optimizer or None, default=None) — custom optimizer. IfNone, uses Adam withlearning_rate.
PSRS.calculate_procrustes_similarity() -> float
Returns the test-set Procrustes similarity between predicted and true representations:
- Values closer to 1.0 indicate higher structural similarity after optimal rotation, scaling, and translation.
License
See the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file psrs-0.1.0.tar.gz.
File metadata
- Download URL: psrs-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d32737db03052eadd59c8a9391d40967d01600bfa341f19f6e15e0065a494de
|
|
| MD5 |
e7b1105b6ea782dade4f9d9127fb14d3
|
|
| BLAKE2b-256 |
48b9b33c71e636c7f30fcd6d3b97bd8419fb220ef7b6396b0c12c1e9f435ff5e
|
File details
Details for the file psrs-0.1.0-py3-none-any.whl.
File metadata
- Download URL: psrs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f9305e4067edc83f84434931e86024415f02816b7dfc33c59185be7d1dc64b9
|
|
| MD5 |
14c5a7e86e0d4d6c61c87ebb6a48178e
|
|
| BLAKE2b-256 |
98eb89570083b2ffa61b6d725170021e46c61eeb7a2dd4e5a9aabfbab61e4589
|