一、   排列熵算法简介:

排列熵算法(Permutation Entroy)为度量时间序列复杂性的一种方法,算法描述如下:

设一维时间序列:

采用相空间重构延迟坐标法对X中任一元素x(i)进行相空间重构,对每个采样点取其连续的m个样点,得到点x(i)的m维空间的重构向量:

则序列X的相空间矩阵为:

其中m和l分别为重构维数和延迟时间;

对x(i)的重构向量Xi各元素进行升序排列,得到:

这样得到的排列方式为

其为全排列m!中的一种,对X序列各种排列情况出现次数进行统计,计算各种排列情况出现的相对频率作为其概率p1、p2、…pk,k<=m!,计算序列归一化后的排列熵:

相对来说,排列熵的计算过程较为简洁,计算量主要为k次序列长度为m的全排序,在满足功能的前提下,窗口可以尽量的小,同时,窗口大小和延迟l值的大小选取非常重要。排列熵H的大小表征时间序列的随机程度,值越小说明该时间序列越规则,反之,该时间序列越具有随机性。在排列熵算法的基础上也可以发展出诸多使用熵值的对时间序列进行异常检测的算法

二.排列熵算法的实现

已排列窗口长度为4为例(由于涉及对数组的重复排序,该窗口长度宜设置较小,已加快计算速度),计算一段序列值得排列熵

