# 基于顺序模式的度量的多元时间序列非线性分析的Matlab工具箱代码

✅作者简介：热爱科研的Matlab仿真开发者，修心和技术同步精进，matlab项目合作可私信。

🍎个人主页：Matlab科研工作室

🍊个人信条：格物致知。

## ⛄ 内容介绍

OPA（序数模式分析）工具箱用于多元时间序列的非线性分析，基于序数模式的度量变得越来越流行 [1-5]，这些度量可以高效计算 [6,7] 并可视化：-

- 具有并列等级的序数模式的排列熵 (cfg.method = 'eqPE') [4,8]

- 排列熵和序数模式分布 (cfg.method = 'opdPE ') [3]

- 序数模式的条件熵 (cfg.method = 'cePE') [6]

- 稳健的排列熵 (cfg.method = 'rePE') [4,7]

## ⛄ 部分代码

%% compute permutation entropy in sliding windows

load( 'tonicClonic.mat' );

cfg            = [];

cfg.method     = 'PE'; % compute permutation entropy

cfg.order      = 3;    % ordinal pattens of order 3 (4-points ordinal patterns)

cfg.delay      = 2;    % delay 2 between points in ordinal patterns

% (one point between successive points in ordinal patterns)

cfg.windowSize = 512;  % window size = 512 time steps

cfg.time       = 0:1/102.4:179.999; % OPTIONAL time axis for plotting

cfg.units      = 'seconds';         % OPTIONAL units of time for plotting

outdata        = OPanalysis( cfg, indata );

%% compute permutation entropy and ordinal distributions in sliding windows

load( 'tonicClonic.mat' );

cfg            = [];

cfg.method     = 'opdPE'; % compute permutation entropy

cfg.order      = 3;       % ordinal pattens of order 3 (4-points ordinal patterns)

cfg.orderSeq   = 6;       % ordinal pattens of order 6 for plotting their sequence (7-points ordinal patterns)

cfg.delay      = 1;       % delay 1 between points in ordinal patterns (successive points)

cfg.windowSize = 1024;    % window size = 1024 time steps

cfg.time       = 0:1/102.4:179.999; % OPTIONAL time axis for plotting

cfg.units      = 'seconds';         % OPTIONAL units of time for plotting

outdata        = OPanalysis( cfg, indata );

%% compute all the implemented measures simultaneously for comparison

load( 'tonicClonic.mat' );

cfg                = [];

cfg.method         = 'all';  % compute all implemented ordinal-patterns-based measures

cfg.order          = 4;      % ordinal patterns of order 4 (5-points ordinal patterns)

cfg.delay          = 1;      % delay 1 between points in ordinal patterns

cfg.windowSize     = 512;    % window size = 512 time steps

cfg.lowerThreshold = 0.2;    % the distance considered negligible between points

cfg.upperThreshold = 200;    % the distance between points most probably related to artifact

cfg.time           = 0:1/102.4:179.999; % OPTIONAL time axis for plotting

cfg.units          = 'seconds';         % OPTIONAL units of time for plotting

outdata            = OPanalysis( cfg, indata );

%% compute conditional entropy of ordinal patterns in sliding windows

load( 'tonicClonic.mat' );

cfg            = [];

cfg.method     = 'CE'; % we compute conditional entropy of ordinal patterns

cfg.order      = 3;    % ordinal pattens of order 3 (4-points ordinal patterns)

cfg.delay      = 1;    % delay 1 between points in ordinal patterns (successive points)

cfg.windowSize = 512;  % window size = 512 time steps

cfg.time       = 0:1/102.4:179.999; % OPTIONAL time axis for plotting

cfg.units      = 'seconds';         % OPTIONAL units of time for plotting

outdata        = OPanalysis( cfg, indata );

%% compute robust permutation entropy

load( 'tonicClonic.mat' );

cfg                = [];

cfg.method         = 'rePE'; % compute robust permutation entropy

cfg.order          = 6;      % ordinal patterns of order 6 (7-points ordinal patterns)

