tensordev 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. tensordev-0.0.1/LICENSE +202 -0
  2. tensordev-0.0.1/PKG-INFO +442 -0
  3. tensordev-0.0.1/README.md +412 -0
  4. tensordev-0.0.1/pyproject.toml +66 -0
  5. tensordev-0.0.1/setup.cfg +4 -0
  6. tensordev-0.0.1/src/tensordev/__init__.py +135 -0
  7. tensordev-0.0.1/src/tensordev/_backend.py +63 -0
  8. tensordev-0.0.1/src/tensordev/core/__init__.py +16 -0
  9. tensordev-0.0.1/src/tensordev/core/einsum.py +68 -0
  10. tensordev-0.0.1/src/tensordev/core/jax.py +303 -0
  11. tensordev-0.0.1/src/tensordev/core/numba.py +103 -0
  12. tensordev-0.0.1/src/tensordev/core/sequential.py +226 -0
  13. tensordev-0.0.1/src/tensordev/core/shuffle.py +192 -0
  14. tensordev-0.0.1/src/tensordev/core/tensorflow.py +0 -0
  15. tensordev-0.0.1/src/tensordev/core/torch.py +0 -0
  16. tensordev-0.0.1/src/tensordev/core/universal.py +1350 -0
  17. tensordev-0.0.1/src/tensordev/core/utils/__init__.py +13 -0
  18. tensordev-0.0.1/src/tensordev/core/utils/annotations.py +57 -0
  19. tensordev-0.0.1/src/tensordev/core/utils/shuffle_basics.py +155 -0
  20. tensordev-0.0.1/src/tensordev/core/utils/shuffle_precalculation.py +260 -0
  21. tensordev-0.0.1/src/tensordev/development/__init__.py +9 -0
  22. tensordev-0.0.1/src/tensordev/development/free.py +177 -0
  23. tensordev-0.0.1/src/tensordev/development/sig.py +132 -0
  24. tensordev-0.0.1/src/tensordev/kernel/__init__.py +25 -0
  25. tensordev-0.0.1/src/tensordev/kernel/base_kernel.py +364 -0
  26. tensordev-0.0.1/src/tensordev/kernel/free.py +1265 -0
  27. tensordev-0.0.1/src/tensordev/kernel/fssk.py +808 -0
  28. tensordev-0.0.1/src/tensordev/kernel/higher_order.py +209 -0
  29. tensordev-0.0.1/src/tensordev/kernel/parallel.py +241 -0
  30. tensordev-0.0.1/src/tensordev/kernel/sig.py +99 -0
  31. tensordev-0.0.1/src/tensordev/kernel/static_kernels.py +331 -0
  32. tensordev-0.0.1/src/tensordev/sss/__init__.py +16 -0
  33. tensordev-0.0.1/src/tensordev/sss/coeffs.py +113 -0
  34. tensordev-0.0.1/src/tensordev/sss/kernel.py +592 -0
  35. tensordev-0.0.1/src/tensordev/sss/lambdas.py +1715 -0
  36. tensordev-0.0.1/src/tensordev/sss/recursion_general.py +339 -0
  37. tensordev-0.0.1/src/tensordev/sss/recursion_scalar.py +267 -0
  38. tensordev-0.0.1/src/tensordev/sss/rough_approx.py +480 -0
  39. tensordev-0.0.1/src/tensordev/sss/state.py +381 -0
  40. tensordev-0.0.1/src/tensordev/sss/state_update.py +532 -0
  41. tensordev-0.0.1/src/tensordev/util/__init__.py +24 -0
  42. tensordev-0.0.1/src/tensordev/util/combinatorics.py +331 -0
  43. tensordev-0.0.1/src/tensordev/util/path_preprocessing.py +237 -0
  44. tensordev-0.0.1/src/tensordev/util/random_paths.py +501 -0
  45. tensordev-0.0.1/src/tensordev/volterra/__init__.py +25 -0
  46. tensordev-0.0.1/src/tensordev/volterra/coeffs.py +161 -0
  47. tensordev-0.0.1/src/tensordev/volterra/eval_general.py +162 -0
  48. tensordev-0.0.1/src/tensordev/volterra/eval_scalar.py +85 -0
  49. tensordev-0.0.1/src/tensordev/volterra/iteration_fft.py +1048 -0
  50. tensordev-0.0.1/src/tensordev/volterra/iteration_pc.py +212 -0
  51. tensordev-0.0.1/src/tensordev/volterra/iteration_quad.py +528 -0
  52. tensordev-0.0.1/src/tensordev/volterra/kernel.py +783 -0
  53. tensordev-0.0.1/src/tensordev/volterra/signature.py +397 -0
  54. tensordev-0.0.1/src/tensordev.egg-info/PKG-INFO +442 -0
  55. tensordev-0.0.1/src/tensordev.egg-info/SOURCES.txt +56 -0
  56. tensordev-0.0.1/src/tensordev.egg-info/dependency_links.txt +1 -0
  57. tensordev-0.0.1/src/tensordev.egg-info/requires.txt +8 -0
  58. tensordev-0.0.1/src/tensordev.egg-info/top_level.txt +1 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,442 @@
