jeremymanning / hypertools

A python toolbox for gaining geometric insights into high-dimensional data
http://hypertools.readthedocs.io/en/latest/
MIT License
1 stars 1 forks source link

ensure "story trajectories" pipeline can be reproduced #27

Open jeremymanning opened 2 years ago

jeremymanning commented 2 years ago

using previous versions of hypertools, the demo "gif" can be reproduced as follows:

import hypertools as hyp
import timecorr as tc
from scipy.interpolate import pchip
import numpy as np

def resample(a, n):
    b = np.zeros([n, a.shape[1]])
    x = np.linspace(1, a.shape[0], num=a.shape[0], endpoint=True)
    xx = np.linspace(1, a.shape[0], num=n, endpoint=True)
    for i in range(a.shape[1]):
        interp = pchip(x, a[:, i])
        b[:, i] = interp(xx)
    return b

pieman_data = hyp.load('weights').data
smoothed = tc.smooth(pieman_data, kernel_fun=tc.helpers.gaussian_weights, kernel_params={'var': 50})
resampled = [resample(x, 1000) for x in smoothed]

aligned = hyp.align(resampled, align='hyper')
hyp.plot(aligned, align=True, reduce='UMAP', animate=True, duration=30, tail_duration=4.0, zoom=0.5, save_path='pieman.mov')

A similar approach should work with the revamped version, but it doesn't seem to work well in practice:

import hypertools as hyp

data = hyp.load('weights')

manip = [{'model': 'Smooth', 'args': [], 'kwargs': {'kernel_width': 25}},
         {'model': 'Resample', 'args': [], 'kwargs': {'n_samples': 1000}},
         'ZScore']
hyperalign = {'model': 'HyperAlign', 'args': [], 'kwargs': {'n_iter': 2}}

hyp.plot(data, manip=manip, align=hyperalign, animate='window', reduce='UMAP', duration=30, focused=4, zoom=0.5)

there are at least a few differences that i notice:

it's also possible that something is off with the revised hyperalignment implementation, despite that the alignment tests are passing...