cfg.delay          = 1;      % delay 1 between points in ordinal patterns

cfg.windowSize     = 2048;   % window size = 2048 time steps

cfg.lowerThreshold = 0.2;    % the distance that is considered negligible between points

cfg.upperThreshold = 100;    % the distance between points most probably related to artifact

cfg.time           = 0:1/102.4:179.999; % OPTIONAL time axis for plotting

cfg.units          = 'seconds';         % OPTIONAL units of time for plotting

outdata            = OPanalysis( cfg, indata );

%% compute permutation entropy for ordinal patterns with tied ranks in sliding windows

load( 'tonicClonic.mat' );

cfg            = [];

cfg.method     = 'PEeq'; % compute permutation entropy for ordinal patterns with tied ranks

cfg.order      = 3;      % ordinal pattens of order 3 (4-points ordinal patterns)

cfg.delay      = 3;      % delay 3 between points in ordinal patterns

% (2 points between successive points in ordinal patterns)

cfg.windowSize = 1024;   % window size = 1024 time steps

cfg.time       = 0:1/102.4:179.999; % OPTIONAL time axis for plotting

cfg.units      = 'seconds';         % OPTIONAL units of time for plotting

outdata        = OPanalysis( cfg, indata );

%% compute permutation entropy for several channels

load( 'tonicClonic.mat' );

indata( 2, : )     = rand( 1, length( indata ) );

cfg                = [];

cfg.method         = 'PE'; % compute robust permutation entropy

cfg.order          = 3;      % ordinal patterns of order 3 (4-points ordinal patterns)

cfg.delay          = 1;      % delay 1 between points in ordinal patterns

cfg.windowSize     = 1024;   % window size = 1024 time steps

cfg.time           = 0:1/102.4:179.999; % OPTIONAL time axis for plotting

cfg.units          = 'seconds';         % OPTIONAL units of time for plotting

outdata            = OPanalysis( cfg, indata );

%% compute permutation entropy and conditional entropy of ordinal patterns

% for different parameters of logistic map (we use low-level functions for the example)

orbitLength = 10^4;

% take different r values

order       = 7;    % for ordinal pattens of order 7 (8-points ordinal patterns)

delay       = 1;    % for delay 1 (successive points in ordinal patterns)

windowSize  = orbitLength - order*delay;

r           = 3.5:5*10^(-4):4;

peValues    = zeros( 1, length( r ) );

ceValues    = zeros( 1, length( r ) );

leValues    = LEofLogisticMap( 3.5, 4, 5*10^(-4) );

indata      = zeros( 1, orbitLength );

for i = 1:length( r )

if ( rem( i, 10 ) == 0 )

disp( [ 'Calculating entropies for r = ' num2str( r( i ) ) ' from 4' ] );

end

indata( 1, 1 ) = rand( 1, 1 );

for j = 2:orbitLength

indata( j ) = r( i )*indata( j - 1 )*( 1 - indata( j - 1 ) );

end

peValues( i ) = PE( indata, delay, order, windowSize );

ceValues( i ) = CondEn( indata, delay, order, windowSize - delay );

end

figure;

linewidth  = 0.5;

markerSize = 2;

plot( r, leValues, 'k',  'LineWidth',  linewidth ); grid on; hold on;

plot( r, peValues, 'go', 'markerSize', markerSize ); grid on; hold on;

plot( r, ceValues, 'bo', 'markerSize', markerSize ); grid on; hold on;

legend( 'LE', 'PE', 'CE' );

xlabel( 'Values of parameter r for logistic map x(t)=r*x(t-1)*(1-x(t-1))' );

%% INEFFICIENT METHOD: compute permutation entropy in sliding windows with an old method

% just for comparison in terms of speed with fast (PE.m) method

load( 'tonicClonic.mat' );

cfg            = [];

cfg.method     = 'oldPE'; % compute permutation entropy

cfg.order      = 6;       % ordinal pattens of order 6 (7-points ordinal patterns)

cfg.delay      = 1;       % delay 1 between points in ordinal patterns (successive points)

