動態規劃時間規整簡介入門

在日常的生活中我們最經常使用的距離毫無疑問應該是歐式距離,但是對於一些特殊情況,歐氏距離存在着其很明顯的缺陷,比如說時間序列,舉個比較簡單的例子,序列A:1,1,1,10,2,3,序列B:1,1,1,2,10,3,如果用歐氏距離,也就是distance[i][j]=(b[j]-a[i])*(b[j]-a[i])來計算的話,總的距離和應該是128,應該說這個距離是非常大的,而實際上這個序列的圖像是十分相似的,這種情況下就有人開始考慮尋找新的時間序列距離的計算方法,然後提出了DTW算法,這種方法在語音識別,機器學習方便有着很重要的作用。

這個算法是基於動態規劃(DP)的思想,解決了發音長短不一的模板匹配問題,簡單來說,就是通過構建一個鄰接矩陣,尋找最短路徑和

還以上面的2個序列作爲例子,A中的10和B中的2對應以及A中的2和B中的10對應的時候,distance[3]以及distance[4]肯定是非常大的,這就直接導致了最後距離和的膨脹,這種時候,我們需要來調整下時間序列,如果我們讓A中的10和B中的10 對應,A中的1和B中的2對應,那麼最後的距離和就將大大縮短,這種方式可以看做是一種時間扭曲,看到這裏的時候,我相信應該會有人提出來,爲什麼不能使用A中的2與B中的2對應的問題,那樣的話距離和肯定是0了啊,距離應該是最小的吧,但這種情況是不允許的,因爲A中的10是發生在2的前面,而B中的2則發生在10的前面,如果對應方式交叉的話會導致時間上的混亂,不符合因果關係。

接下來,以output[6][6](所有的記錄下標從1開始,開始的時候全部置0)記錄A,B之間的DTW距離,簡單的介紹一下具體的算法,這個算法其實就是一個簡單的DP,狀態轉移公式是output[i][j]=Min(Min(output[i-1][j],output[i][j-1]),output[i-1][j-1])+distance[i][j];最後得到的output[5][5]就是我們所需要的DTW距離.

DTW的C語言實現

#include<iostream>
#include<string.h>
using namespace std;
#define NUM 5 //序列中樣本點的個數簡單起見,假設2個序列的樣本點一樣多
#define Min(a,b) (a<b?a:b)

int main()
{
int i,j,k;
int a[NUM],b[NUM];
int distance[NUM+1][NUM+1];
int output[NUM+1][NUM+1];

memset(distance,0,sizeof(distance));
memset(output,0,sizeof(output));
for(i=0;i<NUM;i++) cin>>a[i];
for(i=0;i<NUM;i++) cin>>b[i];
for(i=1;i<=NUM;i++)
for(j=1;j<=NUM;j++)
distance[i][j]=(b[j-1]-a[i-1])*(b[j-1]-a[i-1]); //計算點與點之間的歐式距離

for(i=1;i<=NUM;i++)
{
for(j=1;j<NUM;j++)
cout<<distance[i][j]<<'\t';
cout<<endl;
} //輸出整個歐式距離的矩陣
cout<<endl;
for(i=1;i<=NUM;i++)
for(j=1;j<NUM;j++)
output[i][j]=Min(Min(output[i-1][j-1],output[i][j-1]),output[i-1][j])+distance[i][j];
//DP過程,計算DTW距離

for(i=0;i<=NUM;i++)
{
for(j=0;j<NUM;j++)
cout<<distance[i][j]<<'\t';
cout<<endl;
} //輸出最後的DTW距離矩陣,其中output[NUM][NUM]爲最終的DTW距離和

return 0;
}

動態時間規整DTW

