Efficient Path Signature Features
In what follows I will try to give an accessible introduction to what path signatures are, and the work I did for my Master’s dissertation last year. I am very grateful to Emilio Ferrucci for supervising me. The full dissertation can be found here, but this post includes my thoughts on the main takeaways and limitations.
What are path signatures?
Recall that paths in -dimensional Euclidean space can be defined as continuous functions . Consider a path with the additional property that it has finite length (this is also known as a path of bounded variation). We will use the notation to mean . We can break down into components which are each one-dimensional paths , with .
Each is a function of bounded variation, so an integral of the form
can be given meaning by the Lebesgue-Stieltjes integral. Using this, we can now take repeated integrals of various components against each other, like this:
(note that is simply the increment of the path over the time interval ). Here is the choice of how many repeated integrals to do, and the are choices of dimensions from up to . The same dimension can be chosen more than once.
The signature of a bounded variation path is essentially the collection of all such iterated integrals, at every level . Note that the are dummy variables, so the signature doesn’t depend on them. Such iterated integrals were studied by the mathematician Kuo-Tsai Chen in the mid-20th century1. The signature is in infinite object, but one can take truncations, i.e. only take iterated integrals up to level .
Mathematically, the signature lives in the tensor algebra of the original vector space, . It is not essential to understand what this means at first, and the tensor product notation can make things seem more intimidating than they really are, for example the following expression:
which simply denotes all the -th order iterated integrals of , but arranged to form a tensor in . To be precise,
where is a basis of .
Signatures have several properties which suggest that they are a natural mathematical object. It would be nice if distinct paths had distinct signatures, but this isn’t strictly true: for example, reparametrising a path, or adding a section which exactly doubles back on itself will not change the signature. However, the notion of “tree-like equivalence” perfectly distinguishes when two paths have the same signature2, so one could say that the signature does determine the path, up to tree-like equivalence.
It turns out that signatures contain some redundancies — there are algebraic relations between the values of the iterated integrals which must always hold. But it is possible to define a logarithm map which removes these redundancies. If we start with truncated signatures, then taking logarithms results in truncated log signatures, which take their values in a vector space of lower-dimension than the space where truncated signatures take values.
Path signatures in machine learning
Path signatures can be used in machine learning as feature transform, when the input data takes the form of a path. A strong theoretical justification for doing so is that the signature is a universal nonlinearity. This means that any continuous real-valued function on paths can be approximated arbitrarily well by a linear function composed with the signature! This justifies applying simple linear models to path signature features3.
Signatures have also been used in combination with modern machine learning techniques such as deep learning and gradient boosting, and a range of applications 456789. There are also kernel tricks which allow one to avoid explicitly computing truncated signatures10, and even to implicitly use the untruncated signature11.
It is worth emphasising that any streamed data consisting of numerical values at a number of time-steps can be considered as a continuous path — e.g. by linear interpolation, or through various other methods. More details can be found in this primer by Chevyrev and Kormilitzin, and in the more recent survey by Lyons and McLeod (both of these are great introductions to path signatures in machine learning).
Truncation level vs. number of subpaths
A common technique when creating path signature features is to extract multiple subpaths, compute truncated signatures, or log signatures, over each of them, and stack the results to form a feature vector. This is also done implicitly by several works which use make use of deep learning architectures which use truncated log signatures over subintervals, like Logsig-RNN, Neural Rough Differential Equations, and Log Neural Controlled Differential Equations.
But why take subpaths in the first place? One reason is that, remembering that in practice signatures must be truncated, and therefore contain only a finite amount of information about the path, taking signatures over subpaths allows more information to be captured while only increasing the feature size linearly, by a factor of . In contrast, the feature size grows exponentially if we attempt to capture more information by increasing the truncation level. Depending on the dataset, there may be additional reasons to favour features which are localised in time.
The simplest approach to constructing subpaths is to pick a partition of the time domain, and take the collection of level -truncated signatures over each of the subintervals . Another approach, illustrated below, is to split the time domain in a hierarchical dyadic manner, and compute truncated signatures over every interval (not just those on the lowest level)12.
Let’s consider this setup of using (log) signatures over subpaths as a feature transform, and suppose we want to find a feature set that has minimal dimension while also being sufficiently descriptive. Then, a trade-off between truncation level and path segmentation arises. Increasing either the truncation level of the signatures, or the number of subpaths will make the features more descriptive, but also larger. Having low-dimensional features may be important in “small data” problems, to avoid overfitting, or perhaps we are interested in efficient ways to compress paths just out of mathematical curiosity.
My dissertation explored this trade-off, as well how best to choose the subpaths — previous practical works typically take subpaths by splitting the time domain into equal chunks, but in my opinion the theory suggests that splitting into equal length subpaths is more natural. In experiments I have observed this is sometimes beneficial.
In practice, there is not a principled way to make the choice of truncation level and the family of subpaths. Focussing on the truncation level, the universal nonlinearity result says that by setting it sufficiently high we can approximate any continuous function on paths arbitrarily well by a linear function composed with the truncated signature. However, this tells us nothing about how high needs to be in practice to get decent results — just like universal approximation results for neural networks typically don’t tell you how wide or deep your network needs to be for any specific task.
My dissertation considers two ways of measuring how descriptive the features are: the first via error bounds for approximating a certain class of functions, and the second by training some simple models and measuring the generalisation error.
Error bounds for solutions to controlled differential equations
On the more theoretical side, I considered a class of functions which map paths to the time- solution of a linear controlled differential equation driven by the path. For a fixed linear CDE, with the vector field and the driving path specified, there is a natural way to approximate the time- solution if we are given the signatures up to level over a number of subintervals, using an Euler-like numerical scheme.
An error bound for this approximation scheme can be computed. For a given feature set, this tells us an upper bound on how well an arbitrary function in the set of functions defined by linear CDEs (with bounds on the norm of the vector field, and also on the length of the input paths) can be approximated by some function of the feature set.
The following figures plot these upper bounds against the size of the feature set (assuminng that log signatures are used). is the number of dimensions of the space in which the paths lie. is the product of , the bound on the norm of the vector fields, and , the bound on the length of paths. For each truncation level , the number of subintervals increases in steps of up to a maximum determined by computational constraints.
You can read off from these plots the truncation level of the most efficient feature set that achieves a given value for the error bound. When , higher values of tend to be optimal. But when is increased to or , higher truncation levels are more costly in terms of feature size, and feature sets which use lower-level signatures over a greater number of subpaths seem to be more efficient than ones using higher-order signatures. Increasing favours features sets with lower and higher .
Empirical tests of generalisation performance
The error bound analysis doesn’t account for the fact that the function needs to be learned from a finite dataset. A theoretical analysis of this seems difficult, but we can run empirical experiments.
My empirical tests were to simply train machine learning models and compare choices of , the truncation level, and , to see what is the most efficient way to achieve a given test accuracy. I ran these on both synthetic data and real accelerometer data provided by the Child Mind Institute for a Kaggle competition.
I found setting up these experiments well to be tricky, and did not get amazing results. Initially, we wanted to use log signature features as inputs for polynomial regression, since lo;g signatures are more concise than signatures. The motivation for polynomial regression is that a using a polynomial one can go from the log signatures back to the normal signatures, and then apply a linear function. With the universal nonlinearity theorem, this easily gives a universal nonlinearity result. However, actually computing polynomial features beyond low degrees results in a huge number of features, so I decided to use kernel ridge regression with a polynomial kernel. This then introduces new issues, since there are hyperparameters to tune and the computational complexity limits the size of the dataset that can be used.
In addition to this, splitting the path into more subpaths and taking signatures, while in theory providing more information, can in practice make it harder to learn the desired function. Since the feature sets become large and I was using only small datasets, there are also issues with overfitting.
For more details, see the full dissertation, but overall I would note that I think there is lots of room for improvement in this approach to empirical tests!
The experiments on real data show much better performance when the paths are split by equal length (1-variation) instead of equal time, with the large caveat that I only tried out one (small) dataset:
I think the main takeaway for a practitioner is that splitting by equal length can result in better performance than splitting by equal time. This change is not difficult to implement and it is theoretically motivated.
Using path signature features in practice
On what sorts of real-world data would path signature features be a particularly useful feature transform? I don’t have an answer for this, but here are some rough intuitions (based on my limited experience):
- If the dimensionality of the data is high to begin with then this is not good because signature features beyond a very low truncation level will be very high dimensional.
- If the problem feels like predicting the state of a system which is in some sense “driven” by the path, this might be good because such a system might be modelled as a controlled differential equation.
- If the paths are measured with a lot of noise then this might be bad — I don’t know how errors in measurements of the path propagate to errors in signature terms.
Several software libraries are available which compute (log) signatures, including RoughPy (still under development as of September 2024), signax (a JAX library), Signatory (a differentiable implementation), iisignature, and esig.
Other practical considerations include the following:
- It is important to apply an appropriate form of normalisation. Asymptotically, the magnitude of signature terms decays as the level increases. Morrill et al. compared two dataset-independent approaches to rescaling signature terms. However, the asymptotic results don’t really say much about the magnitudes of signature terms at lower levels, so I think it a good idea to apply a standard approach to normalisation of the path signature features (using the dataset statistics).
- There are a number of augmentations that can be applied to paths as preprocessing steps before computing signatures (see Section 2.1 of Chevyreva and Kormilitzina and Section 2.5 of Lyons and McLeod). Several approaches were compared by Morrill et al.
Footnotes
-
E.g. in Kuo-Tsai Chen: “Iterated integrals and exponential homomorphisms”, Proceedings of the London Mathematical Society 3.1 (1954) ↩
-
Ben Hambly and Terry Lyons: “Uniqueness for the signature of a path of bounded variation and the reduced path group”, Annals of Mathematics (2010) ↩
-
As proposed in Daniel Levin, Terry Lyons, and Hao Ni: “Learning from the past, predicting the statistics for the future, learning an evolving system”, arXiv:1309.0260 (2013) ↩
-
Weixin Yang, Lianwen Jin, and Manfei Liu: “Character-level Chinese writer identification using path signature feature, dropstroke and deep CNN”, arXiv:1505.04922 (2015) ↩
-
Weixin Yang, Lianwen Jin, Hao Ni, and Terry Lyons: “Rotation-free online handwritten character recognition using dyadic path signature features, hanging normalization, and deep neural network”, 2016 23rd International Conference on Pattern Recognition (ICPR), IEEE (2016) ↩
-
Shujian Liao, Terry Lyons, Weixin Yang, and Hao Ni: “Learning stochastic differential equations using RNN with log signature features”, arXiv:1908.08286 (2019) ↩
-
James Morrill, Andrey Kormilitzin, Alejo Nevado-Holgado, Sumanth Swaminathan, Sam Howison, and Terry Lyons: “The signature-based model for early detection of sepsis from electronic health records in the intensive care unit”, 2019 Computing in Cardiology (CinC), IEEE (2019) ↩
-
Shujian Liao, Terry Lyons, Weixin Yang, Kevin Schlegel, and Hao Ni: “Logsig-RNN: A novel network for robust and efficient skeleton-based action recognition”, arXiv:2110.13008 (2021) ↩
-
Weixin Yang, Terry Lyons, Hao Ni, Cordelia Schmid, and Lianwen Jin: “Developing the path signature methodology and its application to landmark-based human action recognition”, Stochastic Analysis, Filtering, and Stochastic Optimization: A Commemorative Volume to Honor Mark HA Davis’s Contributions, Springer (2022) ↩
-
Franz J. Király and Harald Oberhauser: “Kernels for sequentially ordered data”, Journal of Machine Learning Research, Vol. 20 (2019) ↩
-
Cristopher Salvi, Thomas Cass, James Foster, Terry Lyons, and Weixin Yang: “The signature kernel is the solution of a Goursat PDE”, SIAM Journal on Mathematics of Data Science, Vol. 3, No. 3 (2021) ↩
-
This was done in Weixin Yang, Lianwen Jin, Hao Ni, and Terry Lyons: “Rotation-free online handwritten character recognition using dyadic path signature features, hanging normalization, and deep neural network”, 2016 23rd International Conference on Pattern Recognition (ICPR), IEEE (2016) ↩