Registration#
spm1d procedures require registered data. “Registered” means that all measurements must be sampled at the same number of points \(Q\) and an individual domain point \(q\) should generally represent a homologous location in all measurements.
Several linear and nonlinear registration algorithms exist in the literature. “Linear” means that domain points are transformed so that the relative inter-point distance remains unchanged. “Nonlinear” means the relative inter-point distances are generally unequal. If the 1D domain is time, linear registration effectively just speeds up or slows down time so that all observations have the same duration. Nonlinear registration warps time, so that one part of an observation is sped up and another is slowed down, generally to optimally match amplitude patterns in other observations.
In spm1d 0.4 a simple linear interpolation algorithm was provided, but this has been moved to a new package: registration1d. Three registration approaches are described below.
Linear registration#
Linear registration interpolates each observation to the same number of points. In the example below 30 kinematic trajectories with 89 to 150 frames are linearly registered to 101 points:
import numpy as np
import registration1d as reg1d
y0 = list( np.load( 'kinematics_unequal.npy', allow_pickle=True ) ) # 30 arrays with different lengths
y = reg1d.register_linear( y0, n=101 ).y # (30,101) array
Linear registration aligns the start and end of each continuum. Events between the start and end can remain misaligned.
Nonlinear registration#
Nonlinear registration warps the domain of each continuum to align events between its start and end. The example below continues from the linearly registered data y above.
rlm = reg1d.register_landmark( y, kinds=('zero',) ) # landmark registration: align each continuum's zero crossing
rsr = reg1d.register_srsf( y, max_iter=5 ) # elastic registration
Landmark registration aligns specified events (here each continuum’s zero crossing) and warps the domain smoothly between them. Elastic registration (register_srsf) aligns each continuum to a template without specified events. The figure below depicts the linearly registered data and both nonlinear results.
Each nonlinear result contains the warps that were applied to each continuum. Their displacement fields indicate how far each domain point was moved:
d = rsr.warps.displacement_field() # (30,101) array
Amplitude and timing effects#
Several nonlinear registration algorithms, including register_srsf, aim to optimally separate amplitude and phase effects; when the domain is time “phase effects” can be interpreted as “timing effects”. After registration, amplitude effects are embodied in the registered fields themselves, and phase effects are embodied in the warp fields. Both types of fields can be analyzed.
The example below considers knee flexion during walking from 50 subjects aged 6 to 72 years from the (Lencioni et al. 2019) dataset. In jiku-data this dataset is available both pre- and post-registration via register_srsf. Below regression analysis is considered for the original, amplitude and phase data, in each case with age as the independent variable.
import spm1d
import jikudata as jd
for dataset in ( jd.Lencioni2019(), jd.Lencioni2019Registered(), jd.Lencioni2019Warps() ):
y, age = dataset.y, dataset.x # (50,101) array and (50,) array; the warps have 99 points
ti = spm1d.stats.regress( y, age ).inference( 0.05 )
print( dataset.name, ti.h0reject )
Lencioni2019 True
Lencioni2019Registered False
Lencioni2019Warps True
The linearly registered data suggest that knee flexion significantly decreases with age at 46 to 70% of the gait cycle. However nonlinear registration results suggest that this apparent flexion effect is non-significant, and that timing differences in the vicinity of maximum knee flexion can more aptly explain the observed effect.