栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

周期性检测dtw与欧氏距离的区别

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

周期性检测dtw与欧氏距离的区别

from dtaidistance import dtw
import numpy as np
x1 = np.array([1.0, 0, 0, 0, 1, 0, 0, 1, 0, 0])
y1 = np.array([1.0, 0, 0, 0, 1, 0, 0, 1, 0, 0])
y2 = np.array([1.0, 0, 0, 1, 0, 0, 0, 1, 0, 0])
y3 = np.array([1.0, 0, 0, 1, 0, 0, 1, 0, 0, 0])
y4 = np.array([1.0, 0, 1, 0, 0, 0, 0, 0, 1, 0])
# 与欧氏距离差异:
print('Window=1与欧氏距离效果等同:')
print(f'x:{x1}, ny:{y1}')
print('欧氏距离', np.sqrt(sum(np.power(x1 - y1, 2))))
print('window=1', dtw.distance_fast(x1, y1, window=1), 'n')

print(f'x:{x1}, ny:{y2}')
print('欧氏距离', np.sqrt(sum(np.power(x1 - y2, 2))))
print('dtw=1', dtw.distance_fast(x1, y2, window=1))
print('dtw=2', dtw.distance_fast(x1, y2, window=2), 'n')

print(f'x:{x1}, ny:{y3}')
print('欧氏距离', np.sqrt(sum(np.power(x1 - y3, 2))))
print('dtw=1', dtw.distance_fast(x1, y3, window=1))
print('dtw=2', dtw.distance_fast(x1, y3, window=2), 'n')

print(f'x:{x1}, ny:{y4}')
print('欧氏距离', np.sqrt(sum(np.power(x1 - y4, 2))))
print('dtw=1', dtw.distance_fast(x1, y4, window=1))
print('dtw=2', dtw.distance_fast(x1, y4, window=2))
print('dtw=3', dtw.distance_fast(x1, y4, window=3), 'n')

Window=1与欧氏距离效果等同:
x:[1. 0. 0. 0. 1. 0. 0. 1. 0. 0.], 
y:[1. 0. 0. 0. 1. 0. 0. 1. 0. 0.]
欧氏距离 0.0
window=1 0.0 

x:[1. 0. 0. 0. 1. 0. 0. 1. 0. 0.], 
y:[1. 0. 0. 1. 0. 0. 0. 1. 0. 0.]
欧氏距离 1.4142135623730951
dtw=1 1.4142135623730951
dtw=2 0.0 

x:[1. 0. 0. 0. 1. 0. 0. 1. 0. 0.], 
y:[1. 0. 0. 1. 0. 0. 1. 0. 0. 0.]
欧氏距离 2.0
dtw=1 2.0
dtw=2 0.0 

x:[1. 0. 0. 0. 1. 0. 0. 1. 0. 0.], 
y:[1. 0. 1. 0. 0. 0. 0. 0. 1. 0.]
欧氏距离 2.0
dtw=1 2.0
dtw=2 1.4142135623730951
dtw=3 0.0 
结论:

1、本质是元素可以跟相邻位置(由window参数控制偏移量)的数据进行比较,然后再通过欧氏距离进行计算,最后取最小的值,所有的元素都要参与计算,然后取到最小值参与最后结果的汇总。

2、注意事项:计算不能交叉,比如说x =【1,0,1,0】,y = 【1,0,0,1】,比如说最后x一个元素0,计算游标为3,就只能跟y的最后一个元素计算,因为当前y计算游标是3,即最后一个元素;计算时不能往前看,不能存在交叉。如下图所示(黄色线条不能有交叉):

3、window参数的意义如下:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1034073.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号