2017-01-07 9 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に興味の3つの方法があります。

私はそれが距離symmetric2の方法を検討し、このс++機能で変更する必要があります正確には何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); 
} 

のように動作しますC++の機能を持っています。

どのように動作するのですか。symmetric2。それはそれsource code

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). 

についてほとんど言われ

here、私は初心者プログラマ

ですので、私はとても英語を話すの過ちのために私を許していない理解できませんでした。

+0

ようこそ。 [こちらのツアー](http://stackoverflow.com/tour)にアクセスし、[このヘルプページ](http://stackoverflow.com/help/on-topic)を読んで、ここでどのような質問をすることができるかを理解してください。 – UnholySheep

+0

投稿を編集して、「dtw」の意味を明確にしてください。 –

答えて

1

OPはsymmetric2オブジェクトが再帰ルールを明確にすべきR.印刷でアラインメントをワープ動的時間について尋ねているあなたに感謝:

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地元の距離です。残りのコードについてはコメントできません。

この特定のステップパターンで距離値が必要なだけで、他の機能はない場合は、コードを大幅に簡略化できます(たとえば、Wikipediaの擬似コードを参照してください)。