2017-01-07 39 views
-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

,我無法理解,因爲我是一個初學編程的

我不會說英語,所以請原諒我的失誤。

謝謝

+0

歡迎來到SO。請參閱[The Tour](http://stackoverflow.com/tour)並閱讀[本幫助頁面](http://stackoverflow.com/help/on-topic)瞭解您可以在此處詢問哪些類型的問題。 – UnholySheep

+0

請編輯你的帖子,並澄清你的意思'dtw'。 –

回答

1

OP是詢問有關R.印刷動態時間規整路線的symmetric2對象應該澄清遞歸規則:

g[i,j] = min(
    g[i-1,j-1] + 2 * d[i ,j ] , 
    g[i ,j-1] +  d[i ,j ] , 
    g[i-1,j ] +  d[i ,j ] , 
) 

g是全球成本矩陣,d當地的距離。我無法評論你的其他代碼。

如果您只需要此特定步驟模式下的距離值,並且沒有其他功能,則代碼可能會大大簡化(請參閱例如維基百科上的僞代碼)。