Skip to content

Commit

Permalink
[ENH] iisignature backend option for SignatureTransformer (#5398)
Browse files Browse the repository at this point in the history
Fixes a bug where a runtime error is returned if each point of the
time-series has dimension more than 25. Fixes #1591 indirectly through the new backend.

Also allows "no augmentation" choice, currently the code returns an error if
augmentations is None -- the user will be forced to choose an
augmentation.
This PR adds enhanced flexibility to allow to user to choose no stream
augmentation.
  • Loading branch information
sz85512678 committed Nov 4, 2023
1 parent 441e334 commit 8035daa
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 22 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Expand Up @@ -2376,6 +2376,15 @@
"code"
]
},
{
"login": "sz85512678",
"name": "Zhen Shao",
"avatar_url": "https://avatars.githubusercontent.com/sz85512678",
"profile": "https://github.com/sz85512678",
"contributions": [
"code"
]
},
{
"login": "Vasudeva-bit",
"name": "Vasudeva Kilaru",
Expand Down
9 changes: 5 additions & 4 deletions CONTRIBUTORS.md
Expand Up @@ -2,7 +2,7 @@ Contributors
============

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-239-orange.svg)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-240-orange.svg)](#contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Expand Down Expand Up @@ -270,15 +270,16 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<tr>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/yashlamba"><img src="https://avatars.githubusercontent.com/u/44164398?v=4?s=100" width="100px;" alt="Yash Lamba"/><br /><sub><b>Yash Lamba</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=yashlamba" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/xuyxu"><img src="https://avatars2.githubusercontent.com/u/22359569?v=4?s=100" width="100px;" alt="Yi-Xuan Xu"/><br /><sub><b>Yi-Xuan Xu</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=xuyxu" title="Code">💻</a> <a href="https://github.com/sktime/sktime/commits?author=xuyxu" title="Tests">⚠️</a> <a href="#maintenance-xuyxu" title="Maintenance">🚧</a> <a href="https://github.com/sktime/sktime/commits?author=xuyxu" title="Documentation">📖</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/sz85512678"><img src="https://avatars.githubusercontent.com/sz85512678?s=100" width="100px;" alt="Zhen Shao"/><br /><sub><b>Zhen Shao</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=sz85512678" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/ZiyaoWei"><img src="https://avatars.githubusercontent.com/u/940823?v=4?s=100" width="100px;" alt="Ziyao Wei"/><br /><sub><b>Ziyao Wei</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=ZiyaoWei" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/aa25desh"><img src="https://avatars1.githubusercontent.com/u/29518290?v=4?s=100" width="100px;" alt="aa25desh"/><br /><sub><b>aa25desh</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=aa25desh" title="Code">💻</a> <a href="https://github.com/sktime/sktime/issues?q=author%3Aaa25desh" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/abandus"><img src="https://avatars2.githubusercontent.com/u/46486474?v=4?s=100" width="100px;" alt="abandus"/><br /><sub><b>abandus</b></sub></a><br /><a href="#ideas-abandus" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/sktime/sktime/commits?author=abandus" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/adoherty21"><img src="https://avatars.githubusercontent.com/u/52799751?s=400&v=4?s=100" width="100px;" alt="adoherty21"/><br /><sub><b>adoherty21</b></sub></a><br /><a href="https://github.com/sktime/sktime/issues?q=author%3Aadoherty21" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/bethrice44"><img src="https://avatars.githubusercontent.com/u/11226988?v=4?s=100" width="100px;" alt="bethrice44"/><br /><sub><b>bethrice44</b></sub></a><br /><a href="https://github.com/sktime/sktime/issues?q=author%3Abethrice44" title="Bug reports">🐛</a> <a href="https://github.com/sktime/sktime/commits?author=bethrice44" title="Code">💻</a> <a href="https://github.com/sktime/sktime/pulls?q=is%3Apr+reviewed-by%3Abethrice44" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/sktime/sktime/commits?author=bethrice44" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/big-o"><img src="https://avatars1.githubusercontent.com/u/1134151?v=4?s=100" width="100px;" alt="big-o"/><br /><sub><b>big-o</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=big-o" title="Code">💻</a> <a href="https://github.com/sktime/sktime/commits?author=big-o" title="Tests">⚠️</a> <a href="#design-big-o" title="Design">🎨</a> <a href="#ideas-big-o" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/sktime/sktime/pulls?q=is%3Apr+reviewed-by%3Abig-o" title="Reviewed Pull Requests">👀</a> <a href="#tutorial-big-o" title="Tutorials">✅</a> <a href="#mentoring-big-o" title="Mentoring">🧑‍🏫</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/bobbys-dev"><img src="https://avatars.githubusercontent.com/bobbys-dev?s=100" width="100px;" alt="bobbys"/><br /><sub><b>bobbys</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=bobbys-dev" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/bobbys-dev"><img src="https://avatars.githubusercontent.com/bobbys-dev?s=100" width="100px;" alt="bobbys"/><br /><sub><b>bobbys</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=bobbys-dev" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/brettkoonce"><img src="https://avatars2.githubusercontent.com/u/11281814?v=4?s=100" width="100px;" alt="brett koonce"/><br /><sub><b>brett koonce</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=brettkoonce" title="Documentation">📖</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/btrtts"><img src="https://avatars3.githubusercontent.com/u/66252156?v=4?s=100" width="100px;" alt="btrtts"/><br /><sub><b>btrtts</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=btrtts" title="Documentation">📖</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/chizzi25"><img src="https://avatars3.githubusercontent.com/u/67911243?v=4?s=100" width="100px;" alt="chizzi25"/><br /><sub><b>chizzi25</b></sub></a><br /><a href="#blog-chizzi25" title="Blogposts">📝</a></td>
Expand All @@ -287,9 +288,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="11.11%"><a href="https://github.com/hamzahiqb"><img src="https://avatars3.githubusercontent.com/u/10302415?v=4?s=100" width="100px;" alt="hamzahiqb"/><br /><sub><b>hamzahiqb</b></sub></a><br /><a href="#infra-hamzahiqb" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/hiqbal2"><img src="https://avatars3.githubusercontent.com/u/10302415?v=4?s=100" width="100px;" alt="hiqbal2"/><br /><sub><b>hiqbal2</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=hiqbal2" title="Documentation">📖</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/jesellier"><img src="https://avatars0.githubusercontent.com/u/51952076?v=4?s=100" width="100px;" alt="jesellier"/><br /><sub><b>jesellier</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=jesellier" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/jschemm"><img src="https://avatars.githubusercontent.com/u/81151346?v=4?s=100" width="100px;" alt="jschemm"/><br /><sub><b>jschemm</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=jschemm" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/jschemm"><img src="https://avatars.githubusercontent.com/u/81151346?v=4?s=100" width="100px;" alt="jschemm"/><br /><sub><b>jschemm</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=jschemm" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/kkoziara"><img src="https://avatars1.githubusercontent.com/u/4346849?v=4?s=100" width="100px;" alt="kkoziara"/><br /><sub><b>kkoziara</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=kkoziara" title="Code">💻</a> <a href="https://github.com/sktime/sktime/issues?q=author%3Akkoziara" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/matteogales"><img src="https://avatars0.githubusercontent.com/u/9269326?v=4?s=100" width="100px;" alt="matteogales"/><br /><sub><b>matteogales</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=matteogales" title="Code">💻</a> <a href="#design-matteogales" title="Design">🎨</a> <a href="#ideas-matteogales" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/oleskiewicz"><img src="https://avatars1.githubusercontent.com/u/5682158?v=4?s=100" width="100px;" alt="oleskiewicz"/><br /><sub><b>oleskiewicz</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=oleskiewicz" title="Code">💻</a> <a href="https://github.com/sktime/sktime/commits?author=oleskiewicz" title="Documentation">📖</a> <a href="https://github.com/sktime/sktime/commits?author=oleskiewicz" title="Tests">⚠️</a></td>
Expand All @@ -298,9 +299,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="11.11%"><a href="https://github.com/raishubham1"><img src="https://avatars3.githubusercontent.com/u/29356417?v=4?s=100" width="100px;" alt="raishubham1"/><br /><sub><b>raishubham1</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=raishubham1" title="Documentation">📖</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/simone-pignotti"><img src="https://avatars1.githubusercontent.com/u/44410066?v=4?s=100" width="100px;" alt="simone-pignotti"/><br /><sub><b>simone-pignotti</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=simone-pignotti" title="Code">💻</a> <a href="https://github.com/sktime/sktime/issues?q=author%3Asimone-pignotti" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/sophijka"><img src="https://avatars2.githubusercontent.com/u/47450591?v=4?s=100" width="100px;" alt="sophijka"/><br /><sub><b>sophijka</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=sophijka" title="Documentation">📖</a> <a href="#maintenance-sophijka" title="Maintenance">🚧</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/sri1419"><img src="https://avatars2.githubusercontent.com/u/65078278?v=4?s=100" width="100px;" alt="sri1419"/><br /><sub><b>sri1419</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=sri1419" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/sri1419"><img src="https://avatars2.githubusercontent.com/u/65078278?v=4?s=100" width="100px;" alt="sri1419"/><br /><sub><b>sri1419</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=sri1419" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/tensorflow-as-tf"><img src="https://avatars.githubusercontent.com/u/51345718?v=4?s=100" width="100px;" alt="tensorflow-as-tf"/><br /><sub><b>tensorflow-as-tf</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=tensorflow-as-tf" title="Code">💻</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/vedazeren"><img src="https://avatars3.githubusercontent.com/u/63582874?v=4?s=100" width="100px;" alt="vedazeren"/><br /><sub><b>vedazeren</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=vedazeren" title="Code">💻</a> <a href="https://github.com/sktime/sktime/commits?author=vedazeren" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="11.11%"><a href="https://github.com/vincent-nich12"><img src="https://avatars3.githubusercontent.com/u/36476633?v=4?s=100" width="100px;" alt="vincent-nich12"/><br /><sub><b>vincent-nich12</b></sub></a><br /><a href="https://github.com/sktime/sktime/commits?author=vincent-nich12" title="Code">💻</a></td>
Expand Down
10 changes: 5 additions & 5 deletions sktime/transformations/panel/signature_based/_augmentations.py
Expand Up @@ -43,11 +43,11 @@ def _make_augmentation_pipeline(augmentation_list):
if augmentation_list is not None:
if isinstance(augmentation_list, str):
augmentation_list = (augmentation_list,)
assert all(
[x in list(AUGMENTATIONS.keys()) for x in augmentation_list]
), "augmentation_list must only contain string elements from {}. Given: {}.".format(
list(AUGMENTATIONS.keys()), augmentation_list
)
if not [x in list(AUGMENTATIONS.keys()) for x in augmentation_list]:
raise ValueError(
"augmentation_list must only contain string elements from "
f" {list(AUGMENTATIONS.keys())}. Found: {augmentation_list}"
)

# Setup pipeline
if augmentation_list is not None:
Expand Down
5 changes: 5 additions & 0 deletions sktime/transformations/panel/signature_based/_compute.py
Expand Up @@ -45,6 +45,7 @@ def __init__(
sig_tfm=None,
sig_depth=None,
rescaling=None,
backend=None,
):
super().__init__()
self.window_name = window_name
Expand All @@ -54,6 +55,7 @@ def __init__(
self.sig_tfm = sig_tfm
self.sig_depth = sig_depth
self.rescaling = rescaling
self.backend = backend

self.window = _window_getter(
self.window_name, self.window_depth, self.window_length, self.window_step
Expand All @@ -62,6 +64,9 @@ def __init__(
def _transform(self, X, y=None):
import esig

if self.backend == "iisignature":
esig.set_backend("iisignature")

depth = self.sig_depth
data = np.swapaxes(X, 1, 2)

Expand Down
64 changes: 51 additions & 13 deletions sktime/transformations/panel/signature_based/_signature_method.py
Expand Up @@ -9,6 +9,8 @@
from sktime.transformations.panel.signature_based._compute import (
_WindowSignatureTransform,
)
from sktime.utils.validation._dependencies import _check_soft_dependencies
from sktime.utils.warnings import warn


class SignatureTransformer(BaseTransformer):
Expand All @@ -19,19 +21,34 @@ class SignatureTransformer(BaseTransformer):
Parameters
----------
augmentation_list: tuple of strings, contains the augmentations to be
applied before application of the signature transform.
window_name: str, The name of the window transform to apply.
window_depth: int, The depth of the dyadic window. (Active only if
`window_name == 'dyadic'`).
window_length: int, The length of the sliding/expanding window. (Active
only if `window_name in ['sliding, 'expanding']`.
window_step: int, The step of the sliding/expanding window. (Active
only if `window_name in ['sliding, 'expanding']`.
rescaling: str or None, The method of signature rescaling.
sig_tfm: str, String to specify the type of signature transform. One of:
['signature', 'logsignature']).
depth: int, Signature truncation depth.
augmentation_list: list or tuple of strings, possible strings are
['leadlag', 'ir', 'addtime', 'cumsum', 'basepoint']
Augmentations to apply to the data before computing the signature.
The order of the augmentations is the order in which they are applied.
default: ('basepoint', 'addtime')
window_name: str, one of ``['global', 'sliding', 'expanding', 'dyadic']``
default: 'dyadic'
Type of the window to use for the signature transform.
window_depth: int, default=3
The depth of the dyadic window.
Ignored unless ``window_name`` is ``'dyadic'``.
window_length: None (default) or int
The length of the sliding/expanding window. (Active
Ignored unless ``window_name`` is one of ``['sliding, 'expanding']``.
window_step: None (default) or int
The step of the sliding/expanding window.
Ignored unless ``window_name`` is one of ``['sliding, 'expanding']``.
rescaling: None (default) or str, "pre" or "post",
None: No rescaling is applied.
"pre": rescale the path last signature term should be roughly O(1)
"post": Rescales the output signature by multiplying the depth-d term by d!.
Aim is that every term becomes ~O(1).
sig_tfm: str, one of ``['signature', 'logsignature']``. default: ``'signature'``
The type of signature transform to use, plain or logaritmic.
depth: int, default=4
Signature truncation depth.
backend: str, one of: ``'esig'`` (default), or ``'iisignature'``.
The backend to use for signature computation.
Attributes
----------
Expand Down Expand Up @@ -62,6 +79,7 @@ def __init__(
rescaling=None,
sig_tfm="signature",
depth=4,
backend="esig",
):
self.augmentation_list = augmentation_list
self.window_name = window_name
Expand All @@ -71,8 +89,27 @@ def __init__(
self.rescaling = rescaling
self.sig_tfm = sig_tfm
self.depth = depth
self.backend = backend

super().__init__()

if backend == "esig":
_check_soft_dependencies("esig")
elif backend == "iisignature":
_check_soft_dependencies("iisignature")
warn(
"iisignature backend of SignatureTransformer is experimental "
"and not systematically tested, due to lack of stable installation "
"process for iisignature via pip. Kindly exercise caution, "
"and report any issues on the sktime issue tracker.",
stacklevel=2,
)
else:
raise ValueError(
"Error in SignatureTransformer, backend "
"must be one of 'esig' or 'iisignature'"
)

self.setup_feature_pipeline()

def setup_feature_pipeline(self):
Expand All @@ -86,6 +123,7 @@ def setup_feature_pipeline(self):
sig_tfm=self.sig_tfm,
sig_depth=self.depth,
rescaling=self.rescaling,
backend=self.backend,
)

# The so-called 'signature method' as defined in the reference paper
Expand Down

0 comments on commit 8035daa

Please sign in to comment.