1
+ Metadata-Version: 2.4
2
+ Name: tensordev
3
+ Version: 0.0.1
4
+ Summary: JAX-based tensor algebra for signatures, Volterra signatures, free developments, and signature kernels.
5
+ Author: Paul Hager, Julian Pachschwoell, Luca Pelizzari
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/hagerpa/tensordev
8
+ Project-URL: Repository, https://github.com/hagerpa/tensordev
9
+ Project-URL: Issues, https://github.com/hagerpa/tensordev/issues
10
+ Keywords: signature,rough paths,Volterra signature,tensor algebra,JAX,kernel,machine learning,stochastic processes
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: jax>=0.10.0
23
+ Requires-Dist: jaxlib>=0.10.0
24
+ Requires-Dist: numpy>=1.24
25
+ Requires-Dist: numba>=0.58
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest>=7.0; extra == "test"
28
+ Requires-Dist: jaxtyping>=0.2; extra == "test"
29
+ Dynamic: license-file
30
+
31
+ # tensordev
32
+
33
+ JAX-based tensor algebra library for signatures, free developments, Volterra signatures and inner product-kernels thereof.
34
+
35
+ ## Status
36
+
37
+ `tensordev` is under active development. The core tensor algebra, signature development, state-space kernels, Volterra signatures, and free/higher-order kernels are implemented and tested.
38
+
39
+ The current stable backend is JAX. Multi-backend support for PyTorch, TensorFlow, and Numba is planned, but not yet implemented.
40
+
41
+ The implemented JAX components are end-to-end differentiable — from elementary tensor operations and path signatures through to signature-kernel evaluations and Volterra kernel parameters.
42
+
43
+ ## Requirements
44
+
45
+ `tensordev` currently requires Python 3.10+ and JAX 0.10.0+.
46
+
47
+ The package is developed and tested primarily with the JAX backend.
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install tensordev
53
+ ```
54
+
55
+ For the latest development version:
56
+
57
+ ```bash
58
+ pip install git+https://github.com/hagerpa/tensordev.git
59
+ ```
60
+
61
+ ## License
62
+
63
+ `tensordev` is released under the Apache License 2.0.
64
+ See [`LICENSE`](LICENSE) for details.
65
+
66
+ ## Quick start
67
+
68
+ ```python
69
+ import tensordev as td
70
+ from tensordev.util import random_trigonometric_polynomial_paths
71
+
72
+ X = random_trigonometric_polynomial_paths(batch=4, steps=32, dim=2, key=0)
73
+
74
+ sig = td.path_signature(X, trunc=4)
75
+ ip = td.tensor_inner_product(sig, sig)
76
+
77
+ print(td.tensor_to_flat(sig).shape)
78
+ print(ip.shape)
79
+ ```
80
+
81
+ ## Package structure
82
+
83
+ ```text
84
+ tensordev/
85
+ ├── core/ # Tensor algebra backends
86
+ ├── development/ # Signature development, free and classical
87
+ ├── sss/ # State-space signatures, aka Volterra signatures for finite state-space kernels
88
+ ├── volterra/ # Volterra signatures: fractional, gamma, piecewise-constant kernels
89
+ ├── kernel/ # Signature kernels: classical, free, FSSK, higher-order
90
+ └── util/ # Path generators and combinatorics
91
+ ```
92
+
93
+ ### `tensordev.core` — tensor algebra operations
94
+
95
+ A *core object* exposes all tensor algebra operations over a chosen array backend. The default is `Jax()`. Operations are also available directly on the `tensordev` module:
96
+
97
+ ```python
98
+ # If desired, enable float64 — must be set before importing JAX or tensordev.
99
+ import jax
100
+ jax.config.update("jax_enable_x64", True)
101
+
102
+ import tensordev as td
103
+ import jax.numpy as jnp
104
+
105
+ # two elements of the truncated tensor algebra, levels 0..3
106
+ A = (jnp.ones((1,)), jnp.ones((2,)), jnp.ones((4,)), jnp.ones((8,)))
107
+ B = (jnp.ones((1,)), jnp.ones((2,)), jnp.ones((4,)), jnp.ones((8,)))
108
+
109
+ # Chen/tensor/concatenation product
110
+ C = td.tensor_product(A, B, trunc=3)
111
+
112
+ # level-wise sum
113
+ S = td.tensor_summation(A, B)
114
+
115
+ # truncated exponential and logarithm, inputs start at level 1
116
+ E = td.tensor_exponential(A[1:], trunc=3)
117
+ L = td.tensor_logarithm(A[1:], trunc=3)
118
+
119
+ # inner product
120
+ ip = td.tensor_inner_product(A, B)
121
+ ```
122
+
123
+ For the shuffle, i.e. commutative, product, create a `ShuffleCore` for a fixed base dimension and truncation. All shuffle operators are precomputed at construction time as sparse arrays, so repeated calls are pure compute with no reallocation.
124
+
125
+ ```python
126
+ sc = td.shuffle_core(d=2, trunc=3)
127
+ C = sc.tensor_shuffle_product(A, B, trunc=3)
128
+ ```
129
+
130
+ Use `shuffle_core_expected_memory` to check the memory budget before constructing at large `d` or `trunc`. It returns an upper bound; actual usage is typically 20–40% less.
131
+
132
+ ```python
133
+ td.shuffle_core_expected_memory(d=2, trunc=8) # → 1.63 MB (actual 0.52 MB)
134
+ td.shuffle_core_expected_memory(d=4, trunc=6) # → 5.85 MB (actual 4.07 MB)
135
+ td.shuffle_core_expected_memory(d=4, trunc=8) # → 363.85 MB (actual 218.93 MB)
136
+ td.shuffle_core_expected_memory(d=8, trunc=6) # → 353.44 MB (actual 297.57 MB)
137
+ ```
138
+
139
+ ### `tensordev.development` — signature development
140
+
141
+ Compute truncated signatures with optional blocking. `block_size` splits the path into chunks and chains them via Chen's identity internally. This is useful for long sequences where the full path does not fit in memory at once.
142
+
143
+ ```python
144
+ import numpy as np
145
+ import jax.numpy as jnp
146
+ import tensordev as td
147
+ from tensordev.util import random_trigonometric_polynomial_paths
148
+
149
+ X = random_trigonometric_polynomial_paths(batch=4, steps=32, dim=2, key=0)
150
+
151
+ sig = td.path_signature(X, trunc=4) # one shot
152
+
153
+ # signature on two consecutive intervals
154
+ sig_blocked = td.path_signature(X, trunc=4, block_size=16, accumulate=False)
155
+
156
+ # Chen's identity: sig = sig_a ⊗ sig_b
157
+ sig_a = td.tensor_slice(sig_blocked)[:, 0]
158
+ sig_b = td.tensor_slice(sig_blocked)[:, 1]
159
+ sig_c = td.tensor_product(sig_a, sig_b, trunc=4)
160
+
161
+ np.testing.assert_allclose(
162
+ td.tensor_to_flat(sig),
163
+ td.tensor_to_flat(sig_c),
164
+ atol=1e-12,
165
+ ) # ✓
166
+
167
+ # shuffle identity: <sig, a ⊔ b> = <sig, a> · <sig, b>
168
+ # a, b are fixed basis vectors — broadcast over the batch dimension
169
+ e1 = td.tensor_densify((None, jnp.array([1., 0.])))
170
+ e2 = td.tensor_densify((None, jnp.array([0., 1.])))
171
+ sc = td.shuffle_core(d=2, trunc=4)
172
+
173
+ np.testing.assert_allclose(
174
+ td.tensor_inner_product(sig, sc.tensor_shuffle_product(e1, e2, trunc=4)),
175
+ td.tensor_inner_product(sig, e1) * td.tensor_inner_product(sig, e2),
176
+ atol=1e-10,
177
+ ) # ✓
178
+ ```
179
+
180
+ `free_development` generalises this to tensor-valued paths and adds block-level control. The example below computes per-block signatures and their tensor logarithms — the piecewise log-linear approximation that `HigherOrderKernel` uses internally:
181
+
182
+ ```python
183
+ from tensordev.development import free_development
184
+
185
+ # per-block signatures: (batch=4, n_blocks=4, dim^k) for block_size=8, steps=32
186
+ block_sigs = free_development((X,), trunc=3, block_size=8, accumulate=False)
187
+
188
+ # tensor log of each block signature → log-linear increments
189
+ log_sigs = td.tensor_logarithm(block_sigs[1:], trunc=3, output_zero_level=False)
190
+
191
+ # free development of the piecewise log-linear path
192
+ higher_order_sig = free_development(log_sigs, trunc=3, increment_input=True)
193
+
194
+ # piecewise log-linear sig recovers the original sig at the same truncation
195
+ sig = td.path_signature(X, trunc=3)
196
+
197
+ np.testing.assert_allclose(
198
+ td.tensor_to_flat(sig),
199
+ td.tensor_to_flat(higher_order_sig),
200
+ atol=1e-12,
201
+ ) # ✓
202
+ ```
203
+
204
+ ### `tensordev.sss` — state-space signatures
205
+
206
+ State-space signatures are Volterra signatures whose convolution kernel is a *finite state-space kernel* (FSSK), i.e. a matrix-exponential kernel of the form
207
+
208
+ $$K_{A,b}^\Lambda(t,s) = \sum_{r=1}^q \bigl(\mathbf{1}^\top e^{-\Lambda(t-s)} b_r\bigr) A_r .$$
209
+
210
+ with dense or Jordan state-space operators $\Lambda$. This package provides functionality for propagating and reading out the hidden state that evolves via an ODE, making online/streaming evaluation of such Volterra signatures exact and efficient.
211
+
212
+ ```python
213
+ import jax.numpy as jnp
214
+ from tensordev.sss import StateSpaceSignature
215
+
216
+ # Jordan kernel:
217
+ # one real exponential with rate 1.0
218
+ # plus one oscillatory pair with decay 0.5 and frequency 2π
219
+ # acting on R^2 paths via A = I_2 → state dim R = 1 + 2 = 3
220
+ sss = StateSpaceSignature.from_jordan(
221
+ real_rates=jnp.array([1.0]),
222
+ real_sizes=(1,),
223
+ osc_decays=jnp.array([0.5]),
224
+ osc_freqs=jnp.array([2 * jnp.pi]),
225
+ osc_sizes=(1,),
226
+ A=jnp.eye(2)[None], # (n=1, m=2, d=2)
227
+ b=jnp.ones((1, 3)), # (n=1, R=3)
228
+ trunc=3,
229
+ )
230
+
231
+ result = sss.vsig(X, dt=1.0 / 32)
232
+ ```
233
+
234
+ `StateSpaceSignature` carries an optional persistent hidden state for streaming/online evaluation:
235
+
236
+ ```python
237
+ dt = 1.0 / 32
238
+
239
+ # consume the first half of the path — state is updated, not lost
240
+ sss_mid = sss.update_with_path(X[:, :17], dt=dt)
241
+ vsig_mid = sss_mid.readout() # Volterra signature at t = 0.5
242
+
243
+ # continue with the second half
244
+ sss_end = sss_mid.update_with_path(X[:, 16:], dt=dt)
245
+ vsig_end = sss_end.readout() # Volterra signature at t = 1.0
246
+
247
+ # equivalent to the one-shot call
248
+ np.testing.assert_allclose(
249
+ td.tensor_to_flat(vsig_end),
250
+ td.tensor_to_flat(sss.vsig(X, dt=dt)),
251
+ atol=0,
252
+ ) # ✓
253
+ ```
254
+
255
+ ### `tensordev.volterra` — Volterra signature
256
+
257
+ Volterra signatures for fractional, gamma, and piecewise-constant kernel
258
+ families, computed via the quadratic triangular recursion with JAX-vectorized
259
+ evaluation of the inner loop or, on uniform grids, by FFT acceleration.
260
+
261
+ ```python
262
+ import jax.numpy as jnp
263
+ from tensordev.volterra import ConvolutionKernel, VolterraSignature, vsig
264
+
265
+ A = jnp.eye(2)[None] # (n=1, m=2, d=2)
266
+ dt = 1.0 / 32
267
+
268
+ # functional API — fractional kernel k(t,s) = (t-s)^{β-1} / Γ(β)
269
+ kernel = ConvolutionKernel.fractional(beta=jnp.array([0.8]), A=A)
270
+ result = vsig(X, kernel=kernel, dt=dt, trunc=3)
271
+
272
+ # class-based — Gamma kernel, adding exponential damping to the fractional kernel
273
+ kernel_g = ConvolutionKernel.gamma(
274
+ beta=jnp.array([0.8]),
275
+ rate=jnp.array([1.0]),
276
+ scale=jnp.array([1.0]),
277
+ A=A,
278
+ )
279
+ vsig_obj = VolterraSignature(kernel=kernel_g, trunc=3)
280
+ result = vsig_obj.vsig(X, dt=dt)
281
+ ```
282
+
283
+ Available kernel constructors:
284
+
285
+ | Constructor | Formula | Parameters |
286
+ |---|---|---|
287
+ | `ConvolutionKernel.fractional` | $k_p(t,s) = \Gamma(\beta_p)^{-1}(t-s)^{\beta_p-1}$ | `beta`, `A` |
288
+ | `ConvolutionKernel.gamma` | $k(t,s) = \mathrm{scale}\cdot e^{-\mathrm{rate}(t-s)}\cdot\Gamma(\beta)^{-1}(t-s)^{\beta-1}$ | `beta`, `rate`, `scale`, `A` |
289
+ | `ConvolutionKernel.piecewise_constant` | $k(i,j) = B_{p,i,j}$ | `B`, `A` |
290
+
291
+ Setting `beta=1` with `ConvolutionKernel.fractional` recovers the classical iterated-integral signature.
292
+
293
+ ### `tensordev.kernel` — signature kernels
294
+
295
+ Kernel objects for empirical statistics: batchwise values, Gram matrices, MMD, and scoring rules. All inherit from `BaseKernel`.
296
+
297
+ | Class | Description |
298
+ |---|---|
299
+ | `SigKernel` | Classical signature kernel for Euclidean paths |
300
+ | `FreeKernel` | Free signature kernel for tensor-valued paths |
301
+ | `FSSKSigKernel` | Kernel induced by the FSSK Volterra signature |
302
+ | `HigherOrderKernel` | Higher-order kernel via piecewise log-linear approximation |
303
+ | `LinearKernel`, `RBFKernel`, `RBF_CEXP_Kernel`, `RBF_SQR_Kernel` | Static pointwise kernels used as increment kernels |
304
+
305
+ ```python
306
+ import numpy as np
307
+ from tensordev.util import random_trigonometric_polynomial_paths
308
+ from tensordev.kernel import SigKernel, RBFKernel
309
+
310
+ X = random_trigonometric_polynomial_paths(batch=4, steps=32, dim=2, key=0)
311
+ Y = random_trigonometric_polynomial_paths(batch=4, steps=32, dim=2, key=1)
312
+
313
+ k = SigKernel(dyadic_order=1)
314
+
315
+ vals = k.compute_kernel(X, Y) # (4,) — batchwise k(X_i, Y_i)
316
+ gram = k.compute_Gram(X, Y) # (4, 4) — full cross Gram matrix
317
+ Kxx = k.compute_Gram(X) # (4, 4) — symmetric Y=None shortcut
318
+ mmd = k.compute_mmd(X, Y) # scalar — empirical MMD²
319
+ esr = k.compute_expected_scoring_rule(X, Y) # scalar — E_Y[S(X, y)]
320
+ sr = k.compute_scoring_rule(X, Y[0]) # scalar — S(X, y) for a single y
321
+
322
+ # RBF increment kernel — replaces the default ⟨dx, dy⟩ inner product
323
+ k_rbf = SigKernel(dyadic_order=0, static_kernel=RBFKernel(sigma=1.0))
324
+ gram_rbf = k_rbf.compute_Gram(X, Y) # (4, 4)
325
+ ```
326
+
327
+ `FreeKernel`, `HigherOrderKernel`, and `FSSKSigKernel` share the same empirical API and are drop-in replacements for `SigKernel`:
328
+
329
+ ```python
330
+ from tensordev.kernel import FreeKernel, HigherOrderKernel, FSSKSigKernel
331
+
332
+ # free kernel — accepts tensor-valued paths; level-1 path reduces to SigKernel
333
+ k_free = FreeKernel(dyadic_order=1)
334
+ gram_free = k_free.compute_Gram(X, Y) # (4, 4)
335
+
336
+ # higher-order kernel — log_steps must divide the number of intervals, 32 here
337
+ k_ho = HigherOrderKernel(log_steps=(2, 2), log_degree=(3, 3))
338
+ mmd_ho = k_ho.compute_mmd(X, Y) # scalar
339
+
340
+ # FSSK kernel — wraps the sss.kernel of a StateSpaceSignature
341
+ k_fssk = FSSKSigKernel(kernel=sss.kernel, dt_x=1.0 / 32, dt_y=1.0 / 32)
342
+ mmd_fssk = k_fssk.compute_mmd(X, Y) # scalar
343
+ ```
344
+
345
+ ### `tensordev.util` — utilities
346
+
347
+ ```python
348
+ from tensordev.util import (
349
+ path_to_increments,
350
+ integrated_ou_first_on_path,
351
+ random_trigonometric_polynomial_paths,
352
+ unit_speed_paths,
353
+ perturb_path_batch,
354
+ deterministic_trigonometric_path_pair,
355
+ bucket_pad_ragged_paths,
356
+ velocity_to_increments,
357
+ )
358
+ ```
359
+
360
+ ## Tests
361
+
362
+ ```bash
363
+ pytest tests/
364
+ ```
365
+
366
+ Tests are organized by subpackage:
367
+
368
+ ```text
369
+ tests/core/
370
+ tests/development/
371
+ tests/sss/
372
+ tests/volterra/
373
+ tests/kernel/
374
+ ```
375
+
376
+ ## Backends
377
+
378
+ The core abstraction supports multiple array frameworks. Currently only the JAX backend is fully implemented.
379
+
380
+ | Class | Backend | Status |
381
+ |---|---|---|
382
+ | `Jax` | JAX, JIT-compiled | stable |
383
+ | `JaxSequentialCore` | JAX scan / `lax.associative_scan` | stable |
384
+ | `JaxShuffleCore` | JAX sparse shuffle operators | stable |
385
+ | `Universal` | any array-API namespace | stable |
386
+ | `Einsum` | einsum-based base class | stable |
387
+ | `Numba` | Numba | stub |
388
+ | `Torch` / `TensorFlow` | PyTorch / TensorFlow | stub |
389
+
390
+ The active backend is selected via the `TENSORDEV_BACKEND` environment variable. The default is `"jax"`.
391
+
392
+ ```bash
393
+ TENSORDEV_BACKEND=jax python my_script.py
394
+ ```
395
+
396
+ ```python
397
+ from tensordev._backend import get_default_core, get_default_seq_core
398
+
399
+ core = get_default_core()
400
+ seq_core = get_default_seq_core()
401
+ ```
402
+
403
+ ## Acknowledgements and theoretical background
404
+
405
+ `tensordev` is an independent implementation, but it was influenced by several excellent open-source projects in the signature-computation ecosystem:
406
+
407
+ - [`iisignature`](https://github.com/bottler/iisignature): a gold-standard reference for efficient signature and logsignature computation.
408
+ - [`signatory`](https://github.com/patrick-kidger/signatory): inspired the fused Horner-style evaluation used for efficient tensor exponential / signature development routines.
409
+ - [`signax`](https://github.com/anh-tong/signax): provided the initial motivation for building a JAX-native tensor algebra and signature package.
410
+ - [`pySigLib`](https://github.com/daniil-shmelev/pySigLib): a high-performance CPU/GPU library for signatures and signature kernels, whose CUDA and JAX support provides an important contemporary reference point for accelerator-aware signature computation.
411
+ - [`sigkernel`](https://github.com/crispitagorico/sigkernel): inspired parts of the signature-kernel API and the second-order finite-difference stencil used for the standard signature kernel.
412
+ - [`high-order-sigkernel`](https://github.com/maudl3116/high-order-sigkernel): inspired the predictor-corrector schemes for higher-order signature-kernel PDE systems, which are adapted and further developed in this package.
413
+
414
+ The main theoretical background for the algorithms implemented here is:
415
+
416
+ - J. Reizenstein and B. Graham,
417
+ [*Algorithm 1004: The iisignature Library: Efficient Calculation of Iterated-Integral Signatures and Log Signatures*](https://arxiv.org/abs/1802.08252),
418
+ ACM Transactions on Mathematical Software, 2020.
419
+
420
+ - P. Kidger and T. Lyons,
421
+ [*Signatory: differentiable computations of the signature and logsignature transforms, on both CPU and GPU*](https://arxiv.org/abs/2001.00706),
422
+ ICLR 2021.
423
+
424
+ - C. Salvi, T. Cass, J. Foster, T. Lyons and W. Yang,
425
+ [*The Signature Kernel is the Solution of a Goursat PDE*](https://arxiv.org/abs/2006.14794),
426
+ SIAM Journal on Mathematics of Data Science, 2021.
427
+
428
+ - M. Lemercier, T. Lyons and C. Salvi,
429
+ [*Log-PDE Methods for Rough Signature Kernels*](https://arxiv.org/abs/2404.02926),
430
+ arXiv preprint, 2024.
431
+
432
+ - P. K. Friz and P. P. Hager,
433
+ [*Expected Signature Kernels for Lévy Rough Paths*](https://arxiv.org/abs/2509.07893),
434
+ arXiv preprint, 2025.
435
+
436
+ - P. P. Hager, F. N. Harang, L. Pelizzari and S. Tindel,
437
+ [*The Volterra Signature*](https://arxiv.org/abs/2603.04525),
438
+ arXiv preprint, 2026.
439
+
440
+ - P. P. Hager, F. N. Harang, L. Pelizzari and S. Tindel,
441
+ *Computational Aspects of the Volterra Signature*,
442
+ manuscript.