Log Signature
log_signatures_pytorch.log_signature.log_signature(path, depth, stream=False, method='default', mode='words', sparse=False, eps=0.0, lengths=None)
Compute log-signatures for batched paths.
The log-signature is a compressed representation of the signature. Two bases are supported:
mode="words"(default): Signatory-style Lyndon words basis (triangular/gather projection)mode="hall": classic Hall basis
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Tensor
|
Tensor of shape |
required |
depth
|
int
|
Maximum depth to truncate log-signature computation. The output dimension
is |
required |
stream
|
bool
|
If True, computed log-signatures are returned for each step. Default is False. |
False
|
method
|
str
|
Computation method: "default" (signature then log) or "bch_sparse" (sparse Hall-BCH, supported for depth <= 4). For higher depths, "bch_sparse" falls back to the default path automatically. Default is "default". |
'default'
|
mode
|
str
|
Basis for the log-signature coordinates: "words" (default) or "hall".
"words" is only available with |
'words'
|
sparse
|
bool
|
If True, use sparse signature computation for paths with repeated points.
Only applies when |
False
|
eps
|
float
|
Threshold for change detection when using sparse mode. Default is 0.0. |
0.0
|
lengths
|
Tensor
|
Tensor of shape |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
If If |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import torch
>>> from log_signatures_pytorch import log_signature, logsigdim
>>> from log_signatures_pytorch.lyndon_words import logsigdim_words
>>>
>>> # Single path (add batch dimension)
>>> path = torch.tensor([[0.0, 0.0], [1.0, 1.0], [2.0, 0.0]]).unsqueeze(0)
>>> log_sig = log_signature(path, depth=2)
>>> log_sig.shape
torch.Size([1, 3])
>>> logsigdim_words(2, 2)
3
>>>
>>> # Batched paths
>>> batch_paths = torch.tensor([
... [[0.0, 0.0], [1.0, 1.0]],
... [[0.0, 0.0], [2.0, 2.0]],
... ])
>>> log_sig = log_signature(batch_paths, depth=2)
>>> log_sig.shape
torch.Size([2, 3])
>>>
>>> # Streaming log-signatures
>>> log_sig_stream = log_signature(path, depth=2, stream=True)
>>> log_sig_stream.shape
torch.Size([1, 2, 3])
>>>
>>> # Using BCH method (faster for depth <= 4)
>>> log_sig_bch = log_signature(path, depth=2, method="bch_sparse", mode="hall")
>>> log_sig_bch.shape
torch.Size([1, 3])
Source code in src/log_signatures_pytorch/log_signature.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
log_signatures_pytorch.log_signature.signature_to_logsignature(signature, depth, mode='words')
Convert signature to log-signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signature
|
Tensor
|
Signature tensor with arbitrary leading batch/window dimensions and
trailing dimension equal to the flattened signature size
|
required |
depth
|
int
|
Depth of the log-signature. |
required |
mode
|
str
|
Basis for the log-signature coordinates: "words" (default) or "hall". |
'words'
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Log-signature tensor with the same leading shape as |
Source code in src/log_signatures_pytorch/log_signature.py
log_signatures_pytorch.log_signature.windowed_log_signature(path, depth, window_size, hop_size, mode='words')
Sliding-window log-signatures via windowed signatures + projection.
Windows are formed with size=window_size and step=hop_size.
Signatures are obtained using :func:windowed_signature (Chen reuse of
streaming prefixes), then converted to log-signatures and projected to the
requested basis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Tensor
|
Tensor of shape |
required |
depth
|
int
|
Maximum depth to truncate log-signature computation. The output dimension
is |
required |
window_size
|
int
|
Size of the window to use for the signature. |
required |
hop_size
|
int
|
Hop size to use for the signature. |
required |
mode
|
str
|
Basis for the log-signature coordinates: "words" (default) or "hall".
"words" is only available with |
'words'
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |