-
Notifications
You must be signed in to change notification settings - Fork 1
/
calcMutInfDelay.m
62 lines (54 loc) · 2.17 KB
/
calcMutInfDelay.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function [Z, varargout] = calcMutInfDelay(X, varargin)
% An nD wrapper for the 'mexCalcMutInfDelay2D.c' function.
% Calculates mutual information of the delayed time series for each delay
% Replaces uncomputed time points with NaN
%
% ========= Input =========
% one to three arguments:
%
% - X -- an nD array of time series,
% with the time running along the first dimension
% i.e. array size [ T x N x M x ... ],
% where T is the number of time points
% - tauMax (optional) -- the maximal time delay;
% (default: 20)
% - bins (optional) -- number of bins
%
% ========= Output =========
% - Z -- an array of the mutual information;
% the first dimension of Z is equal to (tauMax+1)
% with the corresponding timeline (0:1:tauMax)
% - t (optional) -- the lag-timeline:
% t = (0:1:tauMax)'
%
% ========= References: =========
% 1. Andrew M. Fraser and Harry L. Swinney. "Independent coordinates for strange attractors from mutual information," Phys. Rev. A 33 (1986) 1134-1140.
% http://dx.doi.org/10.1103%2fPhysRevA.33.1134
% 2. Eric Weeks' page with the description of the modified algorithm,
% http://www.physics.emory.edu/~weeks/software/minfo.html
%
% ===============================
% Author: Dmytro S. Lituiev (2013), University of Zurich,
% based on the Eric Weeks' C script (1997)
%% check the second argument, tauMax
if nargin>1 && isscalar(varargin{1})
tauMaxIn = varargin{1};
tauMaxOut = min(varargin{1}, size(X,1)- 2^6);
else
tauMaxIn = min(20, size(X,1)-5);
tauMaxOut = tauMaxIn;
end
dim = size(X);
%== squeeze nD into 2D
X = reshape(X, [dim(1), prod(dim(2:end))] );
%% run the MEX file
Z = mexCalcMutInfDelay2D(X, tauMaxOut, varargin{2:end});
%== tauMax is obtained directly from the MEX function output:
tauMaxOut = size(Z,1)-1;
if tauMaxOut < tauMaxIn
Z( tauMaxOut+2:tauMaxIn+1, :) = NaN;
end
Z = reshape( Z, [tauMaxIn + 1, dim(2:end)]);
if nargout>1
varargout{1} = (0:1:tauMaxIn)';
end