Computes the least cost matrix from a distance matrix. Considers diagonals during computation of least-costs. In case of ties, diagonals are favored.
See also
Other Rcpp_cost_path:
cost_path_cpp()
,
cost_path_diagonal_itakura_cpp()
,
cost_path_orthogonal_cpp()
,
cost_path_orthogonal_itakura_cpp()
,
cost_path_slotting_cpp()
,
cost_path_sum_cpp()
,
cost_path_trim_cpp()
Examples
#simulate two time series
x <- zoo_simulate(seed = 1)
y <- zoo_simulate(seed = 2)
#distance matrix
dist_matrix <- distance_matrix_cpp(
x = x,
y = y,
distance = "euclidean"
)
#least cost matrix
cost_matrix <- cost_matrix_orthogonal_cpp(
dist_matrix = dist_matrix
)
#least cost path
cost_path <- cost_path_diagonal_cpp(
dist_matrix = dist_matrix,
cost_matrix = cost_matrix
)
cost_path
#> x y dist cost
#> 1 100 100 0.6934760 66.9232470
#> 2 99 99 0.7648549 65.0343113
#> 3 98 98 0.6320462 63.5887700
#> 4 97 97 0.6777913 62.5184229
#> 5 96 96 0.6215667 61.2049937
#> 6 95 95 0.5904734 60.0198369
#> 7 94 94 0.5674837 58.8738118
#> 8 93 93 0.5636236 57.9576445
#> 9 92 92 0.5285802 56.9145449
#> 10 91 92 0.5443292 56.3859647
#> 11 90 92 0.4135332 55.8416355
#> 12 89 92 0.5039765 55.4281023
#> 13 88 92 0.5108834 54.9241258
#> 14 87 92 0.5230073 54.4132424
#> 15 86 91 0.5478903 53.8710065
#> 16 85 90 0.5387814 52.8671347
#> 17 84 89 0.6283737 51.9734536
#> 18 83 88 0.5491395 50.7950872
#> 19 82 87 0.5427198 50.1626329
#> 20 81 86 0.4458249 49.5607198
#> 21 80 86 0.4561570 49.1148949
#> 22 79 86 0.6058592 48.6587378
#> 23 78 85 0.5548788 48.0424610
#> 24 77 85 0.5108495 47.4875822
#> 25 76 84 0.5278081 46.9328961
#> 26 75 83 0.2749964 46.1840836
#> 27 74 82 0.3362982 45.8501683
#> 28 73 82 0.2755243 45.5138701
#> 29 72 82 0.2580913 45.2383457
#> 30 71 82 0.2466212 44.9802545
#> 31 70 82 0.2101682 44.7336333
#> 32 69 82 0.2373155 44.5234652
#> 33 68 82 0.2261700 44.2861497
#> 34 67 82 0.2031087 44.0599797
#> 35 66 82 0.1502621 43.8568710
#> 36 65 82 0.1305400 43.7066088
#> 37 64 82 0.1506714 43.5760688
#> 38 63 82 0.1762334 43.4253974
#> 39 62 82 0.1629928 43.2491640
#> 40 61 82 0.1612566 43.0861712
#> 41 60 82 0.1526246 42.9249147
#> 42 59 82 0.1434672 42.7722900
#> 43 58 82 0.1726055 42.6288228
#> 44 57 82 0.1296162 42.4562173
#> 45 56 82 0.2352345 42.3266012
#> 46 55 82 0.1600529 42.0913666
#> 47 54 82 0.1674942 41.9313137
#> 48 53 82 0.1540136 41.7638195
#> 49 52 82 0.1344377 41.6098058
#> 50 51 82 0.1418574 41.4753681
#> 51 50 82 0.1646179 41.3335107
#> 52 49 82 0.1936073 41.1688929
#> 53 48 82 0.1593103 40.9752856
#> 54 47 81 0.2380341 40.7828032
#> 55 46 80 0.2603981 40.3623305
#> 56 45 79 0.2337894 39.9922269
#> 57 44 78 0.2522322 39.5952233
#> 58 43 77 0.1743998 39.1583134
#> 59 42 76 0.2114731 38.9504137
#> 60 41 75 0.3089992 38.6840963
#> 61 40 74 0.3313175 38.1237119
#> 62 39 73 0.3631816 37.5619956
#> 63 38 72 0.3045351 36.9818444
#> 64 37 71 0.2396572 36.4507223
#> 65 36 70 0.1722297 36.0914306
#> 66 35 69 0.1440328 35.8244977
#> 67 35 68 0.1674252 35.6804649
#> 68 35 67 0.1786501 35.5130397
#> 69 35 66 0.1855774 35.3343896
#> 70 34 65 0.2061691 35.1081678
#> 71 33 64 0.1756490 34.7420115
#> 72 32 63 0.2995759 34.5006863
#> 73 31 62 0.2687903 33.9213091
#> 74 30 61 0.3267435 33.4793163
#> 75 29 60 0.2318210 32.8600078
#> 76 28 59 0.2170579 32.4780512
#> 77 28 58 0.2000520 32.2609933
#> 78 28 57 0.1736652 32.0609413
#> 79 28 56 0.2224500 31.8872762
#> 80 28 55 0.2671070 31.6648262
#> 81 28 54 0.2832049 31.3977192
#> 82 28 53 0.2639180 31.1145142
#> 83 28 52 0.2259958 30.8505963
#> 84 28 51 0.2121769 30.6246004
#> 85 28 50 0.1981827 30.4124235
#> 86 28 49 0.2011492 30.2142408
#> 87 28 48 0.2321620 30.0130917
#> 88 28 47 0.2843064 29.7809297
#> 89 28 46 0.2752997 29.4966233
#> 90 28 45 0.2724771 29.2213236
#> 91 28 44 0.2632239 28.9488465
#> 92 28 43 0.2831713 28.6856227
#> 93 28 42 0.3172355 28.4024514
#> 94 28 41 0.3024352 28.0852159
#> 95 28 40 0.3443351 27.7827807
#> 96 28 39 0.2905489 27.4384455
#> 97 28 38 0.3372605 27.1478966
#> 98 28 37 0.3560955 26.8106361
#> 99 28 36 0.3602208 26.4545406
#> 100 28 35 0.3714868 26.0943198
#> 101 28 34 0.3744984 25.7228330
#> 102 28 33 0.4085635 25.3483346
#> 103 28 32 0.3766831 24.9397711
#> 104 28 31 0.3424833 24.5630880
#> 105 28 30 0.3805911 24.2206047
#> 106 28 29 0.3524106 23.8400136
#> 107 28 28 0.3770721 23.4876031
#> 108 28 27 0.3917478 23.1105309
#> 109 28 26 0.4113225 22.7187831
#> 110 28 25 0.4055345 22.3074607
#> 111 28 24 0.4614801 21.9019262
#> 112 28 23 0.4232874 21.4404461
#> 113 28 22 0.3757436 21.0171587
#> 114 28 21 0.3505313 20.6414151
#> 115 28 20 0.3495128 20.2908837
#> 116 28 19 0.3387319 19.9413709
#> 117 28 18 0.3872206 19.6026390
#> 118 27 17 0.4057451 19.1673382
#> 119 27 16 0.3575246 18.7615932
#> 120 26 15 0.4855975 18.3344463
#> 121 26 14 0.4861830 17.8488487
#> 122 25 13 0.4680005 17.2726716
#> 123 24 12 0.5080264 16.5225224
#> 124 23 11 0.5276057 15.6622155
#> 125 22 10 0.4691932 14.6882277
#> 126 21 10 0.4937712 14.2190345
#> 127 20 10 0.5184232 13.7252633
#> 128 19 10 0.5520151 13.2068401
#> 129 18 10 0.5284255 12.6548250
#> 130 17 10 0.5819680 12.1263995
#> 131 16 10 0.4882528 11.5444315
#> 132 15 10 0.5451257 11.0561787
#> 133 14 10 0.5789974 10.5110529
#> 134 13 9 0.5616895 9.8869043
#> 135 12 9 0.5379617 9.3252149
#> 136 11 8 0.5804374 8.7376186
#> 137 10 7 0.5918210 8.0269721
#> 138 9 6 0.5530716 7.1489267
#> 139 8 5 0.5931723 6.2663526
#> 140 7 4 0.5099716 5.2771827
#> 141 6 3 0.5493263 4.3870978
#> 142 5 2 0.5387187 3.3114509
#> 143 4 1 0.5374539 2.3329749
#> 144 3 1 0.5176733 1.7955210
#> 145 2 1 0.6144512 1.2778477
#> 146 1 1 0.6633965 0.6633965