데이터과학 삼학년

Dynamic Time Warping(DTW) 본문

Time Series Analysis

Dynamic Time Warping(DTW)

Dan-k 2022. 3. 25. 19:28
반응형

Dynamic Time Warping

- 와핑(warping)의 사전적의미는 뒤틀림, 휨 이라는 뜻

- 동적 시간 와핑은 이름과 같이 '속도 또는 길이에 따라 움직임이 다른 두 시계열간의 유사성(거리)을 측정'하는 알고리즘

- 그 거리가 최소화되는 방향으로 매칭시켜 누적 거리가 최소가 되는 warping(뒤틀림) 경로를 찾음

- DTW는 주로 그래픽, 비디오, 오디오와 같은 분야에서 사용되며, 의료분야에서 보행 유사성, 생체신호 분석에 사용, 자동음성 인식 분야에서 두각을 보이며 다른 속도를 가지는 음성을 인식

 

https://www.cs.ucr.edu/~eamonn/KAIS_2004_warping.pdf

 

 

 

코드

import numpy as np

## A noisy sine wave as query
idx = np.linspace(0,6.28,num=100)
query = np.sin(idx) + np.random.uniform(size=100)/10.0

## A cosine is for template; sin and cos are offset by 25 samples
template = np.cos(idx)

## Find the best match with the canonical recursion formula
from dtw import *
alignment = dtw(query, template, keep_internals=True)

## Display the warping curve, i.e. the alignment curve
alignment.plot(type="threeway")
## Align and plot with the Rabiner-Juang type VI-c unsmoothed recursion
dtw(query, template, keep_internals=True, 
    step_pattern=rabinerJuangStepPattern(6, "c")).plot(type="twoway",offset=-2)
    
dtw(query, template, keep_internals=True).distance
19.127911

https://dynamictimewarping.github.io/python/

https://colab.research.google.com/drive/1-fbhBlKRrEG8jkqoBAWOAzWaOarDQcDp#scrollTo=eoXK1R4r8Hzr

728x90
반응형
LIST
Comments