⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutual_average_inf.m

📁 主成分分析和偏最小二乘SquaresPrincipal成分分析( PCA )和偏最小二乘( PLS )
💻 M
字号:
function y=mutual_average_inf(x,maxLag);
% MUTUAL_AVERAGE_INF(x,maxLag) calculates the Mutual Average Information (MAI) (in
% bits) of vector x using lags from 0 to maxLag

%
% last modified 10.12.04


if nargin<2
    prompt = {'Enter maximal lag (in samples)'};
	dlg_title = 'Enter maximal lag';
	num_lines= 1;
	def     = {num2str(min([128 floor(length(x)/2)]))};
	answer  = inputdlg(prompt,dlg_title,num_lines,def);
	if isempty(answer)
        return
    end
    maxLag=str2num(answer{1});
end
      
if ~nargout
    titles='';
        [T,B]=mai(x,maxLag);
        plot(T,B),grid on
        xlim([T(1) T(end)]);
        xlabel('lag (samples)');
else
        [T,y]=mai(x,maxLag);
end


function [lag,v]=mai(x,maxLag)
%Syntax: v=mai(x,lag)
%
% Calculates the Mutual Average Information (MAI) (in bits) of a time series
% x for time lag from 0 to maxLag.
%
% v is the the value of the MAI.
% x is the time series.
% lag is the time lag.
%
% Reference:
% Fraser A, Swinney H (1986): Independent coordinates for strange attractors
% from mutual information. Physical Review A 33:1134-1140.
%
% Alexandros Leontitsis
% Lifetime e-mail: leoaleq@yahoo.com
% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421


% x must be a vector
x=x(:);
% n is the time series length
n=length(x);

lag=0:maxLag;

% The mutual average information
x=x-min(x);
x=x/max(x);
v=zeros(length(lag),1);
if var(x,1)~=0
	for i=1:length(lag)
       % Define the number of bins
       k=floor(1+log2(n-lag(i))+0.5);
          for k1=1:k
             for k2=1:k
                a=x(1:n-lag(i));
                b=x(1+lag(i):n);
                ppp=find((k1-1)/k<a & a<=k1/k & (k2-1)/k<b & b<=k2/k);
                ppp=length(ppp);
                if ppp>0
                   px1=find((k1-1)/k<a & a<=k1/k);
                   px2=find((k2-1)/k<b & b<=k2/k);
                   ppp=ppp/(n-lag(i));
                   px1=length(px1)/(n-lag(i));
                   px2=length(px2)/(n-lag(i));
                   v(i,1)=v(i,1)+ppp*log2(ppp/px1/px2);
                end
             end
          end
	end
end
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -