Document:
为每个(x_i, x_j)创建一个时间相关性矩阵。首先,它以-1
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mIHtqGZ3-1678874178580)(null)]
格拉姆矩阵:假设有一个向量V,Gram矩阵就是来自V的每一对向量的内积矩阵。
# Author: Johann Faouzi
# License: BSD-3-Clause
import numpy as np
import matplotlib.pyplot as plt
from pyts.approximation import PiecewiseAggregateApproximation
# Parameters
n_samples, n_timestamps = 100, 48
# Toy dataset
rng = np.random.RandomState(41)
X = rng.randn(n_samples, n_timestamps)
# PAA transformation
window_size = 6
paa = PiecewiseAggregateApproximation(window_size=window_size)
X_paa = paa.transform(X)
# Show the results for the first time series
plt.figure(figsize=(6, 4))
plt.plot(X[0], 'o--', ms=4, label='Original')
plt.plot(np.arange(window_size // 2,
n_timestamps + window_size // 2,
window_size), X_paa[0], 'o--', ms=4, label='PAA')
plt.vlines(np.arange(0, n_timestamps, window_size) - 0.5,
X[0].min(), X[0].max(), color='g', linestyles='--', linewidth=0.5)
plt.legend(loc='best', fontsize=10)
plt.xlabel('Time', fontsize=12)
plt.title('Piecewise Aggregate Approximation', fontsize=16)
plt.show()
# python 示例
# 导入需要的包
from pyts.approximation import PiecewiseAggregateApproximation
from pyts.preprocessing import MinMaxScaler
import numpy as np
import matplotlib.pyplot as plt
# 生成一些demo数据
X = [[1,2,3,4,5,6,7,8],[23,56,52,46,34,67,70,60]]
plt.plot(X[0],X[1])
plt.title(‘Time series’)
plt.xlabel(‘timestamp’)
plt.ylabel(‘value’)
plt.show()
# 分段聚合逼近和缩放
# PAA
transformer = PiecewiseAggregateApproximation(window_size=2)
result = transformer.transform(X)
# Scaling in interval [0,1]
scaler = MinMaxScaler()
scaled_X = scaler.transform(result)
plt.plot(scaled_X[0,:],scaled_X[1,:])
plt.title(‘After scaling’)
plt.xlabel(‘timestamp’)
plt.ylabel(‘value’)
plt.show()
# 转换成极坐标
arccos_X = np.arccos(scaled_X[1,:])
fig, ax = plt.subplots(subplot_kw={‘projection’: ‘polar’})
ax.plot(result[0,:], arccos_X)
ax.set_rmax(2)
ax.set_rticks([0.5, 1, 1.5, 2]) # Less radial ticks
ax.set_rlabel_position(-22.5) # Move radial labels away from plotted line
ax.grid(True)
ax.set_title(“Polar coordinates”, va=’bottom’)
plt.show()
# Gramina angular summation fields
field = [a+b for a in arccos_X for b in arccos_X]
gram = np.cos(field).reshape(-1,4)
plt.imshow(gram)
参考文献:
《Encoding Time Series as Images for Visual Inspection and Classification Using Tiled Convolutional Neural Networks》 janurary,2015
Gramian Angular Field
给定一个时间序列X,将其缩放到[-1,1],
然后再在极坐标系中表示该时间序列(通过将value编码为angular cosine,将时间戳编码为radius,
ti是时间戳,N是正则化极坐标系统跨度的常数因子。这种基于极坐标的表示方法是理解时间序列的一种新方法。随着时间的增加,相应的值在跨越圆上的不同角度点之间扭曲,就像水荡漾一样。
Question:当编码为反函数值时,-1和1怎么确定呢?value都是正的时,对应两个角度(在 0 0 0到 2 π 2\pi 2π上)。。。怎么选