1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401
r"""
Python wrapper for the Rust DpResult struct
This class wraps the Rust DpResult and provides Python-friendly access
to the distance and optional matrix.
"""
r"""
Get the distance value
"""
r"""
Get the matrix (or None if not computed)
Returns a numpy array if use_full_matrix was True, otherwise None
"""
r"""
String representation
"""
r"""
String representation
"""
r"""
Pickle serialization support using __reduce__
Uses bincode to serialize the entire DpResult::inner as bytes for better performance.
Returns a tuple (callable, args) that pickle can use to reconstruct the object.
"""
r"""
A metric configuration object for distance calculations.
This class encapsulates the distance algorithm, its parameters, and the
underlying point-to-point distance type (e.g., Euclidean or Spherical).
Do not instantiate this class directly. Use the provided static factory
methods instead (e.g., `Metric.sspd()`, `Metric.lcss(...)`).
"""
...
r"""
Symmetric Segment-Path Distance.
"""
r"""
Dynamic Time Warping.
"""
r"""
Hausdorff Distance.
"""
r"""
Discrete Frechet Distance.
"""
r"""
Longest Common Subsequence.
"""
r"""
Edit Distance on Real sequence.
"""
r"""
Edit distance with Real Penalty.
"""
r"""
Edit Distance with Projections.
EDwP is designed for trajectories with inconsistent sampling rates.
Note: EDwP only supports Euclidean distance (not spherical distance).
"""
r"""
Frechet Distance (continuous).
Unlike Discrete Frechet, this considers all continuous points along
the curve segments, providing an exact solution.
Note: Frechet only supports Euclidean distance (not spherical distance).
"""
r"""
Helper function to create DpResult from pickle data
Deserializes the DpResult from bincode-encoded bytes.
"""
r"""
Compute distances between two trajectory collections
This function computes the distances between all pairs of trajectories
from two collections. The result is a full distance matrix (2D array)
with shape (n_a, n_b).
When to Use `cdist` vs `pdist`
- Use `cdist` when:
1. Computing distances between two different trajectory collections
2. Your distance metric is **asymmetric** (distance(A, B) != distance(B, A))
3. You need the full distance matrix for both directions
- Use `pdist` when:
1. Computing distances within a single trajectory collection
2. Your distance metric is **symmetric** (distance(A, B) == distance(B, A))
3. You want to save memory by using the compressed distance matrix format
# Arguments
* `trajectories_a` - First collection of trajectories, where each trajectory is a
2D numpy array or list of [x, y] pairs
* `trajectories_b` - Second collection of trajectories
* `metric` - Metric configuration object (e.g., `Metric.sspd()`, `Metric.lcss(eps=5.0)`)
* `parallel` - Whether to use parallel processing (default: True)
* `show_progress` - Whether to display a progress bar during computation (default: False).
The progress bar is rendered to stderr so it does not interfere with stdout.
# Returns
* `distances` - 2D numpy array with shape (len(trajectories_a), len(trajectories_b))
# Output Format
For `n_a` trajectories in the first collection and `n_b` trajectories in the second,
the result is a 2D array with shape `(n_a, n_b)`. The distance at index `[i, j]`
represents the distance from `trajectories_a[i]` to `trajectories_b[j]`.
# Examples
```python
import traj_dist_rs
import numpy as np
# Create metric configuration
metric = traj_dist_rs.Metric.sspd(type_d="euclidean")
# Using numpy arrays (zero-copy)
trajectories_a = [
np.array([[0.0, 0.0], [1.0, 1.0]]),
np.array([[0.0, 1.0], [1.0, 0.0]])
]
trajectories_b = [
np.array([[0.5, 0.5], [1.5, 1.5]]),
np.array([[0.5, 1.5], [1.5, 0.5]])
]
distances = traj_dist_rs.cdist(trajectories_a, trajectories_b, metric=metric)
print(distances.shape) # (2, 2)
# Using lists (will be copied)
trajectories_a = [
[[0.0, 0.0], [1.0, 1.0]],
[[0.0, 1.0], [1.0, 0.0]]
]
trajectories_b = [
[[0.5, 0.5], [1.5, 1.5]],
[[0.5, 1.5], [1.5, 0.5]]
]
distances = traj_dist_rs.cdist(trajectories_a, trajectories_b, metric=metric)
# Using ERP with gap point parameter
metric_erp = traj_dist_rs.Metric.erp(g=[0.0, 1.0], type_d="euclidean")
distances = traj_dist_rs.cdist(trajectories_a, trajectories_b, metric=metric_erp)
# With progress bar
distances = traj_dist_rs.cdist(trajectories_a, trajectories_b, metric=metric, show_progress=True)
```
"""
r"""
Compute the Discret Frechet distance between two trajectories
The discret Frechet distance is a measure of similarity between two curves
that takes into account the location and ordering of the points along the curves.
# Arguments
* `t1` - First trajectory (list of [longitude, latitude] pairs)
* `t2` - Second trajectory (list of [longitude, latitude] pairs)
* `dist_type` - Distance type: "euclidean" (only Euclidean is supported for Discret Frechet)
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: Discret Frechet distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
result = traj_dist_rs.discret_frechet(t1, t2, "euclidean")
print(result.distance) # Distance value
print(result.matrix) # None
result = traj_dist_rs.discret_frechet(t1, t2, "euclidean", True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the Discret Frechet distance using a precomputed distance matrix
This function allows you to use a precomputed distance matrix instead of computing
distances between trajectory points on the fly.
# Arguments
* `distance_matrix` - A 2D numpy array where `matrix[i][j]` is the distance between
point i of trajectory 1 and point j of trajectory 2
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: Discret Frechet distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
import numpy as np
dist_matrix = np.array([
[1.0, 1.0],
[1.0, 1.0],
])
# Without matrix
result = traj_dist_rs.discret_frechet_with_matrix(dist_matrix)
print(result.distance) # Distance value
print(result.matrix) # None
# With matrix
result = traj_dist_rs.discret_frechet_with_matrix(dist_matrix, use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the DTW (Dynamic Time Warping) distance between two trajectories
# Arguments
* `t1` - First trajectory (list of [longitude, latitude] pairs)
* `t2` - Second trajectory (list of [longitude, latitude] pairs)
* `dist_type` - Distance type: "euclidean" or "spherical"
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: DTW distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
# Without matrix
result = traj_dist_rs.dtw(t1, t2, "euclidean")
print(result.distance) # Distance value
print(result.matrix) # None
# With matrix
result = traj_dist_rs.dtw(t1, t2, "euclidean", True)
print(result.distance) # Distance value
print(result.matrix) # numpy array
```
"""
r"""
Compute the DTW (Dynamic Time Warping) distance using a precomputed distance matrix
This function allows you to use a precomputed distance matrix instead of computing
distances between trajectory points on the fly. This can be useful when:
- You need to compute multiple distance measures on the same trajectory pair
- You want to reuse the same distance matrix across different computations
- You have custom distance calculations that don't fit the standard distance types
# Arguments
* `distance_matrix` - A 2D numpy array where `matrix[i][j]` is the distance between
point i of trajectory 1 and point j of trajectory 2
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: DTW distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
import numpy as np
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
# Precompute distance matrix
dist_matrix = np.array([
[1.0, 1.0], # distance from t1[0] to t2[0], t2[1]
[1.0, 1.0], # distance from t1[1] to t2[0], t2[1]
])
# Without matrix
result = traj_dist_rs.dtw_with_matrix(dist_matrix)
print(result.distance) # Distance value
print(result.matrix) # None
# With matrix
result = traj_dist_rs.dtw_with_matrix(dist_matrix, True)
print(result.distance) # Distance value
print(result.matrix) # numpy array
```
"""
r"""
Compute the EDR (Edit Distance on Real sequence) distance between two trajectories
EDR is a distance measure for trajectories that allows for gaps in the matching.
It uses a threshold `eps` to determine if two points match.
The distance is normalized by the maximum length of the two trajectories.
# Arguments
* `t1` - First trajectory (list of [longitude, latitude] pairs)
* `t2` - Second trajectory (list of [longitude, latitude] pairs)
* `dist_type` - Distance type: "euclidean" or "spherical"
* `eps` - Epsilon threshold for matching points
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: EDR distance as f64 (normalized to [0, 1])
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
result = traj_dist_rs.edr(t1, t2, "euclidean", eps=0.5)
print(result.distance) # Distance value
print(result.matrix) # None
result = traj_dist_rs.edr(t1, t2, "euclidean", eps=0.5, use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the EDR (Edit Distance on Real sequence) distance using a precomputed distance matrix
This function allows you to use a precomputed distance matrix instead of computing
distances between trajectory points on the fly.
# Arguments
* `distance_matrix` - A 2D numpy array where `matrix[i][j]` is the distance between
point i of trajectory 1 and point j of trajectory 2
* `eps` - Epsilon threshold for matching points
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: EDR distance as f64 (normalized to [0, 1])
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
import numpy as np
dist_matrix = np.array([
[1.0, 1.0],
[1.0, 1.0],
])
# Without matrix
result = traj_dist_rs.edr_with_matrix(dist_matrix, eps=0.5)
print(result.distance) # Distance value
print(result.matrix) # None
# With matrix
result = traj_dist_rs.edr_with_matrix(dist_matrix, eps=0.5, use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the EDwP (Edit Distance with Projections) distance between two trajectories
EDwP is designed for trajectories with inconsistent sampling rates. It uses
point-to-segment projections to handle different sampling densities.
# Arguments
* `t1` - First trajectory (list of [x, y] pairs)
* `t2` - Second trajectory (list of [x, y] pairs)
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: EDwP distance as f64
- `matrix`: numpy array of shape (n0, n1) if use_full_matrix=True, else None
# Notes
- EDwP only supports Euclidean distance (not spherical distance)
- Passing "spherical" as distance type will result in an error
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0], [2.0, 2.0]]
t2 = [[0.1, 0.1], [1.1, 1.1], [2.1, 2.1]]
# Without matrix
result = traj_dist_rs.edwp(t1, t2, False)
print(result.distance) # Distance value
print(result.matrix) # None
# With matrix
result = traj_dist_rs.edwp(t1, t2, True)
print(result.distance) # Distance value
print(result.matrix) # numpy array
```
"""
r"""
Compute the ERP (Edit distance with Real Penalty) distance between two trajectories
This is the **traj-dist compatible** implementation that matches the (buggy) implementation
in traj-dist. This version should be used when compatibility with traj-dist is required.
ERP is a distance measure for trajectories that uses a gap point `g` as a penalty
for insertions and deletions. The distance is computed using dynamic programming.
**Note**: This implementation has a bug in the DP matrix initialization where it uses
the total sum of distances to g instead of cumulative sums. This matches the bug in
traj-dist's Python implementation.
# Arguments
* `t1` - First trajectory (list of [longitude, latitude] pairs)
* `t2` - Second trajectory (list of [longitude, latitude] pairs)
* `dist_type` - Distance type: "euclidean" or "spherical"
* `g` - Gap point for penalty (list of [longitude, latitude] or None for centroid)
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: ERP distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
result = traj_dist_rs.erp_compat_traj_dist(t1, t2, "euclidean", g=[0.0, 0.0])
print(result.distance) # Distance value
print(result.matrix) # None
result = traj_dist_rs.erp_compat_traj_dist(t1, t2, "euclidean", g=[0.0, 0.0], use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the ERP (Edit distance with Real Penalty) distance using a precomputed distance matrix
This is the **traj-dist compatible** implementation that matches the (buggy) implementation
in traj-dist. This version should be used when compatibility with traj-dist is required.
This function allows you to use a precomputed distance matrix and extra distance arrays
instead of computing distances on the fly.
# Arguments
* `distance_matrix` - A 2D numpy array where `matrix[i][j]` is the distance between
point i of trajectory 1 and point j of trajectory 2
* `seq0_gap_dists` - A 1D numpy array where `seq0_gap_dists[i]` is the distance between
point i of trajectory 1 and the gap point g
* `seq1_gap_dists` - A 1D numpy array where `seq1_gap_dists[j]` is the distance between
point j of trajectory 2 and the gap point g
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: ERP distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
import numpy as np
dist_matrix = np.array([
[1.0, 1.0],
[1.0, 1.0],
])
seq0_gap_dists = np.array([1.0, 1.0])
seq1_gap_dists = np.array([1.0, 1.0])
# Without matrix
result = traj_dist_rs.erp_compat_traj_dist_with_matrix(dist_matrix, seq0_gap_dists, seq1_gap_dists)
print(result.distance) # Distance value
print(result.matrix) # None
# With matrix
result = traj_dist_rs.erp_compat_traj_dist_with_matrix(dist_matrix, seq0_gap_dists, seq1_gap_dists, use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the ERP (Edit distance with Real Penalty) distance between two trajectories
This is the **standard** ERP implementation with correct cumulative initialization.
This version should be used for new applications where correctness is more important
than compatibility with traj-dist.
ERP is a distance measure for trajectories that uses a gap point `g` as a penalty
for insertions and deletions. The distance is computed using dynamic programming.
**Note**: This implementation correctly accumulates distances by index in the DP matrix
initialization, unlike the buggy implementation in traj-dist.
# Arguments
* `t1` - First trajectory (list of [longitude, latitude] pairs)
* `t2` - Second trajectory (list of [longitude, latitude] pairs)
* `dist_type` - Distance type: "euclidean" or "spherical"
* `g` - Gap point for penalty (list of [longitude, latitude] or None for centroid)
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: ERP distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
result = traj_dist_rs.erp_standard(t1, t2, "euclidean", g=[0.0, 0.0])
print(result.distance) # Distance value
print(result.matrix) # None
result = traj_dist_rs.erp_standard(t1, t2, "euclidean", g=[0.0, 0.0], use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the ERP (Edit distance with Real Penalty) distance using a precomputed distance matrix
This is the **standard** ERP implementation with correct cumulative initialization.
This version should be used for new applications where correctness is more important
than compatibility with traj-dist.
This function allows you to use a precomputed distance matrix and extra distance arrays
instead of computing distances on the fly.
# Arguments
* `distance_matrix` - A 2D numpy array where `matrix[i][j]` is the distance between
point i of trajectory 1 and point j of trajectory 2
* `seq0_gap_dists` - A 1D numpy array where `seq0_gap_dists[i]` is the distance between
point i of trajectory 1 and the gap point g
* `seq1_gap_dists` - A 1D numpy array where `seq1_gap_dists[j]` is the distance between
point j of trajectory 2 and the gap point g
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: ERP distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
import numpy as np
dist_matrix = np.array([
[1.0, 1.0],
[1.0, 1.0],
])
seq0_gap_dists = np.array([1.0, 1.0])
seq1_gap_dists = np.array([1.0, 1.0])
# Without matrix
result = traj_dist_rs.erp_standard_with_matrix(dist_matrix, seq0_gap_dists, seq1_gap_dists)
print(result.distance) # Distance value
print(result.matrix) # None
# With matrix
result = traj_dist_rs.erp_standard_with_matrix(dist_matrix, seq0_gap_dists, seq1_gap_dists, use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the Frechet distance between two trajectories
The Frechet distance considers all continuous points along the curve segments,
providing an exact solution (unlike Discrete Frechet which only considers vertices).
Intuitively, it represents the minimum leash length required for a person
and their dog to walk along the two curves without backtracking.
# Arguments
* `t1` - First trajectory (list of [x, y] pairs or numpy array)
* `t2` - Second trajectory (list of [x, y] pairs or numpy array)
# Returns
* The Frechet distance as a float
# Notes
- Frechet distance only supports Euclidean distance (not spherical distance)
- Trajectories with fewer than 2 points return float('inf')
- Result is always <= the Discrete Frechet distance for the same trajectories
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0], [2.0, 0.0]]
t2 = [[0.0, 0.5], [1.0, 1.5], [2.0, 0.5]]
distance = traj_dist_rs.frechet(t1, t2)
print(f"Frechet distance: {distance}")
```
"""
r"""
Compute the Hausdorff distance between two trajectories
# Arguments
* `t1` - First trajectory (list of [longitude, latitude] pairs)
* `t2` - Second trajectory (list of [longitude, latitude] pairs)
* `dist_type` - Distance type: "euclidean" or "spherical"
# Returns
* Hausdorff distance as f64
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
dist = traj_dist_rs.hausdorff(t1, t2, "euclidean")
```
"""
r"""
Compute the LCSS (Longest Common Subsequence) distance between two trajectories
The LCSS distance is calculated as 1 - (length of longest common subsequence) / min(len(t0), len(t1))
where two points are considered matching if their distance is less than eps.
# Arguments
* `t1` - First trajectory (list of [longitude, latitude] pairs)
* `t2` - Second trajectory (list of [longitude, latitude] pairs)
* `dist_type` - Distance type: "euclidean" or "spherical"
* `eps` - Epsilon threshold for matching points
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: LCSS distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
result = traj_dist_rs.lcss(t1, t2, "euclidean", eps=0.5)
print(result.distance) # Distance value
print(result.matrix) # None
result = traj_dist_rs.lcss(t1, t2, "euclidean", eps=0.5, use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute the LCSS (Longest Common Subsequence) distance using a precomputed distance matrix
This function allows you to use a precomputed distance matrix instead of computing
distances between trajectory points on the fly.
# Arguments
* `distance_matrix` - A 2D numpy array where `matrix[i][j]` is the distance between
point i of trajectory 1 and point j of trajectory 2
* `eps` - Epsilon threshold for matching points
* `use_full_matrix` - If true, compute and return the full DP matrix;
if false (default), return None for the matrix to save space
# Returns
* A `DpResult` object with two properties:
- `distance`: LCSS distance as f64
- `matrix`: numpy array of shape (n0+1, n1+1) if use_full_matrix=True, else None
# Examples
```python
import traj_dist_rs
import numpy as np
dist_matrix = np.array([
[1.0, 1.0],
[1.0, 1.0],
])
# Without matrix
result = traj_dist_rs.lcss_with_matrix(dist_matrix, eps=0.5)
print(result.distance) # Distance value
print(result.matrix) # None
# With matrix
result = traj_dist_rs.lcss_with_matrix(dist_matrix, eps=0.5, use_full_matrix=True)
print(result.matrix) # numpy array
```
"""
r"""
Compute pairwise distances between trajectories
This function computes the distances between all unique pairs of trajectories
in the input list. The result is a compressed distance matrix (1D array)
containing distances for all pairs (i, j) where i < j.
# Symmetry Assumption
This function assumes that the distance metric is **symmetric**, i.e.,
`distance(A, B) == distance(B, A)`. All standard distance algorithms
in traj-dist-rs (SSPD, DTW, Hausdorff, LCSS, EDR, ERP, Discret Frechet)
satisfy this property.
**Important**: If your distance metric is **asymmetric**, use `cdist` instead
to compute the full distance matrix. Using `pdist` with asymmetric distances
will only compute half of the distances and may produce incorrect results.
# Arguments
* `trajectories` - List of trajectories, where each trajectory is a 2D numpy array
or list of [x, y] pairs
* `metric` - Metric configuration object (e.g., `Metric.sspd()`, `Metric.lcss(eps=5.0)`)
* `parallel` - Whether to use parallel processing (default: True)
* `show_progress` - Whether to display a progress bar during computation (default: False).
The progress bar is rendered to stderr so it does not interfere with stdout.
# Returns
* `distances` - 1D numpy array containing distances for all unique pairs
# Output Format
For `n` trajectories, the result is a 1D array of length `n * (n - 1) / 2`.
The distances are ordered as `d(0,1), d(0,2), ..., d(0,n-1), d(1,2), d(1,3), ..., d(n-2,n-1)`.
# Examples
```python
import traj_dist_rs
import numpy as np
# Create metric configuration
metric = traj_dist_rs.Metric.sspd(type_d="euclidean")
# Using numpy arrays (zero-copy)
trajectories = [
np.array([[0.0, 0.0], [1.0, 1.0]]),
np.array([[0.0, 1.0], [1.0, 0.0]]),
np.array([[0.5, 0.5], [1.5, 1.5]])
]
distances = traj_dist_rs.pdist(trajectories, metric=metric)
# Using lists (will be copied)
trajectories = [
[[0.0, 0.0], [1.0, 1.0]],
[[0.0, 1.0], [1.0, 0.0]],
[[0.5, 0.5], [1.5, 1.5]]
]
distances = traj_dist_rs.pdist(trajectories, metric=metric)
# Using LCSS with epsilon parameter
metric_lcss = traj_dist_rs.Metric.lcss(eps=5.0, type_d="euclidean")
distances = traj_dist_rs.pdist(trajectories, metric=metric_lcss)
# With progress bar
distances = traj_dist_rs.pdist(trajectories, metric=metric, show_progress=True)
```
"""
r"""
Compute the SSPD distance between two trajectories
# Arguments
* `t1` - First trajectory (list of [longitude, latitude] pairs)
* `t2` - Second trajectory (list of [longitude, latitude] pairs)
* `dist_type` - Distance type: "euclidean" or "spherical"
# Returns
* SSPD distance as f64
# Examples
```python
import traj_dist_rs
t1 = [[0.0, 0.0], [1.0, 1.0]]
t2 = [[0.0, 1.0], [1.0, 0.0]]
dist = traj_dist_rs.sspd(t1, t2, "euclidean")
```
"""