动态规划时间规整简介入门
这个算法是基于动态规划(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适合于特定人基元较小的场合,多用于孤立词识别;
动态规划算法总体思想
动态规划算法基本思想是将待求解问题分解成若干个子问题
但是经分解得到的子问题往往不是互相独立的。不同子问题的数目常常只有多项式量级。求解时,有些子问题被重复计算了许多次。
如果能够保存已解决的子问题的答案,而在需要时再找出已求得的答案,就可以避免大量重复计算,从而得到多项式时间算法。
动态规划基本步骤
找出最优解的性质,并刻划其结构特征。
递归地定义最优值。
以自底向上的方式计算出最优值。
根据计算最优值时得到的信息,构造最优解
语音信号具有很强的随机性,不同的发音习惯,发音时所处的环境不同,心情不同都会导致发音持续时间长短不一的现象。如单词最后的声音带上一些拖音,或者带上一点呼吸音,此时,由于拖音或呼吸音会被误认为一个音素,造成单词的端点检测不准,造成特征参数的变化,从而影响测度估计,降低识别率,因此在语音识别时,首先有必要对语音信号进行时间规整。
二、动态时间规整的定义
三、动态时间规整的原理描述
原理描述
公式
公式2
时间规整的依据
Dynamic time warping
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
- Levenshtein distance
- Elastic matching
动态规划时间规整简介入门相关推荐
- 动态规划-时间规整算法
在日常的生活中我们最经常使用的距离毫无疑问应该是欧式距离,但是对于一些特殊情况,欧氏距离存在着其很明显的缺陷,比如说时间序列,举个比较简单的例子,序列A:1,1,1,10,2,3,序列B:1,1,1, ...
- 动态时间规整_动态规划-数组系列(10%)
哇呀呀呀呀~~~好!实不相瞒,小弟我就是人称玉树临风胜潘安,一支梨花压海棠的小淫虫周伯通!<唐伯虎点秋香> 不同路径 IIleetcode-cn.com 一个机器人位于一个 m x n ...
- DTW动态时间规整算法
原文地址:https://blog.csdn.net/qcyfred/article/details/53824507 https://zhuanlan.zhihu.com/p/43247215 动态 ...
- 【时序】动态时间规整(DTW)算法原理及Python实现
DTW 简介 DTW 定义 动态时间规整(Dynamic Time Warping,DTW)用于比较具有不同长度的两个阵列或时间序列之间的相似性或距离. 假设要计算两个等长数组的距离: a = [1, ...
- 动态时间规整算法: 从DTW到FastDTW
目录 动态时间规整算法: 从DTW到FastDTW 总结: 简介[^1] DTW[^1] FastDTW:使用多级粗化的方法[^1] 结果 动态时间规整算法: 从DTW到FastDTW 总结: Fas ...
- 动态时间规整_动态时间规整下时间序列子序列的搜索与挖掘
一.DTW的背景 对于时间序列数据挖掘算法的相似性搜索来说最大的瓶颈就是所花费的时间,所以大多数关于时间序列数据挖掘的学术研究都在考虑数百万个时间序列对象时停滞不前,而许多工业和科学都在数十亿个等待探 ...
- 语音信号处理之(一)动态时间规整(DTW)
语音信号处理之(一)动态时间规整(DTW) zouxy09@qq.com http://blog.csdn.net/zouxy09 这学期有<语音信号处理>这门课,快考试了,所以也要了解了 ...
- 动态时间规整-DTW算法
作者:桂. 时间:2017-05-31 16:17:29 链接:http://www.cnblogs.com/xingshansi/p/6924911.html 前言 动态时间规整(Dynamic ...
- 【重大修改】动态时间规整(Dynamic Time Warping)
本文只是简单的介绍DTW算法的目的和实现.具体的DTW可以参考一下文献: 离散序列的一致性度量方法:动态时间规整(DTW) http://blog.csdn.net/liyuefeilong/art ...
最新文章
- 使用bash判断PATH中是否存在某个路径
- price change SAT trace
- [最新下载] 【火车票订票外挂】Go-Home–12306.cn 网上火车票自动订票程序
- jboss 不适用内置日志_适用于孩子,父母和祖父母的JBoss HornetQ –第1章
- linux条件测试的三种,shell编程之条件测试 | 旺旺知识库
- 【Makefile由浅入深完全学习记录4】变量和不同的赋值方式
- 作为一个非天才型选手,普通程序员如何升级打怪?
- nopcommerce笔记3 还可以控制什么
- 【AI】行为树(Behaviour Tree)
- java调用短信api接口发送短信demo实例
- php 判断是否是日文,php正则判断中文韩文的编码的例子
- 桌面上的计算机打不开怎么办,电脑桌面计算机打不开怎么办
- 【网络技术联盟站】瑞哥教你如何使用 Console 接口管理设备
- 一步一步实现STM32-FOTA系列教程之STM32-FLASH分区说明
- 轻松学编曲,论FL钢琴卷帘
- 中国石油大学计算机图形学第一次在线作业,北京交通大学《计算机图形学》20秋在线作业1-001答案...
- 简述空串和空格串(或称空格符串)的区别。
- 30.7.1 通过mysqladmin修改用户密码
- Java调用opencv实现图片去水印
- 量化投资常用技能——绘图篇 2:绘制移动平均线
热门文章
- 电脑常识(1) 32位的电脑和64位的电脑是什么意思?
- 个人网站SEO推广方法
- 从双十一看阿里云安全的“创世纪”——采访阿里云安全掌门人肖力有感
- Java技术类校招面试题汇总:用java实现发送手机验证码
- English- 近反义词
- Dubbo+Redis
- html div自动居中显示,DIV居中_div水平居中_DIV布局居中
- CS3实现动画效果,当页面到达某个位置时,触发动画效果,目标元素的宽度从中间到两端自动延申
- SAT2生物考试300个常用词汇
- 2022年质量员-装饰方向-通用基础(质量员)考试题库及模拟考试