動態時間規整DTW(dynamic time warping)曾經是語音識別的一種主流方法。
其思想是:由於語音信號是一種具有相當大隨機性的信號,即使相同說話者對相同的詞,每一次發音的結果都是不同的,也不可能具有完全相同的時間長度。因此在與已存儲模型相匹配時,未知單詞的時間軸要不均勻地扭曲或彎折,以使其特徵與模板特徵對正。用時間規整手段對正是一種非常有力的措施,對提高系統的識別精度非常有效。
動態時間規整DTW是一個典型的優化問題,它用滿足一定條件的的時間規整函數W(n)描述輸入模板和參考模板的時間對應關係,求解兩模板匹配時累計距離最小所對應的規整函數。


™將時間規整與距離測度結合起來,採用動態規劃技術,比較兩個大小不同的模式,解決語音識別中語速多變的難題;
™一種非線性時間規整模式匹配算法;


DTW ( Dynamic Time Warping ),即「動態時間扭曲」或是「動態時間規整」。這是一套根基於「動態規劃」(Dynamic Programming,簡稱DP)的方法,可以有效地將搜尋比對的時間大幅降低。
DTW 的目標就是要找出兩個向量之間的最短距離。一般而言,對於兩個 n 維空間中的向量 x 和 y,它們之間的距離可以定義爲兩點之間的直線距離,稱爲尤拉距離(Euclidean Distance)。
dist(x, y) = |x – y| ,
但是如果向量的長度不同,那它們之間的距離,就無法使用上述的數學式來計算。一般而言,假設這兩個向量的元素位置都是代表時間,由於我們必須容忍在時間軸的偏差,因此我們並不知道兩個向量的元素對應關係,因此我們必須靠着一套有效的運算方法,纔可以找到最佳的對應關係。


DTW是用於與說話人有關(Speaker Dependent)的語音識別,使用者自行錄音然後再以自己的聲音來比對之前錄好的語音資料。此方法比較適合同一位說話人的聲音來進行比較,因此應用範圍比較狹隘,譬如目前手機 Name Dialing 等等。


DTW的問題:
™運算量大;
™識別性能過分依賴於端點檢測;
™太依賴於說話人的原來發音;
™不能對樣本作動態訓練;
™沒有充分利用語音信號的時序動態特性;
DTW適合於特定人基元較小的場合,多用於孤立詞識別;


動態規劃算法總體思想
動態規劃算法基本思想是將待求解問題分解成若干個子問題
但是經分解得到的子問題往往不是互相獨立的。不同子問題的數目常常只有多項式量級。求解時,有些子問題被重複計算了許多次。
如果能夠保存已解決的子問題的答案,而在需要時再找出已求得的答案,就可以避免大量重複計算,從而得到多項式時間算法。


動態規劃基本步驟
找出最優解的性質,並刻劃其結構特徵。
遞歸地定義最優值。
以自底向上的方式計算出最優值。
根據計算最優值時得到的信息,構造最優解

一、動態時間規整的提出
  語音信號具有很強的隨機性,不同的發音習慣,發音時所處的環境不同,心情不同都會導致發音持續時間長短不一的現象。如單詞最後的聲音帶上一些拖音,或者帶上一點呼吸音,此時,由於拖音或呼吸音會被誤認爲一個音素,造成單詞的端點檢測不準,造成特徵參數的變化,從而影響測度估計,降低識別率,因此在語音識別時,首先有必要對語音信號進行時間規整。

二、動態時間規整的定義

  一次正確的發音應該包含構成該發音的全部音素以及正確的音素連接次序。其中各音素持續時間的長短與音素本身以及講話人的狀況有關。爲了提高識別率,克服發同一音而發音時間長短的不同,採用對輸入語音信號進行伸長或縮短直到與標準模式的長度一致。這個過程稱爲時間規整。

三、動態時間規整的原理描述

  60年代由日本學者提出,算法的思想是把未知量伸長或縮短(壓擴),直到與參考模板的長度一致,在這一過程中,未知單詞的時間軸會產生扭曲或彎折,以便其特徵量與標準模式對應。

原理描述

  DTW 是把時間規整和距離測度計算結合起來。測試語音參數共有I幀矢量,而參考模板共有J幀矢量,I和J不等,尋找一個時間規整函數j=w(i),它將測試矢量的時間軸i非線性地映射到模板的時間軸j上,並使該函數w(i)滿足:

