模糊熵、分布熵、近似熵、样本熵理论相关知识与代码实现

本篇为《信号处理》系列博客的第八篇,该系列博客主要记录信号处理相关知识的学习过程和自己的理解,方便以后查阅。

模糊熵

理论基础

模糊熵(Fuzzy Entropy, FuzzyEn, FE) 衡量的也是新模式产生的概率大小,测度值越大,新模式产生的概率越大,即序列复杂度越大。

算法描述如下:
在这里插入图片描述
在这里插入图片描述

代码实现

%%% 模糊熵计算函数 %%%
function fuzzyen = Fuzzy_Entropy( dim, r, data, tau )
% FUZZYEN Fuzzy Entropy
%   calculates the fuzzy entropy of a given time series data

% Similarity definition based on vectors' shapes, together with the
% exclusion of self-matches, earns FuzzyEn stronger relative consistency
% and less dependence on data length.

%   dim     : embedded dimension 
%   r       : tolerance (typically 0.2 * std)
%   data    : time-series data
%   tau     : delay time for downsampling (user can omit this, in which case
%             the default value is 1)
%

if nargin < 4, tau = 1; end
if tau > 1, data = downsample(data, tau); end

N = length(data);
Phi = zeros(1,2);

for m = dim:dim+1
    
    Ci = zeros(1,N-m+1);
    dataMat = zeros(m,N-m+1);
    
    % setting up data matrix - form vectors
    for j = 1:m
        dataMat(j,:) = data(j:N-m+j);
    end
    
    % baseline
    U0 = mean(dataMat);
    % remove baseline and calculate the absolute values
    Sm = abs(dataMat - repmat(U0,m,1));
    
    % Given vector Si, calculate the similarity degree between its'
    % neighboring vector Sj
    for i = 1:N-m+1
        
        Sm_tmp = Sm;
        Sm_tmp(:,i) = []; % excluded self-matches
        % maximum absolute difference of the corresponding scalar components
        % of Si and Sj (j≠i)
        dij = max(repmat(Sm(:,i),1,N-m) - Sm_tmp);
        % similarity degree
        Aij = exp(-log(2)*(dij/r).^2);
        % averaging all the similarity degree of its neighboring vectors Sj
        Ci(i) = sum(Aij)/(N - m);
        
    end
    
    % summing over the counts
    Phi(m-dim+1) = sum(Ci)/(N-m+1); % φ_m and φ_m+1
    
end

fuzzyen = log(Phi(1))-log(Phi(2));  % fuzzyen = ln(φ_m)-ln(φ_m+1)

end

关于一些参数的选择

在这里插入图片描述

Detection of epileptic seizure based on entropy analysis of short-term EEG

分布熵

理论基础

分布熵(DistEn) 较适应于短数据序列

分布熵解决了样本熵和近似熵的参数依赖性以及非
鲁棒性的缺点, 充分利用分析时间序列的状态空间对应项来量化向量间距离的分布特

算法描述如下:
在这里插入图片描述

代码实现

%%% 分布熵计算函数 %%%
function DistEn = Distribution_Entropy(dim, data, B, tau)
% DISTEN Distribution Entropy
%   calculates the distribution entropy of a given time series data

%   dim     : embedded dimension 
%   r       : tolerance (typically 0.2 * std)
%   data    : time-series data
%   tau     : delay time for downsampling (user can omit this, in which case
%             the default value is 1)
%   B       : 直方图的参数,分割数据的份数

if nargin < 4, tau = 1; end
if tau > 1, data = downsample(data, tau); end

m = dim;

N = length(data);
dataMat = zeros(m,N-m+1);

% setting up data matrix - form vectors
for j = 1:m
	dataMat(j,:) = data(j:N-m+j);
end

Sm = dataMat;
% Given vector Si, calculate the similarity degree between its'
% neighboring vector Sj
for i = 1:N-m+1
AE
	Sm_tmp = Sm;
	Sm_tmp(:,i) = []; % excluded self-matches
	% maximum absolute difference of the corresponding scalar components
	% of Si and Sj (j≠i)
	dij = max(repmat(Sm(:,i),1,N-m) - Sm_tmp);

    D(i,:)  = dij;% 生成N-m+1*N-m的矩阵
end

Dij=reshape(D,1,(N-(m-1))*(N-(m-1)-1));% 将D重置为1维矩阵,为啥呢???

% Dij:一维的向量
% B  :分割的数量
% n  :在一个分割区域内,Dij数据出现的次数
% x  :一个分割区域的中心线位置坐标
[n,x]=hist(Dij,B);
f=n/length(Dij);% 计算概率密度

for i=1:B
    if f(i)==0
        P(i)=0;% 如果概率密度为零,则求和值置零
    else
        P(i)= (f(i))*log2(f(i));
    end
end
    
DistEn = (-1/log2(B))*sum(P);

end

近似熵

理论基础

近似熵(Approximate Entropy, ApEn) 是一种用于量化时间序列波动的规律性和不可预测性的非线性动力学参数,它用一个非负数来表示一个时间序列的复杂性,反映了时间序列中新信息发生的可能性,越复杂的时间序列对应的近似熵越大

算法描述如下:
在这里插入图片描述
在这里插入图片描述

代码实现

%%% 近似熵计算函数 %%%
function apen = Approximate_Entropy( dim, r, data, tau )
%ApEn
%   dim  : embedded dimension
%   r    : tolerance (typically 0.2 * std)
%   data : time-series data
%   tau  : delay time for downsampling

