This repository provides a Python implementation of TDLM.
- Work-in-Progress -
Temporally Delayed Linear Modeling (TDLM) is a method used to quantify the "sequenceness" or sequential structure in time-series data. It's particularly useful for analyzing sequences of events or actions where the order of occurrence is significant. TDLM works by creating a linear model that incorporates time delays between different elements of the sequence. By introducing these delays, the model can capture the temporal dependencies within the sequence. For instance, in the context of analyzing human behavior, TDLM can help identify patterns such as the likelihood of certain reactivation events following others with a specific time lag.
pip install git+https://github.com/skjerns/TDLM-Python/
import tdlm
preds = ... # get your prediction matrix somehwere
tf = [[0, 1, 0], [ 0, 0, 1], [1, 0 , 0]] # transition matrix
sequenceness_fwd, sequenceness_bkw, * = tdlm.compute_1step(preds, tf)
# plot results
tdlm.plotting.plot_sequenceness(sequenceness_fwd, sequenceness_bkw)
Currently the repo is still quite bare, only providing basic functionality. I have created some Issues to get started. Designing a package is always challenging, as design choices will be difficult to revert, so feel free to contribute and discuss this.
design decisions:
-
all time dimensions should be in sample steps. E.g.
max_lag=50
means 50 steps in sample space, disregarding the actual sample frequency. It is up to the user to calculate the fitting times. -
The base function for all computations should be
compute_glm
orcompute_crosscorr
, all other functions should use this function modularly to their needs -
Cross correlation and GLM are two different base function that can be used. Other functions take a parameter which is either
glm
orcrosscorr
to denote which function is used. This way it is theoretically possible to extend the repository using other functions as well (e.g. granger causality, which is basically a flavor of crosscorr I guess) -
Transition matrices should be format of a binary matrix. Helper functions are provided to convert a sequence string in format
ABC_DEF
denoting transitions from A->B->C and D->E->F.