</pre><span style="white-space:pre">       </span>private double PermutationEntropyCalCulator(double[] dArrData)<span style="white-space:pre">      </span>{<span style="white-space:pre">           </span>/*<span style="white-space:pre">          </span> *  计算一段序列值的排列熵<span style="white-space:pre">         </span> */<span style="white-space:pre">         </span>int M = 4; //窗口长度值<span style="white-space:pre">         </span>int nMPer = 24;// 大小为窗口长度的集合全排列数<span style="white-space:pre">           </span>int L = 8; //延迟<span style="white-space:pre">            </span>double[] dArrSample = new double[M];<span style="white-space:pre">           </span>int[] nArrSampleSortIndex = new int[M];<span style="white-space:pre">            </span>int[] nPermCount = new int[nMPer];<span style="white-space:pre">         </span><span style="white-space:pre">            </span>Dictionary<string, int> permlist = new Dictionary<string, int>();<span style="white-space:pre">          </span>//构建字典索性<span style="white-space:pre">            </span>permlist.Add("4321", 0);<span style="white-space:pre">          </span>permlist.Add("4312", 1);<span style="white-space:pre">          </span>permlist.Add("4231", 2);<span style="white-space:pre">          </span>permlist.Add("4213", 3);<span style="white-space:pre">          </span>permlist.Add("4123", 4);<span style="white-space:pre">          </span>permlist.Add("4132", 5);<span style="white-space:pre">          </span><span style="white-space:pre">            </span>permlist.Add("3421", 6);<span style="white-space:pre">          </span>permlist.Add("3412", 7);<span style="white-space:pre">          </span>permlist.Add("3241", 8);<span style="white-space:pre">          </span>permlist.Add("3214", 9);<span style="white-space:pre">          </span>permlist.Add("3124", 10);<span style="white-space:pre">         </span>permlist.Add("3142", 11);<span style="white-space:pre">         </span><span style="white-space:pre">            </span>permlist.Add("2341", 12);<span style="white-space:pre">         </span>permlist.Add("2314", 13);<span style="white-space:pre">         </span>permlist.Add("2431", 14);<span style="white-space:pre">         </span>permlist.Add("2413", 15);<span style="white-space:pre">         </span>permlist.Add("2143", 16);<span style="white-space:pre">         </span>permlist.Add("2134", 17);<span style="white-space:pre">         </span><span style="white-space:pre">            </span>permlist.Add("1324", 18);<span style="white-space:pre">         </span>permlist.Add("1342", 19);<span style="white-space:pre">         </span>permlist.Add("1234", 20);<span style="white-space:pre">         </span>permlist.Add("1243", 21);<span style="white-space:pre">         </span>permlist.Add("1423", 22);<span style="white-space:pre">         </span>permlist.Add("1432", 23);<span style="white-space:pre">         </span><span style="white-space:pre">                        </span><span style="white-space:pre">            </span>Array.Clear(nPermCount, 0, nPermCount.Length);<span style="white-space:pre">          </span><span style="white-space:pre">            </span>int j, k;<span style="white-space:pre">           </span><span style="white-space:pre">            </span>for (j=0; j < (dArrData.Length- M*L); j++)<span style="white-space:pre">            </span>{<span style="white-space:pre">               </span>for (k=0; k<M; k++)<span style="white-space:pre">               </span>{<span style="white-space:pre">                   </span>dArrSample[k] = dArrData[j+k*L];<span style="white-space:pre">              </span>}<span style="white-space:pre">               </span><span style="white-space:pre">                </span>SortIdex(dArrSample, ref nArrSampleSortIndex);//排序<span style="white-space:pre">              </span><span style="white-space:pre">                </span>string strSampleSortIndex = "";<span style="white-space:pre">              </span>for (k=0; k<M; k++)<span style="white-space:pre">               </span>{<span style="white-space:pre">                   </span>strSampleSortIndex += nArrSampleSortIndex[k];<span style="white-space:pre">             </span>}<span style="white-space:pre">               </span><span style="white-space:pre">                </span>if (permlist.TryGetValue(strSampleSortIndex, out k) == false)<span style="white-space:pre">             </span>{<span style="white-space:pre">                   </span>k = 0;<span style="white-space:pre">             </span>}<span style="white-space:pre">               </span><span style="white-space:pre">                </span>nPermCount[k]++;<span style="white-space:pre">          </span>}<span style="white-space:pre">           </span><span style="white-space:pre">            </span>double dPermSum = 0;<span style="white-space:pre">           </span>nMPer = 24;<span style="white-space:pre">            </span>for (j=0; j<nMPer; j++)<span style="white-space:pre">           </span>{<span style="white-space:pre">               </span>dPermSum += nPermCount[j];<span style="white-space:pre">            </span>}<span style="white-space:pre">           </span><span style="white-space:pre">            </span>double dPermutationEntropy = 0;<span style="white-space:pre">            </span>for (j=0; j<nMPer; j++)<span style="white-space:pre">           </span>{<span style="white-space:pre">               </span>if(nPermCount[j]>0)<span style="white-space:pre">              </span>{<span style="white-space:pre">               </span>   double dProb = nPermCount[j]/dPermSum;<span style="white-space:pre">              </span>   dPermutationEntropy += -dProb*Math.Log(dProb);//计算熵值<span style="white-space:pre">               </span>}<span style="white-space:pre">           </span>}<span style="white-space:pre">           </span><span style="white-space:pre">            </span>dPermutationEntropy = dPermutationEntropy/Math.Log(nMPer);<span style="white-space:pre">         </span><span style="white-space:pre">            </span>double dWeight = (dPermSum-nPermCount[0])/dPermSum;<span style="white-space:pre">            </span>dPermutationEntropy = dPermutationEntropy*dWeight;<span style="white-space:pre">         </span><span style="white-space:pre">            </span>return dPermutationEntropy;<span style="white-space:pre">     </span>}</p><p style="color: rgb(54, 46, 43); font-family: Arial; font-size: 14px; line-height: 26px;"><pre name="code" class="html">private void SortIdex(double[] dArrSample, ref int[] nArrSampleSortIndex){/** 由小至大,依次排序* */if (dArrSample.Length != nArrSampleSortIndex.Length){return;   }int i,j;int nTempIndex = 0;double dTempValue = 0;for(i=0; i<nArrSampleSortIndex.Length; i++){nArrSampleSortIndex[i] = i+1;}for(i=0; i<dArrSample.Length; i++){             for(j=(dArrSample.Length-1); j>i; j--){if(dArrSample[j-1]>dArrSample[j]){dTempValue = dArrSample[j-1];nTempIndex = nArrSampleSortIndex[j-1];dArrSample[j-1] = dArrSample[j];nArrSampleSortIndex[j-1] = nArrSampleSortIndex[j];dArrSample[j] = dTempValue;nArrSampleSortIndex[j] = nTempIndex;              }}}}

窗口长度较大的时,在小型设备上实时运行需要耗费较多的资源,不知道能否做进一步的优化呢

转载于:https://www.cnblogs.com/cl1024cl/p/6205048.html

排列熵算法简介及c#实现相关推荐

  1. 排列熵算法--用于时间序列信号的复杂度检测

    排列熵算法(Permutation Entropy PE) 出发点:用于脑电信号的信号判别,提取该排列熵特征,以区分不同的类 其它突变信号检测方法: 总结: 1.傅里叶变换在全局上提供了信号整体奇异性 ...

  2. 参数优化多尺度排列熵算法

    目录 一.多尺度排列熵原理 1.1 排列熵(PE) 1.2 多尺度排列熵(MPE) 1.3 参数对MPE的影响 二.参数优化方法 2.1 遗传算法(GA) 2.2 粒子群优化算法(PSO) 2.3 多 ...

  3. 排列熵算法举例子理解

    python基础知识 x = np.linspace(0.05, 10, 1000) # 在0.05到10的区间中,等差选取1000个,端点不属于.返回一个数组 格式: array = numpy.l ...

  4. 关于排列熵的一些理解与解释

    排列熵的主要原理可见链接1与链接2 针对这两天学习排列熵的疑问,根据上述理论与链接代码进行理解的基础上,将matlab代码增添了一些注释,使得能详细的说明其原理. 此外,需要说明的是. "( ...

  5. 排列熵、模糊熵、近似熵、样本熵的原理及MATLAB实现

    目录 一.排列熵 1.概念 2.基本原理 补充说明 3.MATLAB代码 参考文献 一.排列熵 1.概念 一种检测动力学突变和时间序列随机性的方法,能够定量评估信号序列中含有的随机噪声. 2.基本原理 ...

  6. DL之SoftmaxWithLoss:SoftmaxWithLoss算法(Softmax+交叉熵误差)简介、使用方法、应用案例之详细攻略

    DL之SoftmaxWithLoss:SoftmaxWithLoss算法(Softmax函数+交叉熵误差)简介.使用方法.应用案例之详细攻略 目录 SoftmaxWithLoss算法简介 1.Soft ...

  7. 排列熵、模糊熵、近似熵、样本熵的原理及MATLAB实现之近似熵

    说明:"本博文为排列熵.模糊熵.近似熵.样本熵的原理及MATLAB实现"系列博文的最后一篇,关于排列熵.模糊熵.样本熵的内容请阅读博客: 排列熵 模糊熵 样本熵 近似熵 四.近似熵 ...

  8. 数据结构与算法:算法简介

    数据结构与算法:算法简介 雪柯 大工生物信息 提笔为写给奋进之人 已关注 你说呢 . shenwei356 等 70 人赞同了该文章 引用自算法图解,作者[美] Aditya Bhargava 译袁国 ...

  9. DL之DNN优化技术:神经网络算法简介之数据训练优化【mini-batch技术+etc】

    DL之DNN优化技术:神经网络算法简介之数据训练优化[mini-batch技术+etc] 目录 1.mini-batch技术 输出结果 实现代码 1.mini-batch技术 输出结果 实现代码 # ...

最新文章

  1. 一起学微软Power BI系列-使用技巧(3)Power BI安卓手机版安装与体验
  2. Exchange系列—管理邮件队列
  3. 从微信公众平台·小程序内测邀请函看应用号动向
  4. python异常类型(Exception只是常规错误的基类)
  5. nuxt.js 本地开发跨域问题(Access-Control-Allow-Origin)及其解决方案
  6. (四) View/Model 全解(mvc)
  7. Java Bean + 注册验证
  8. linux下grep查找关键字
  9. python的for语句怎么写_Python日常之——不要再写循环了!
  10. 使用springboot遇到的的异常
  11. 集成学习lgb库调参的粒子群方法
  12. 伍德里奇计量经济学计算机课后答案第一章,伍德里奇---计量经济学第7章部分计算机习题详解(STATA)...
  13. 使用DroidCam将手机作为PC的摄像头
  14. ipad iphone横屏竖屏
  15. 决策树CART 代价复杂度剪枝
  16. sumifs多条件求和步骤?如何运用sumifs函数进行求和
  17. POJ 1129 Channel Allocation(四色定理)
  18. mysql odbc 连接失败,mysql odbc 定时连接不上数据库
  19. 用dRING设置特定日期提醒
  20. J2EE系列:再谈IE的浏览器模式和文档模式

热门文章

  1. 思考则第一法则:目的性
  2. 在IT行业里,网工都有啥高含金量的证书可考?
  3. swf/AS2.0/AS3.0/fla/ppt课件如何转化为跨平台HTML5交互课件/动画?
  4. PCB 自动发送邮件---加入表格实现方法
  5. 实战 PureMVC
  6. text-overflow: ellipsis; white-space: nowrap;文本超出部门省略号
  7. 17.letterCombinations
  8. matlab bar中画显著性水平线,科学网—简析条形图(bar plot)上的误差线 - 于淼的博文...
  9. Windows下的Powerlink主从站通信-(现场总线作业——NJIT)
  10. shell命令之tee