公式

第i幀測試矢量T(i)和第j幀模板矢量R(j)之間的距離測度D。
  最優時間規整情況下所有矢量幀間的距離,也稱爲代價函數。

公式2

計算兩倒譜矢量幀(i和j) 間的歐氏距離,兩矢量幀中分別具有p個倒譜參數。
  爲了使T(測試)的第i個樣本與R(參考)的第j個樣本對正,其對應的點不在直線對角線上,得到一條彎曲的曲線j=w(i) 。j=w(i)稱爲規整函數。

時間規整的依據

  設 T={a1 , a2 , …… , ai , …… , aI} i=1~I   R={b1 , b2 , …… , bj , …… , bJ} j=1~J   I≠J   時間規整要解決的問題是使元素a和元素b之間匹配,使每對匹配樣本之間的差別最小,達到歐氏距離最小。
Veeraraghavan等人用動態時間規整(dynamic time warping,DTW)來匹配運動序列。DTW是一種時變數據序列匹配方法,常用於微生物學的DNA匹配、字符串和符號的比較以及語音分析[77]。DTW算法的思想是給定參考模板特徵矢量序列與輸入特徵矢量序列,尋找一個最佳的時間規整函數,使得輸入序列的時間軸映射到參考模板的時間軸上總的累計失真最小。對DTW而言,即使測試序列模式與參考序列模式的時間尺度不能完全一致,只要時間次序約束存在,它仍能較好地完成測試序列與參考序列之間的模式匹配。DTW具有概念簡單、算法魯棒的優點,能夠對圖像序列進行分類。文獻[35]在形狀空間中用動態時間規整方法計算兩個形狀序列之間的距離來識別動作和步態,取得了很好的分類結果。然而,DTW算法計算量較大,缺乏考慮相鄰時序之間的動態特性,而在實際中,運動序列中相鄰序列在時間和空間上有高度的相關性。
1) dynamic time war ping (DTW) 
動態時軸彎曲或動態時間規正(DTW)
2) DTW 
動態時間規整(DTW)
3) dynamic time warping 
動態時間彎曲
1.Time series similar pattern matching based on wavelet and dynamic time warping; 
基於小波和動態時間彎曲的時間序列相似匹配
2.Similarity matching algorithm for interval-valued time series based on dynamic time warping;
基於動態時間彎曲的區間值時間序列匹配算法
3.Through dynamic time warping analysis to the hot-fire test data and simulated fault data of a certain liquid rocket engine,the warped path sets were obtained.
對某大型液體火箭發動機的熱試車數據及通過發動機模型仿真得到的故障數據進行動態時間彎曲分析,得到彎曲路徑集,然後結合決策樹方法進行了故障檢測和診斷。
更多例句>>
4) Dynamic Time Warping(DTW) 
動態時間彎曲
1.An efficient lower bounding technique is proposed based on Dynamic Time Warping(DTW) for time series similarity search,which measures the distance between original sequence reduced dimensionality by Piecewise Aggregate Approximation(PAA) approximation method and query sequence reduced dimensionality by Grid Minimum Bounding Rectangle(GMBR) representation approach.
針對時間序列數據,提出一種新的基於動態時間彎曲的下界技術,該技術首先基於分段聚集近似的線性表示對原始序列進行降維,同時生成查詢序列的網格最小邊界矩形近似表示,然後利用基於動態時間彎曲距離對兩者下界距離度量。
更多例句>>
5) dynamic time alignment 
時間動態規正
6) dynamic time warping 
動態時間規正
1.Gait contour by using Fourier descriptors was described,to make quasi-periodic analysis on height and width ratio of gait image,and to solve the problems resulting from image sequence of different gait cycle by using dynamic time warping.
利用傅立葉描繪子對步態輪廓圖像進行描述,用步態圖像的高寬比進行步態的準週期性分析,並採用動態時間規正算法解決不同的步態週期的圖像序列之間的比較問題。
2.In the system, RelAtive SepeTrAl(RASTA) filter was used to reduce the convolution channel noise mixed in speech signal, and the improved dynamic time warping (DTW) algorithm was adopted for recognizing speech command.
該系統採用RASTA濾波方法去除語音信號中夾雜的卷積信道噪聲,採用改進的動態時間規正(DTW)算法對語音命令進行識別。
DTW(Dynamic Time Warping,動態時間歸整)算法,該算法基於動態規劃(DP)的思想,解決了發音長短不一的模板匹配問題,是語音識別中出現較早、較爲經典的一種算法。用於孤立詞識別,DTW算法與HMM算法在訓練階段需要提供大量的語音數據,通過反覆計算才能得到模型參數,而DTW算法的訓練中幾乎不需要額外的計算。所以在孤立詞語音識別中,DTW算法仍然得到廣泛的應用。
機羣系統上並行計算時間序列的動態彎曲距離
莫倩芸  鍾誠 
時間序列的相似性度量是衡量兩個序列相似性的依據.動態時間彎曲距離計算方法具有較強的健壯性且可以度量不同長度的時間序列間的相似性,但其十分耗時.採用波前式推進方法並行計算動態時間彎曲距離並以流水線並行方式傳送局部子結果,提出一個在機羣系統上實現的度量兩個時間序列相似性的並行算法.PC機羣系統上的實驗結果表明,該並行算法高效,獲得了良好的加速和可擴展性.
關鍵詞:時間序列;動態時間彎曲;並行計算;機羣系統
基於分段線性動態時間彎曲的時間序列聚類算法研究
翁穎鈞 朱仲英 
時間序列是一類重要的複雜類型數據 ,時間序列知識發現正成爲知識發現的研究熱點之一。歐幾里德距離及其擴展作爲相似測度被廣泛應用於時間序列的比較中 ,但是這種距離測度對數據沒有好的魯棒性。動態時間彎曲技術是基於非線性動態編程的一種模式匹配算法 ,但是其計算複雜性相當高。本文提出了基於時間序列分段線性表示的動態時間彎曲算法 ,通過計算線性分段序列數據之間的最短彎曲路徑來獲得序列的匹配。對綜合控制時間序列數據進行基於不同距離測度的聚類分析對比結果表明本文提出的算法有很高的精度和對振幅差異、嘈聲和線性漂移有強的魯棒性 ,大大降低計算複雜性 ,具有良好的應用價值
1) Segmented Dynamic Time Warping Distance 
分段動態彎曲距離
1.After finding similar segmented subsequence by Segmented Dynamic Time Warping Distance,this method then search this subsequence point by point,by which the subsequence is acquired accurately.
該算法首先通過中線距離閾值和極值點兩個約束條件分段線性擬合時間序列,利用分段動態彎曲距離度量獲得相似的分段子序列,逐點檢索該子序列實現序列的精確查詢。
2) Time Warping Distance 
動態彎曲距離
3) segmented time warping distance 
分段時間彎曲距離
4) Dynamic Time Warping distance 
動態時間彎曲距離
5) range curvature distortion 
距離彎曲
1.In this dissertation, the presence of range curvature distortion in conventional PFA is analyzed from data format perspective.
本文對聚束模式經典算法極座標格式算法(Polar Format Algorithm, PFA)進行討論,從信號格式角度分析了PFA中距離彎曲對高分辨率成像區域大小的限制,並給出補償距離彎曲的一般方法,但距離彎曲的空變性使得補償複雜且運算量大。
更多例句>>
6) range curvature distinction 
距離彎曲差
1.Effect caused by range curvature distinction for deception jamming under SAR imaging
距離彎曲差對SAR欺騙干擾成像的影響
機羣系統上並行計算時間序列的動態彎曲距離http://wenku.baidu.com/view/c40dabba1a37f111f1855b60.html

