인공지능 공부

dtw-python 써보기

DualQuaternion 2023. 8. 2. 12:01

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

 

DTW for Python - The DTW suite

From here you can search these documents. Enter your search terms below.

dynamictimewarping.github.io

 

위 링크를 보고 따라해보았다.

 

일단 가상 공간을 만들자. 

 

conda create -n DTW-Env python=3.8

 

pip install dtw-python

pip install matplot

 

간단하게 설치 완료

 

퀵스타트 코드 실행

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)

## See the recursion relation, as formula and diagram
print(rabinerJuangStepPattern(6,"c"))
rabinerJuangStepPattern(6,"c").plot()

## And much more!

 

위 코드 실행

 

플로팅이 안되는 이슈가 있다... 

https://github.com/DynamicTimeWarping/dtw-python/commit/0698942da33230bcefbc45a3ffa0bebc262c5d4f

 

do not call plt.show() · DynamicTimeWarping/dtw-python@0698942

tonigi committed Aug 18, 2022

github.com

보니까 1.3.0 부터 plot.show()를 없애서 안보이는 것으로 확인되어서 다시 추가해줬다...

 

플로팅 결과는 위와 같다.

 

이상으로 python-DTW 써보기 포스팅을 마친다.