-3
還有就是DTW包需要DTW像中的R包
dtw(x, y=NULL, dist.method="Euclidean", step.pattern=symmetric2, window.type="none", keep.internals=FALSE, distance.only=FALSE, open.end=FALSE, open.begin=FALSE, ...)
在功能的功能,有計算距離
symmetric1 , symmetric2 , asymmetric
我對所述方法step.pattern = symmetric2
的三種方法。
我有一個C++函數的操作完全相同symmetric1
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double dtw_rcpp(const NumericVector& x, const NumericVector& y) {
size_t n = x.size(), m = y.size();
NumericMatrix res = no_init(n + 1, m + 1);
std::fill(res.begin(), res.end(), R_PosInf);
res(0, 0) = 0;
double cost = 0;
size_t w = std::abs(static_cast<int>(n - m));
for (size_t i = 1; i <= n; ++i) {
for (size_t j = std::max(1, static_cast<int>(i - w)); j <= std::min(m, i + w); ++j) {
cost = std::abs(x[i - 1] - y[j - 1]);
res(i, j) = cost + std::min(std::min(res(i - 1, j), res(i, j - 1)), res(i - 1, j - 1));
}
}
return res(n, m);
}
什麼我需要在這個с改變++,它認爲距離symmetric2
的方法功能。我不明白它是如何工作的symmetric2
。
here據說對其知之甚少
1. Well-known step patterns
These common transition types are used in quite a lot of implementations.
symmetric1 (or White-Neely) is the commonly used quasi-symmetric, no local constraint, non-normalizable. It is biased in favor of oblique steps. symmetric2 is normalizable, symmetric, with no local slope constraints. Since one diagonal step costs as much as the two equivalent steps along the sides, it can be normalized dividing by N+M (query+reference lengths).
在
source code
,我無法理解,因爲我是一個初學編程的
我不會說英語,所以請原諒我的失誤。
謝謝
歡迎來到SO。請參閱[The Tour](http://stackoverflow.com/tour)並閱讀[本幫助頁面](http://stackoverflow.com/help/on-topic)瞭解您可以在此處詢問哪些類型的問題。 – UnholySheep
請編輯你的帖子,並澄清你的意思'dtw'。 –