patrick-kidger / signatory

Differentiable computations of the signature and logsignature transforms, on both CPU and GPU. (ICLR 2021)
Apache License 2.0
262 stars 35 forks source link

Is it possible to expose the exp map to the Python API via a logsignature_to_signature function? #48

Open Mithrillion opened 2 years ago

Mithrillion commented 2 years ago

Somehow, I found myself needing to map a logsignature back to the full signature (where the logsignature can be in either the tensor algebra or a compressed form). It appears the relevant operations such as exp map already exist in the C++ code, so I wonder how difficult it would be to implement a logsignature_to_signature function.

Currently, I have tried two options. The iisignature package do offer a mapping from logsignature to signature, but this requires casting data from PyTorch to numpy and back, and potentially also moving data between devices, so it works, but is not ideal.

Alternatively, I could implement the truncated expansion of the exp map directly in PyTorch, following the template in iisignature and also bottler's free-lie-algebra-py, using the exp(x)=1+x+x/2(x+x/3(x+...)) trick. However, this is significantly slower than computing via iisignature.

Therefore I guess my best bet is to expose the exp map within signatory's C++ code to the Python API. However, I am not familiar with PyTorch in C++ and am not sure how much effort it would take to try to implement a logsignature_to_signature function.

Is it possible that such a functionality can be implemented fairly quickly? And is it possible for logsignature_to_signature to eventually be included in signatory?

Many thanks!

patrick-kidger commented 2 years ago

Signatory's exp map only takes in a path increment; not a generic logsignature. I'm afraid Signatory does not implement a full logsig-to-sig conversion.

As another alternate solution, you could do all of your operations on the signature, and then just convert sig-to-logsig whenever you need the latter.

Mithrillion commented 2 years ago

This is a bit unfortunate... But I guess I can take the iisignature detour for now, while looking for a PyTorch-compatible solution or trying to port an existing solution.

For my use case I really need to do my operations on the logsignature, as I am trying to find a way to scale or "average" signatures such that they do not leave the domain of "well-defined signatures" . The average of two signatures is likely not a valid signature, therefore I have to do so in the logsignature domain. I then would like to do normal operations like concatenation afterwards, so it would be helpful to return it to the signature domain.

But thanks anyway. Now I know a little bit more about how signatory works internally.