signature_sparse¶
Compute sparse path signature for paths with repeated points.
Uses Chen's identity to combine segment signatures, skipping zero increments (repeated points). For a path with M knots, computes the signature as the ordered tensor product of M-1 segment exponentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Tensor
|
Tensor of shape |
required |
depth
|
int
|
Maximum depth L for truncation (>=1). |
required |
eps
|
float
|
Threshold for change detection. Default is 0.0. |
0.0
|
lengths
|
Tensor
|
Tensor of shape Best practice (recommended): pad by repeating the last valid point
of each path (see
If you instead pad with zeros/any other values, you must pass Default is None. |
None
|
return_levels
|
bool
|
If True, return list of level tensors. If False, return flattened signature. Default is False. |
False
|
stream
|
bool
|
If True, return signatures at each step along the path. If False, return only the final signature. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Tensor or list[Tensor]
|
If If |
Examples:
>>> import torch
>>> from tensorsig.classical.sparse import signature_sparse
>>>
>>> # Path with repeats
>>> path = torch.tensor([
... [[0.0, 0.0], [0.0, 0.0], [1.0, 1.0], [1.0, 1.0], [2.0, 0.0]]
... ])
>>> sig = signature_sparse(path, depth=2)
>>> sig.shape
torch.Size([1, 6])
>>> stream_sig = signature_sparse(path, depth=2, stream=True)
>>> stream_sig.shape
torch.Size([1, 4, 6])
Source code in src/tensorsig/classical/sparse_signature.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |