Dynamic Time Warping
lineagetree.measure
¶
Functions:
| Name | Description |
|---|---|
calculate_dtw |
Calculate DTW distance between two chains |
calculate_dtw
¶
calculate_dtw(
lT: LineageTree,
nodes1: int,
nodes2: int,
threshold: int = 1000,
regist: bool = True,
start_d: int = 0,
back_d: int = 0,
fast: bool = False,
w: int = 0,
centered_band: bool = True,
cost_mat_p: bool = False,
) -> (
tuple[float, tuple, np.ndarray, np.ndarray, np.ndarray]
| tuple[float, tuple]
)
Calculate DTW distance between two chains
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
node to compare distance |
required |
|
int
|
node to compare distance |
required |
|
int
|
set a maximum number of points a chain can have |
1000
|
|
bool
|
Rotate and translate trajectories |
True
|
|
int
|
start delay |
0
|
|
int
|
end delay |
0
|
|
bool
|
if |
False
|
|
int
|
window size |
0
|
|
bool
|
when running the fast algorithm, |
True
|
|
bool
|
True if print the not normalized cost matrix |
False
|
Returns:
| Type | Description |
|---|---|
float
|
DTW distance |
tuple of tuples
|
Aligment path |
matrix
|
Cost matrix |
list of lists
|
rotated and translated trajectories positions |
list of lists
|
rotated and translated trajectories positions |
Source code in src/lineagetree/measure/dynamic_time_warping.py
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 | |
lineagetree.plot
¶
Functions:
| Name | Description |
|---|---|
plot_dtw_heatmap |
Plot DTW cost matrix between two chains in heatmap format |
plot_dtw_trajectory |
Plots DTW trajectories aligment between two chains in 2D or 3D |
plot_dtw_heatmap
¶
plot_dtw_heatmap(
lT: LineageTree,
nodes1: int,
nodes2: int,
threshold: int = 1000,
regist: bool = True,
start_d: int = 0,
back_d: int = 0,
fast: bool = False,
w: int = 0,
centered_band: bool = True,
) -> tuple[float, plt.Figure]
Plot DTW cost matrix between two chains in heatmap format
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
node to compare distance |
required |
|
int
|
node to compare distance |
required |
|
int
|
set a maximum number of points a chain can have |
1000
|
|
bool
|
Rotate and translate trajectories |
True
|
|
int
|
start delay |
0
|
|
int
|
end delay |
0
|
|
bool
|
if |
False
|
|
int
|
window size |
0
|
|
bool
|
when running the fast algorithm, |
True
|
Returns:
| Type | Description |
|---|---|
float
|
DTW distance |
Figure
|
Heatmap of cost matrix with opitimal path |
Source code in src/lineagetree/plot.py
plot_dtw_trajectory
¶
plot_dtw_trajectory(
lT: LineageTree,
nodes1: int,
nodes2: int,
threshold: int = 1000,
regist: bool = True,
start_d: int = 0,
back_d: int = 0,
fast: bool = False,
w: int = 0,
centered_band: bool = True,
projection: Literal[
"3d", "xy", "xz", "yz", "pca", None
] = None,
alig: bool = False,
) -> tuple[float, plt.Figure]
Plots DTW trajectories aligment between two chains in 2D or 3D
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
LineageTree
|
The LineageTree instance. |
required |
|
int
|
node to compare distance |
required |
|
int
|
node to compare distance |
required |
|
int
|
set a maximum number of points a chain can have |
1000
|
|
bool
|
Rotate and translate trajectories |
True
|
|
int
|
start delay |
0
|
|
int
|
end delay |
0
|
|
int
|
window size |
0
|
|
bool
|
True if the user wants to run the fast algorithm with window restrains |
False
|
|
bool
|
if running the fast algorithm, True if the windown is centered |
True
|
|
('3d', 'xy', 'xz', 'yz', 'pca')
|
specify which 2D to plot -> "3d" : for the 3d visualization "xy" or None (default) : 2D projection of axis x and y "xz" : 2D projection of axis x and z "yz" : 2D projection of axis y and z "pca" : PCA projection |
"3d"
|
|
bool
|
True to show alignment on plot |
False
|
Returns:
| Type | Description |
|---|---|
float
|
DTW distance |
figure
|
Trajectories Plot |
Source code in src/lineagetree/plot.py
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 | |