Code covered by the BSD License  

Highlights from
ProcessNetwork Version 1.0 Software

image thumbnail

ProcessNetwork Version 1.0 Software

by

 

Functions for the delineation of Dynamical Process Networks using Information Theory

[HXt, HYw, HYf, HXtYw, HXtYf, HYwYf, HXtYwYf, I, T, meanShuffT, sigmaShuffT, meanShuffI, sigmaShuffI, nCounts] ...
function [HXt, HYw, HYf, HXtYw, HXtYf, HYwYf, HXtYwYf, I, T, meanShuffT, sigmaShuffT, meanShuffI, sigmaShuffI, nCounts] ...
    = ShannonBitsWrapper( nSignals, lag, NoDataCode, nTuples, nTests, classifiedData, nBinMat, iter, isFirstLag)

HXt             = NaN( nSignals, nSignals );
HYw             = NaN( nSignals, nSignals );
HYf             = NaN( nSignals, nSignals );
HXtYw           = NaN( nSignals, nSignals );
HXtYf           = NaN( nSignals, nSignals );
HYwYf           = NaN( nSignals, nSignals );
HXtYwYf         = NaN( nSignals, nSignals );
I               = NaN( nSignals, nSignals );
T               = NaN( nSignals, nSignals );
meanShuffT      = NaN( nSignals, nSignals );
sigmaShuffT     = NaN( nSignals, nSignals );
meanShuffI      = NaN( nSignals, nSignals );
sigmaShuffI     = NaN( nSignals, nSignals );
nCounts         = NaN( nSignals, nSignals );

for sX=1:nSignals
    for sY=1:nSignals
        
        %CONSTRUCT THREE-COLUMN MATRIX WITH COLUMNS TIME-SHIFTED
        XtSTART=1;
        YwSTART=0+lag;
        YfSTART=1+lag;
        if (lag == 0)
            YwSTART = 1;
        end
        tupleMat=NaN(nTuples,3);
        tupleMat(:,1)=classifiedData(XtSTART:XtSTART+nTuples-1,sX);        %Leading Node Xt (lag tau earlier than present)
        tupleMat(:,2)=classifiedData(YwSTART:YwSTART+nTuples-1,sY);        %Led Node Yw (present time)
        tupleMat(:,3)=classifiedData(YfSTART:YfSTART+nTuples-1,sY);        %Led Node Yf (one timestep in future)

        %CHECK TO ENSURE TUPLEMAT HAS AT LEAST ONE COMPLETE ROW OF DATA
        hasDataFlagA=0;
        for i = 1:nTuples
            if ((tupleMat(i,1) ~= NoDataCode) && (tupleMat(i,2) ~= NoDataCode) && (tupleMat(i,3) ~= NoDataCode))
                hasDataFlagA = 1;
                break
            end
        end
        if (hasDataFlagA == 0)
            fprintf('ERROR: no data in tupleMat, skipping sX=%d sY=%d lag=%d \n',sX,sY, iter); %%%%%%%%%%%%%%%%debug print this and log this!!!
            continue
        end
 
        %CALCULATE ENTROPIES FROM TUPLEMAT
        [C, nCounts(sX,sY)] = getCountMat( tupleMat, nBinMat, sX, sY, NoDataCode );
        [HXt(sX,sY),HYw(sX,sY),HYf(sX,sY),HXtYw(sX,sY),HXtYf(sX,sY),HYwYf(sX,sY),HXtYwYf(sX,sY)]=GetShannonBits( C, nCounts(sX,sY) );
        I(sX,sY) = HXt(sX,sY) + HYf(sX,sY) - HXtYf(sX,sY);
        T(sX,sY) = HXtYw(sX,sY) + HYwYf(sX,sY) - HYw(sX,sY) - HXtYwYf(sX,sY);
        
        %COMPUTE SHUFFLED SURROGATE INFORMATION STATISTICS FROM TIME SHUFFLED VERSION OF TUPLEMAT
        %check to see if this is the first lag; otherwise don't do shuffling tests
        I_s = NaN(nTests,1);
        T_s = NaN(nTests,1);
        for test = 1:nTests
            
            % ONLY RUN TESTS FOR THE FIRST LAG; THE FIRST DISTRIBUTION IS
            % CLOSE ENOUGH TO THE DISTRIBUTION OF ALL TUPLEMATS, ASSUMING
            % THAT THE DATA INPUT SAMPLE TRULY DOES REPRESENT A SINGLE
            % STATE WITH STATIONARY INFORMATION DYNAMICS
            if ~isFirstLag
                break
            end
            
            % GENERATE SHUFFLED SURROGATE TUPLE MATRIX
            shuffleMat = NaN(nTuples,3);
            shuffleMat(:,1) = randsample(tupleMat(:,1),nTuples);
            shuffleMat(:,2) = randsample(tupleMat(:,2),nTuples);
            shuffleMat(:,3) = randsample(tupleMat(:,3),nTuples);
            
            %CALCULATE ENTROPIES FROM SHUFFLED TUPLEMAT
            [C, tempCount] = getCountMat( shuffleMat, nBinMat, sX, sY, NoDataCode );
            [HXt_s,HYw_s,HYf_s,HXtYw_s,HXtYf_s,HYwYf_s,HXtYwYf_s]=GetShannonBits( C, tempCount);
            I_s(test)=HXt_s+HYf_s-HXtYf_s;
            T_s(test)=HXtYw_s+HYwYf_s-HYw_s-HXtYwYf_s;

        end
        meanShuffT( sX, sY )  = mean(T_s(:));
        meanShuffI( sX, sY )  = mean(I_s(:));
        sigmaShuffT( sX, sY ) = std(T_s(:));
        sigmaShuffI( sX, sY ) = std(I_s(:));

    end
end

Contact us