%   Changes in version 1
%       Ver 0 had a minor error in the final step of calculating ApEn
%       because it took logarithm after summation of phi's.
%       In Ver 1, I restored the definition according to original paper's
%       definition, to be consistent with most of the work in the
%       literature. Note that this definition won't work for Sample
%       Entropy which doesn't count self-matching case, because the count
%       can be zero and logarithm can fail.
%
%       A new parameter tau is added in the input argument list, so the users
%       can apply ApEn on downsampled data by skipping by tau.
%---------------------------------------------------------------------
% coded by Kijoon Lee,  kjlee@ntu.edu.sg
% Ver 0 : Aug 4th, 2011
% Ver 1 : Mar 21st, 2012
%---------------------------------------------------------------------
if nargin < 4, tau = 1; end
if tau > 1, data = downsample(data, tau); end

N = length(data);
result = zeros(1,2);

for j = 1:2
    m = dim+j-1;
    phi = zeros(1,N-m+1);
    dataMat = zeros(m,N-m+1);
    
    % setting up data matrix
    for i = 1:m
        dataMat(i,:) = data(i:N-m+i);
    end
    
    % counting similar patterns using distance calculation
    for i = 1:N-m+1
        tempMat = abs(dataMat - repmat(dataMat(:,i),1,N-m+1));
        boolMat = any( (tempMat > r),1);
        phi(i) = sum(~boolMat)/(N-m+1);
    end
    
    % summing over the counts
    result(j) = sum(log(phi))/(N-m+1);
end

apen = result(1)-result(2);

end

样本熵

理论基础

样本熵(Sample Entropy, SampEn, SE) 是基于近似熵(ApEn)的一种用于度量时间序列复杂性的改进方法,在评估生理时间序列的复杂性和诊断病理状态等方面均有应用

由于样本熵是近似熵的一种改进方法,因此可以将其与近似熵联系起来理解.

算法描述如下:
在这里插入图片描述
在这里插入图片描述

代码实现

%%% 样本熵计算函数 %%% 
function SampEn = Sample_Entropy( dim, r, data, tau )
% SAMPEN Sample Entropy
%   calculates the sample entropy of a given time series data

%   SampEn is conceptually similar to approximate entropy (ApEn), but has
%   following differences:
%       1) SampEn does not count self-matching. The possible trouble of
%       having log(0) is avoided by taking logarithm at the latest step.
%       2) SampEn does not depend on the datasize as much as ApEn does. The
%       comparison is shown in the graph that is uploaded.

%   dim     : embedded dimension
%   r       : tolerance (typically 0.2 * std)
%   data    : time-series data
%   tau     : delay time for downsampling (user can omit this, in which case
%             the default value is 1)
%

if nargin < 4, tau = 1; end
if tau > 1, data = downsample(data, tau); end

N = length(data);
result = zeros(1,2);

for m = dim:dim+1% 该循环用于实现算法的第六步
    Bi = zeros(1,N-m+1);
    dataMat = zeros(m,N-m+1);
    
    % setting up data matrix
    for i = 1:m
        dataMat(i,:) = data(i:N-m+i);
    end
    
    % counting similar patterns using distance calculation
    for j = 1:N-m+1
        % calculate Chebyshev distance, excluding self-matching case
        dist = max(abs(dataMat - repmat(dataMat(:,j),1,N-m+1)));
        % calculate Heaviside function of the distance
        % User can change it to any other function
        % for modified sample entropy (mSampEn) calculation
        D = (dist <= r);
        % excluding self-matching case
        Bi(j) = (sum(D)-1)/(N-m);
    end
    
    % summing over the counts
    result(m-dim+1) = sum(Bi)/(N-m+1);
    
end

SampEn = -log(result(2)/result(1));

end
  • 11
    点赞
  • 135
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
多尺度近似样本、排列都是常用的非线性动力学分析方法,用于研究时间序列数据的复杂性和随机性。它们的主要区别在于计算的方法、对时间序列的处理方式、以及尺度的选择等方面。 1.多尺度(Multiscale Entropy,MSE):是一种用于描述时间序列复杂性的非线性动力学分析方法。它将时间序列分解为多个尺度,计算每个尺度下的样本,然后将不同尺度下的样本取平均值得到多尺度。MSE能够反映时间序列在不同尺度下的复杂性,并且可以避免传统的缺陷,如灵敏度不足和不适用于非平稳信号。 2.近似(Approximate Entropy,ApEn):是一种用于描述时间序列随机性的非线性动力学分析方法。它通过比较时间序列中不同长度的子序列之间的相似度,计算出一个近似近似越大,表明时间序列的随机性越低,越接近周期性。 3.样本(Sample Entropy,SampEn):是一种用于描述时间序列随机性的非线性动力学分析方法。它类似于近似,但是使用了不同的相似度测量方法。与近似不同,样本不受序列长度影响,具有较高的稳定性和可重复性。 4.排列(Permutation Entropy,PE):是一种用于描述时间序列复杂性的非线性动力学分析方法。它将时间序列转换为排列序列,并计算不同长度的排列序列出现的概率,然后计算排列。排列越大,表明时间序列的复杂性越高。 总的来说,这些方法都是用于研究时间序列数据的复杂性和随机性,并且在实际应用中往往需要结合具体的数据特点和研究目的来选择合适的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值