compress_path¶
Compress a path by removing repeated points.
Extracts sparse increments (non-zero changes) and constructs a compressed path that generates the same signature. This is useful for paths with many repeated points, as the compressed path has fewer segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Tensor
|
Tensor of shape |
required |
eps
|
float
|
Threshold for change detection. If |
0.0
|
lengths
|
Tensor
|
Tensor of shape See Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor, Tensor]
|
A tuple of:
- compressed_path: Tensor of shape |
Examples:
>>> import torch
>>> from tensorsig.classical.sparse import compress_path
>>>
>>> # 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]]
... ])
>>> compressed, knots, counts = compress_path(path)
>>> compressed.shape
torch.Size([1, 3, 2])
>>> knots
tensor([[0, 2, 4]])
>>> counts
tensor([3])