Dynamic time warping

Not to be confused with the Time Warp mechanism for discrete event simulation, or the Time Warp Operating System that used this mechanism.

Dynamic time warping (DTW) is an algorithm for measuring similarity between two sequences which may vary in time or speed. For instance, similarities in walking patterns would be detected, even if in one video the person was walking slowly and if in another he or she were walking more quickly, or even if there were accelerations and decelerations during the course of one observation. DTW has been applied to video, audio, and graphics — indeed, any data which can be turned into a linear representation can be analyzed with DTW. A well known application has been automatic speech recognition, to cope with different speaking speeds.

In general, DTW is a method that allows a computer to find an optimal match between two given sequences (e.g.time series) with certain restrictions. The sequences are "warped" non-linearly in the time dimension to determine a measure of their similarity independent of certain non-linear variations in the time dimension. This sequence alignment method is often used in the context of hidden Markov models.

One example of the restrictions imposed on the matching of the sequences is on the monotonicity of the mapping in the time dimension. Continuity is less important in DTW than in other pattern matching algorithms; DTW is an algorithm particularly suited to matching sequences with missing information, provided there are long enough segments for matching to occur.

The extension of the problem for two-dimensional "series" like images (planar warping) is NP-complete, while the problem for one-dimensional signals like time series can be solved in polynomial time.

