Computes a least-cost matrix from a distance matrix.
This version differs from cost_path_orthogonal_cpp()
in the way it solves ties.
In the case of a tie, cost_path_orthogonal_cpp()
uses the first neighbor satisfying
the minimum distance condition, while this function selects the neighbor
that changes the axis of movement within the least-cost matrix. This function
is not used anywhere within the package, but was left here for future reference.
See also
Other Rcpp_cost_path:
cost_path_cpp()
,
cost_path_diagonal_cpp()
,
cost_path_diagonal_itakura_cpp()
,
cost_path_orthogonal_cpp()
,
cost_path_orthogonal_itakura_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_slotting_cpp(
dist_matrix = dist_matrix,
cost_matrix = cost_matrix
)
cost_path
#> x y dist cost
#> 1 100 100 0.6934760 66.9232470
#> 2 100 99 0.7161694 65.5663746
#> 3 100 98 0.6821893 64.8502052
#> 4 100 97 0.6874341 64.1680159
#> 5 100 96 0.6409757 63.4805819
#> 6 100 95 0.6222391 62.8396061
#> 7 100 94 0.5760614 62.2173671
#> 8 100 93 0.5696817 61.6413056
#> 9 100 92 0.5130193 61.0716239
#> 10 99 92 0.5365579 60.5586046
#> 11 98 92 0.4842729 60.0220467
#> 12 97 92 0.5063508 59.5377738
#> 13 96 92 0.5065797 59.0314230
#> 14 95 92 0.5285806 58.5248433
#> 15 94 92 0.5537613 57.9962626
#> 16 93 92 0.5279564 57.4425013
#> 17 92 92 0.5285802 56.9145449
#> 18 91 92 0.5443292 56.3859647
#> 19 90 92 0.4135332 55.8416355
#> 20 89 92 0.5039765 55.4281023
#> 21 88 92 0.5108834 54.9241258
#> 22 87 92 0.5230073 54.4132424
#> 23 86 92 0.5245394 53.8902351
#> 24 85 92 0.5034589 53.3656958
#> 25 84 92 0.5519456 52.8622369
#> 26 83 92 0.5296750 52.3102913
#> 27 82 92 0.5044439 51.7806162
#> 28 81 92 0.4569037 51.2761724
#> 29 80 92 0.4553854 50.8192686
#> 30 79 92 0.5364900 50.3638833
#> 31 78 92 0.4961084 49.8273933
#> 32 77 92 0.4352922 49.3312849
#> 33 76 92 0.4666304 48.8959928
#> 34 75 92 0.4616177 48.4293624
#> 35 74 92 0.3890522 47.9677447
#> 36 74 91 0.3405644 47.5786924
#> 37 74 90 0.3108773 47.2381280
#> 38 74 89 0.2788660 46.9272508
#> 39 74 88 0.2210212 46.6483848
#> 40 74 87 0.2117861 46.4273636
#> 41 73 87 0.1793031 46.2155775
#> 42 72 87 0.1897519 46.0362744
#> 43 71 87 0.1806690 45.8465225
#> 44 70 87 0.1951448 45.6658535
#> 45 70 86 0.1922087 45.4707087
#> 46 70 85 0.2126529 45.2785000
#> 47 70 84 0.2013065 45.0658471
#> 48 69 84 0.2369120 44.8645406
#> 49 68 84 0.2388685 44.6276286
#> 50 67 84 0.2120945 44.3887601
#> 51 66 84 0.1740653 44.1766656
#> 52 65 84 0.1460344 44.0026003
#> 53 64 84 0.1752535 43.8565659
#> 54 63 84 0.1988074 43.6813124
#> 55 62 84 0.1804145 43.4825050
#> 56 61 84 0.1764448 43.3020905
#> 57 60 84 0.1534586 43.1256457
#> 58 59 84 0.1526458 42.9721871
#> 59 58 84 0.1617319 42.8195412
#> 60 57 84 0.1282278 42.6578093
#> 61 56 84 0.2262139 42.5295815
#> 62 55 84 0.1591592 42.3033677
#> 63 54 84 0.1537377 42.1442085
#> 64 53 84 0.1346854 41.9904708
#> 65 52 84 0.1251040 41.8557854
#> 66 52 83 0.1411702 41.7306814
#> 67 51 83 0.1141431 41.5895112
#> 68 51 82 0.1418574 41.4753681
#> 69 50 82 0.1646179 41.3335107
#> 70 49 82 0.1936073 41.1688929
#> 71 48 82 0.1593103 40.9752856
#> 72 47 82 0.1801237 40.8159754
#> 73 46 82 0.1858304 40.6358517
#> 74 45 82 0.2078866 40.4500213
#> 75 44 82 0.2071551 40.2421347
#> 76 43 82 0.1588663 40.0349796
#> 77 43 81 0.1782292 39.8761133
#> 78 43 80 0.1676922 39.6978841
#> 79 43 79 0.1872008 39.5301919
#> 80 43 78 0.1846777 39.3429910
#> 81 43 77 0.1743998 39.1583134
#> 82 43 76 0.1675317 38.9839135
#> 83 43 75 0.2037025 38.8163818
#> 84 43 74 0.2177045 38.6126793
#> 85 43 73 0.2479942 38.3949749
#> 86 43 72 0.2327807 38.1469807
#> 87 42 72 0.2238950 37.9142000
#> 88 41 72 0.2529557 37.6903050
#> 89 40 72 0.2385352 37.4373493
#> 90 39 72 0.2314280 37.1988140
#> 91 39 71 0.2857965 36.9673861
#> 92 39 70 0.2457342 36.6815896
#> 93 38 70 0.2247903 36.4358554
#> 94 37 70 0.1502859 36.2110651
#> 95 37 69 0.1795865 36.0607792
#> 96 37 68 0.1642340 35.8811927
#> 97 37 67 0.1741271 35.7169587
#> 98 37 66 0.1624438 35.5428316
#> 99 37 65 0.1691243 35.3803878
#> 100 36 65 0.1518868 35.2112635
#> 101 36 64 0.1357962 35.0593767
#> 102 36 63 0.1166018 34.9235804
#> 103 36 62 0.1149776 34.8069786
#> 104 36 61 0.1339489 34.6920010
#> 105 35 61 0.1574512 34.5580521
#> 106 34 61 0.2326869 34.4006009
#> 107 33 61 0.2148496 34.1679141
#> 108 32 61 0.3005456 33.9530645
#> 109 31 61 0.2575778 33.6525189
#> 110 31 60 0.2423684 33.3949411
#> 111 30 60 0.2925649 33.1525727
#> 112 29 60 0.2318210 32.8600078
#> 113 29 59 0.2251552 32.6281867
#> 114 29 58 0.2169255 32.4030315
#> 115 29 57 0.1831173 32.1861061
#> 116 29 56 0.2093290 32.0029887
#> 117 29 55 0.2522001 31.7936598
#> 118 29 54 0.2679934 31.5414597
#> 119 29 53 0.2475634 31.2734662
#> 120 29 52 0.2070829 31.0259028
#> 121 29 51 0.2090501 30.8188199
#> 122 29 50 0.1973464 30.6097699
#> 123 28 50 0.1981827 30.4124235
#> 124 28 49 0.2011492 30.2142408
#> 125 28 48 0.2321620 30.0130917
#> 126 28 47 0.2843064 29.7809297
#> 127 28 46 0.2752997 29.4966233
#> 128 28 45 0.2724771 29.2213236
#> 129 28 44 0.2632239 28.9488465
#> 130 28 43 0.2831713 28.6856227
#> 131 28 42 0.3172355 28.4024514
#> 132 28 41 0.3024352 28.0852159
#> 133 28 40 0.3443351 27.7827807
#> 134 28 39 0.2905489 27.4384455
#> 135 28 38 0.3372605 27.1478966
#> 136 28 37 0.3560955 26.8106361
#> 137 28 36 0.3602208 26.4545406
#> 138 28 35 0.3714868 26.0943198
#> 139 28 34 0.3744984 25.7228330
#> 140 28 33 0.4085635 25.3483346
#> 141 28 32 0.3766831 24.9397711
#> 142 28 31 0.3424833 24.5630880
#> 143 28 30 0.3805911 24.2206047
#> 144 28 29 0.3524106 23.8400136
#> 145 28 28 0.3770721 23.4876031
#> 146 28 27 0.3917478 23.1105309
#> 147 28 26 0.4113225 22.7187831
#> 148 28 25 0.4055345 22.3074607
#> 149 28 24 0.4614801 21.9019262
#> 150 28 23 0.4232874 21.4404461
#> 151 28 22 0.3757436 21.0171587
#> 152 28 21 0.3505313 20.6414151
#> 153 28 20 0.3495128 20.2908837
#> 154 28 19 0.3387319 19.9413709
#> 155 28 18 0.3872206 19.6026390
#> 156 28 17 0.3471985 19.2154184
#> 157 28 16 0.3018819 18.8682199
#> 158 28 15 0.3426634 18.5663380
#> 159 28 14 0.3568688 18.2236746
#> 160 28 13 0.3037264 17.8668058
#> 161 28 12 0.3423200 17.5630794
#> 162 28 11 0.3280436 17.2207594
#> 163 28 10 0.3383397 16.8927157
#> 164 27 10 0.3358649 16.5543760
#> 165 26 10 0.3165562 16.2185111
#> 166 25 10 0.3677074 15.9019548
#> 167 24 10 0.3996376 15.5342474
#> 168 23 10 0.4463821 15.1346098
#> 169 22 10 0.4691932 14.6882277
#> 170 21 10 0.4937712 14.2190345
#> 171 20 10 0.5184232 13.7252633
#> 172 19 10 0.5520151 13.2068401
#> 173 18 10 0.5284255 12.6548250
#> 174 17 10 0.5819680 12.1263995
#> 175 16 10 0.4882528 11.5444315
#> 176 15 10 0.5451257 11.0561787
#> 177 14 10 0.5789974 10.5110529
#> 178 13 10 0.5093922 9.9320556
#> 179 12 10 0.4821676 9.4226633
#> 180 11 10 0.4692307 8.9404957
#> 181 10 10 0.4247215 8.4712650
#> 182 9 10 0.4053145 8.0465435
#> 183 8 10 0.3998707 7.6412291
#> 184 7 10 0.3402029 7.2413584
#> 185 7 9 0.3591259 6.9011555
#> 186 6 9 0.3618647 6.5420296
#> 187 5 9 0.3975981 6.1801649
#> 188 4 9 0.3812121 5.7825668
#> 189 3 9 0.3950188 5.4013548
#> 190 3 8 0.4043094 5.0063360
#> 191 3 7 0.4232290 4.6020265
#> 192 3 6 0.4405291 4.1787976
#> 193 3 5 0.4604920 3.7382684
#> 194 3 4 0.4791459 3.2777764
#> 195 3 3 0.5131015 2.7986305
#> 196 3 2 0.4900080 2.2855290
#> 197 3 1 0.5176733 1.7955210
#> 198 2 1 0.6144512 1.2778477
#> 199 1 1 0.6633965 0.6633965