cfg.windowSize = 512;     % window size = 512 time steps

cfg.time       = 0:1/102.4:179.999; % OPTIONAL time axis for plotting

cfg.units      = 'seconds';         % OPTIONAL units of time for plotting

outdata        = OPanalysis( cfg, indata );

## ⛄ 参考文献

REFERENCES:

[1] Amigo, J.M., Keller, K. and Unakafova, V.A., 2015. On entropy, entropy-like quantities, and applications. Discrete & Continuous Dynamical Systems-Series B, 20(10).

[2] Bandt C., Pompe B., Permutation entropy: a natural complexity measure for time series. Physical review letters, 2002, APS

[3] Keller, K., and M. Sinn. Ordinal analysis of time series. Physica A: Statistical Mechanics and its Applications 356.1 (2005): 114--120

[4] Keller, K., Unakafov, A.M. and Unakafova, V.A., 2014. Ordinal patterns, entropy, and EEG. Entropy, 16(12), pp.6212-6239.

[5] Zanin, M., Zunino, L., Rosso, O.A. and Papo, D., 2012.

Permutation entropy and its main biomedical and econophysics applications: a review. Entropy, 14(8), pp.1553-1577.

[6] Unakafova, V.A., Keller, K., 2013. Efficiently measuring complexity on the basis of real-world Data. Entropy, 15(10), 4392-4415.

[7] Unakafova, V.A., 2015. Investigating measures of complexity for dynamical systems and for time series (Doctoral dissertation, University of Luebeck).

[8] Bian, C., Qin, C., Ma, Q.D. and Shen, Q., 2012. Modified permutation-entropy analysis of heartbeat dynamics. Physical Review E, 85(2), p.021906.

[9] Amigo, J.M., Zambrano, S. and Sanjuan, M.A., 2008. Combinatorial detection of determinism in noisy time series. EPL (Europhysics Letters), 83(6), p.60005.

[10] Cao, Y., Tung, W.W., Gao, J.B. et al., 2004. Detecting dynamical changes in time series using the permutation entropy. Physical Review E, 70(4), p.046217.

[11] Riedl, M., Muller, A. and Wessel, N., 2013. Practical considerations of permutation entropy. The European Physical Journal Special Topics, 222(2), pp.249-262

## ⛳️ 完整代码

##### ❤️ 关注我领取海量matlab电子书和数学建模资料

|
5天前
|

【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码

20 6
|
6天前
|

【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现

17 3
|
2天前
|

9 2
|
5天前
|

14 2
|
6天前
|

【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码

14 0
|
1月前
|

- **算法理论:** 利用PSO优化的CNN-GRU，结合CNN的特征提取和GRU的记忆机制，进行时间序列预测。 - **CNN:** 通过卷积捕获序列的结构信息。 - **GRU:** 简化的LSTM，处理序列依赖。 - **预测步骤:** 1. 初始化粒子群，每粒子对应一组模型参数。 2. 训练并评估CNN-GRU模型的验证集MSE。 3. 使用PSO更新参数，寻找最佳配置。 4. 迭代优化直至满足停止准则。 `
46 13
|
11天前
【光波电子学】MATLAB绘制光纤中线性偏振模式LP之单模光纤的电场分布(光斑)

12 0
|
1月前
|

**算法预览图省略** - **软件版本**: MATLAB 2022a - **核心代码片段**略 - **PSO-CNN-LSTM概览**: 结合深度学习与优化，解决复杂时间序列预测。 - **CNN**利用卷积捕获时间序列的空间特征。 - **LSTM**通过门控机制处理长序列依赖，避免梯度问题。 - **流程**： 1. 初始化粒子群，每个粒子对应CNN-LSTM参数。 2. 训练模型，以验证集MSE评估适应度。 3. 使用PSO更新粒子参数，寻找最佳配置。 4. 迭代优化直到满足停止条件，如最大迭代次数或找到优良解。
39 0
|
3月前
|

176 1
|
3月前

107 1