Note
Go to the end to download the full example code.
Aligning two matrices with the procrustes function¶
run this example as a notebook — or grab the .ipynb (also linked at the bottom of the page)
In this example, we load in some synthetic data, rotate it, and then use the procrustes function to get the datasets back in alignment. The procrustes function uses linear transformations to project a source matrix into the space of a target matrix.
/home/docs/checkouts/readthedocs.org/user_builds/hypertools/checkouts/latest/hypertools/plot/backend.py:1353: UserWarning: Failed to switch to any interactive backend (TkAgg, QtAgg, Qt5Agg, Qt4Agg, GTK4Agg, GTK3Agg, WXAgg). Falling back to 'Agg'.
warnings.warn(BACKEND_WARNING)
/home/docs/checkouts/readthedocs.org/user_builds/hypertools/checkouts/latest/hypertools/plot/backend.py:1353: UserWarning: Failed to switch to any interactive backend (TkAgg, QtAgg, Qt5Agg, Qt4Agg, GTK4Agg, GTK3Agg, WXAgg). Falling back to 'Agg'.
warnings.warn(BACKEND_WARNING)
# Code source: Andrew Heusser
# License: MIT
# import
import hypertools as hyp
from hypertools.align.procrustes import procrustes
# load example data
data = hyp.load('spiral')
hyp.plot(data, title='Before Alignment')
# use procrustes to align the data
source, target = data
aligned = [procrustes(source, target), target]
# after alignment
hyp.plot(aligned, ['-','--'], title='After alignment')
Total running time of the script: (0 minutes 1.201 seconds)