Example of one of the many forms of the algorithm

This example illustrates the implementation of dynamic time warping when the two sequences are strings of discrete symbols. d(x, y) is a distance between symbols, i.e. d(x, y) = | x - y |.

int DTWDistance(char s[1..n], char t[1..m]) { declare int DTW[0..n, 0..m] declare int i, j, cost for i := 1 to m DTW[0, i] := infinity for i := 1 to n DTW[i, 0] := infinity DTW[0, 0] := 0 for i := 1 to n for j := 1 to m cost:= d(s[i], t[j]) DTW[i, j] := cost + minimum(DTW[i-1, j ], // insertion DTW[i , j-1], // deletion DTW[i-1, j-1]) // match return DTW[n, m] }  

We sometimes want to add a locality constraint. That is, we require that if s[i] is matched with t[j], then | i - j| is no larger than w, a window parameter.

We can easily modify the above algorithm to add a locality constraint (differences marked in bold italic). However, the above given modification works only if |n - m| is no larger than w, i.e. the end point is within the window length from diagonal. In order to make the algorithm work, the window parameter w must be adapted so that |n - m ≤ w| (see the line marked with (*) in the code).

int DTWDistance(char s[1..n], char t[1..m], int w) { declare int DTW[0..n, 0..m] declare int i, j, cost w := max(w, abs(n-m)) // adapt window size (*) for i := 0 to n for j:= 0 to m DTW[i, j] := infinity DTW[0, 0] := 0 for i := 1 to n for j := max(1, i-w) to min(m, i+w) cost := d(s[i], t[j]) DTW[i, j] := cost + minimum(DTW[i-1, j ], // insertion DTW[i , j-1], // deletion DTW[i-1, j-1]) // match return DTW[n, m] }  

Open Source software

  • The lbimproved C++ library implements Fast Nearest-Neighbor Retrieval algorithms under the Dynamic Time Warping (GPL). It also provides a C++ implementation of Dynamic Time Warping as well as various lower bounds.
  • The R package dtw implements most known variants of the DTW algorithm family, including a variety of recursion rules (also called step patterns), constraints, and substring matching.
  • The mlpy Python library implements DTW.

References

  • Sakoe, H. and Chiba, S., Dynamic programming algorithm optimization for spoken word recognition, IEEE Transactions on Acoustics, Speech and Signal Processing, 26(1) pp. 43- 49, 1978, ISSN: 0096-3518
  • C. S. Myers and L. R. Rabiner. A comparative study of several dynamic time-warping algorithms for connected word recognition. The Bell System Technical Journal, 60(7):1389-1409, September 1981.
  • L. R. Rabiner and B. Juang. Fundamentals of speech recognition. Prentice-Hall, Inc., 1993 (Chapter 4)

See also

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章