闲话几句
相空间重构听起来高大上,但是一旦确定了嵌入维数和延迟时间,之后的操作就十分简单了。
下边给个代码示例一下“之后的操作”,至于嵌入维数和延迟时间的确定,还是需要查查论文的,后期看情况再写。
python程序
def embed_vectors_1d(self, lag, embed):
"""Embeds vectors from a one dimensional time series in m-dimensional
space.
Parameters
----------
X : 1d array
Training or testing set.
lag : int
Lag value as calculated from the first minimum of the mutual info.
embed : int
Embedding dimension. How many lag values to take.
predict : int
Distance to forecast (see example).
Returns
-------
features : 2d array
Contains all of the embedded vectors. Shape (num_vectors,embed).
Example
-------
>>> X = [0,1,2,3,4,5,6,7,8,9,10]
em = 3
lag = 2
predict=3
>>> embed_vectors_1d
features = [[0,2,4], [1,3,5], [2,4,6], [3,5,7]]
"""
tsize = self.X.shape[0]
t_iter = tsize-(lag*(embed-1))
features = np.zeros((t_iter,embed))
for ii in range(t_iter):
end_val = ii+lag*(embed-1)+1
part = self.X[ii : end_val]
features[ii,:] = part[::lag]
return features
这个程序是从skccm里边摘抄出来的,程序中用了for循环,这个在效率上不太高。
朴素的解释
相空间重构是要解决什么问题呢?最近看的两篇网文1 2很好的解释了这个问题,先把图片粘贴到这里,有人想看的话我再加上文字解释。
see also
- skccm:https://github.com/NickC1/skccm(GitHub可能无法打开)
Visualization of EDM Prediction with a Chaotic Time Series ↩︎
Explaining simplex projection ↩︎
扫描二维码关注公众号,回复: 13263373 查看本文章