Automated Eigenvalue analysis of SD models

by

 

Identifying dominant behavior patterns, links and loops: Automated Eigenvalue analysis of SD models.

analysis( modelObjectsStructVector , constantsVector , constantsValuesVector , modelObjectsValuesMatrix , netflowsValuesMatrix , initialTime , finalTime , timeStepLength , outFileName )
function analysis( modelObjectsStructVector , constantsVector , constantsValuesVector , modelObjectsValuesMatrix , netflowsValuesMatrix , initialTime , finalTime , timeStepLength , outFileName )

% -------------------------------------------------------------------------
% Filename:     analysis.m
% Author:       Ahmed AbdelTawab AbdelGawad
% Package:      Analysis Package
% Inputs:	    modelObjectsStructVector
%               modelObjectsValuesMatrix
%               initialTime
%               finalTime
%               timeStepLength
%               internalSteps
% Outputs:	    N/A
% Description:  The main function in the Analysis package, it calls all the
%               other functions, and executes the steps of the eigenvalue
%               analysis
% -------------------------------------------------------------------------

disp( [ sprintf('\n') 'Starting Analysis' ]);

% Extract Model Objects
[ numLevels , numAuxiliaries , modelObjectsNamesVector , modelObjectsEquationsVector ] = ...
    extractModelObjects( modelObjectsStructVector );

% Empty and Initialize checkpoint (0)
fid = fopen( [ 'checkpoint_0.csv' ] , 'w' );
fwrite( fid , [ 'This checkpoint file generated by "findDominantEigenvalue.m" at the end of the file,' sprintf('\n') ] );
fwrite( fid , [ 'it contains the following:' sprintf('\n') ] );
fwrite( fid , [ 'it computes the error (E) and percentage error (PE)' sprintf('\n') ] );
fwrite( fid , [ 'between the absolute value of:' sprintf('\n') ] );
fwrite( fid , [ 'next time step State Vector X(t+1),' sprintf('\n') ] );
fwrite( fid , [ 'the one comes from simulation' sprintf('\n') ] );
fwrite( fid , [ 'and the computed one from the (alpha / lambda) * exp(lambda * dt) equations ...' sprintf('\n\n') ] );
fwrite( fid , [ 'Time;' ] );
for I = 1 : numLevels,
    fwrite( fid , [ 'E (X' num2str( I ) ');PE (X' num2str( I ) ');' ] );
end
fwrite( fid , [ sprintf('\n\n') ] );
fclose( fid );

% Empty and Initialize checkpoint (1)
fid = fopen( [ 'checkpoint_1.csv' ] , 'w' );
fwrite( fid , [ 'This checkpoint file generated by "findDominantEigenvalue.m" at the end of the file,' sprintf('\n') ] );
fwrite( fid , [ 'it contains the following:' sprintf('\n') ] );
fwrite( fid , [ 'it computes the error (E) and percentage error (PE)' sprintf('\n') ] );
fwrite( fid , [ 'between the absolute value of:' sprintf('\n') ] );
fwrite( fid , [ 'next time step Slope Vector X dot(t+1),' sprintf('\n') ] );
fwrite( fid , [ 'the one comes from simulation' sprintf('\n') ] );
fwrite( fid , [ 'and the computed one from the alpha * exp(lambda * dt) equations ...' sprintf('\n\n') ] );
fwrite( fid , [ 'Time;' ] );
for I = 1 : numLevels,
    fwrite( fid , [ 'E (X' num2str( I ) ''');PE (X' num2str( I ) ''');' ] );
end
fwrite( fid , [ sprintf('\n\n') ] );
fclose( fid );

% Empty and Initialize checkpoint (2)
fid = fopen( [ 'checkpoint_2.csv' ] , 'w' );
fwrite( fid , [ 'This checkpoint file generated by "computeLinkElasticity.m" at the end of the file,' sprintf('\n') ] );
fwrite( fid , [ 'it contains the following:' sprintf('\n') ] );
fwrite( fid , [ 'for every time step:' sprintf('\n') ] );
fwrite( fid , [ 'The error between sum of row( i ) and column( i ) of' sprintf('\n')] );
fwrite( fid , [ 'the compact Elasticity values matrix, also the percentage error (PE).' sprintf('\n')] );
fwrite( fid , [ '(they should be the same, for any Level the Elasticity value entering' sprintf('\n') ] );
fwrite( fid , [ 'should be the same value leaving (Forrester, N., 1983))' sprintf('\n\n') ] );
fwrite( fid , [ 'Time;' ] );
for I = 1 : numLevels,
    fwrite( fid , [ 'E (r&c' num2str( I ) ');PE (r&c' num2str( I ) ');' ] );
end
fwrite( fid , [ sprintf('\n\n') ] );
fclose( fid );

% Empty and Initialize checkpoint (3)
fid = fopen( [ 'checkpoint_3.csv' ] , 'w' );
fwrite( fid , [ 'This checkpoint file generated by "computeLinkElasticity.m" at the end of the file,' sprintf('\n')] );
fwrite( fid , [ 'it contains the following:' sprintf('\n') ] );
fwrite( fid , [ 'for every time step:' sprintf('\n') ] );
fwrite( fid , [ 'The sum of all elements of the compact Elasticity values matrix' sprintf('\n') ] );
fwrite( fid , [ '(should eqaul 1)' sprintf('\n\n') ] );
fwrite( fid , [ 'Time;SUM(E)' sprintf('\n\n') ] );
fclose( fid );

% Empty and Initialize checkpoint (4)
fid = fopen( [ 'checkpoint_4.csv' ] , 'w' );
fwrite( fid , [ 'This checkpoint file generated by "computeLinkElasticity.m" at the end of the file,' sprintf('\n') ] );
fwrite( fid , [ 'it contains the following:' sprintf('\n') ] );
fwrite( fid , [ 'for every time step:' sprintf('\n') ] );
fwrite( fid , [ 'The error between sum of row( i ) and column( i ) of' sprintf('\n') ] );
fwrite( fid , [ 'the full Elasticity values matrix, also the percentage error (PE).' sprintf('\n') ] );
fwrite( fid , [ '(they should be the same, for any variable (Level or Auxiliary) the' sprintf('\n') ] );
fwrite( fid , [ 'Elasticity value entering should be the same value leaving' sprintf('\n\n') ] );
fwrite( fid , [ 'Time;' ] );
for I = 1 : numLevels + numAuxiliaries,
    fwrite( fid , [ 'E (r&c' num2str( I ) ');PE (r&c' num2str( I ) ');' ] );
end
fwrite( fid , [ sprintf('\n\n') ] );
fclose( fid );

% Empty and Initialize checkpoint (5)
fid = fopen( [ 'checkpoint_5.csv' ] , 'w' );
fwrite( fid , [ 'This checkpoint file generated by "computeIndependentCycleElasticity.m" at the end of the file,' sprintf('\n') ] );
fwrite( fid , [ 'it contains the following:' sprintf('\n') ] );
fwrite( fid , [ 'numericLinkElasticityMatrixComputed = Cr * independentCyclesElasticityMatrix' sprintf('\n') ] );
fwrite( fid , [ 'error (E) = numericLinkElasticityMatrix - numericLinkElasticityMatrixComputed' sprintf('\n') ] );
fwrite( fid , [ 'and also the percentage error (PE) ...' sprintf('\n\n') ] );
fclose( fid );

% Empty and Initialize checkpoint (7)
fid = fopen( [ 'checkpoint_7.csv' ] , 'w' );
fwrite( fid , [ 'This checkpoint file generated by "computeLinkElasticity.m" at the end of the file,' sprintf('\n') ] );
fwrite( fid , [ 'it contains the following:' sprintf('\n') ] );
fwrite( fid , [ 'for every time step:' sprintf('\n') ] );
fwrite( fid , [ 'The error between sum of col( i ) and col( i ) of' sprintf('\n') ] );
fwrite( fid , [ 'the Elasticity values matrix and the full Elasticity values matrix respectively,' sprintf('\n') ] );
fwrite( fid , [ 'also the percentage error (PE).' sprintf('\n') ] );
fwrite( fid , [ '(they should be the same, for all Levels, the' sprintf('\n') ] );
fwrite( fid , [ 'Elasticity value entering any Level in both matrices should be the same value' sprintf('\n\n') ] );
fwrite( fid , [ 'Time;' ] );
for I = 1 : numLevels,
    fwrite( fid , [ 'E (r&c' num2str( I ) ');PE (r&c' num2str( I ) ');' ] );
end
fwrite( fid , [ sprintf('\n\n') ] );
fclose( fid );

% Empty and Initialize checkpoint (8)
fid = fopen( [ 'checkpoint_8.csv' ] , 'w' );
fwrite( fid , [ 'This checkpoint file generated by "computeLinkElasticity.m" at the end of the file,' sprintf('\n') ] );
fwrite( fid , [ 'it contains the following:' sprintf('\n') ] );
fwrite( fid , [ 'for every time step:' sprintf('\n') ] );
fwrite( fid , [ 'The error between sum of row( i ) and row( i ) of' sprintf('\n') ] );
fwrite( fid , [ 'the Elasticity values matrix and the full Elasticity values matrix respectively,' sprintf('\n') ] );
fwrite( fid , [ 'also the percentage error (PE).' sprintf('\n') ] );
fwrite( fid , [ '(they should be the same, for all Levels, the' sprintf('\n') ] );
fwrite( fid , [ 'Elasticity value leaving any Level in both matrices should be the same value' sprintf('\n\n') ] );
fwrite( fid , [ 'Time;' ] );
for I = 1 : numLevels,
    fwrite( fid , [ 'E (r&c' num2str( I ) ');PE (r&c' num2str( I ) ');' ] );
end
fwrite( fid , [ sprintf('\n\n') ] );
fclose( fid );

% Time Steps
numTimeSteps = ( ( finalTime - initialTime ) / timeStepLength ) + 1;

% Which level to study its behavior?
endLoop = true;
while ( endLoop )
    for I = 1 : numLevels,
        disp( [ int2str( I ) ' - ' char( modelObjectsNamesVector( I ) ) ] );
    end
    levels2Study = input( [ 'Enter the number of the level, you are intersted' sprintf('\n') 'in studying  (ex.: 2):' sprintf('\t') ] ); 
    if length( levels2Study ) ~= 1 | levels2Study > numLevels | levels2Study < 1,
        disp( 'Wrong Input(s), try again ...' );
    else
        endLoop = false;
    end
end

% Which constants are inputs?
endLoop = true;
while ( endLoop )
    for I = 1 : length( constantsVector ),
        disp( [ int2str( I ) ' - ' char( constantsVector( I ) ) ] );
    end
    inputs2Study = input( [ 'Enter the number of constants, you would like to' sprintf('\n') 'consider as inputs  (ex.: 30 or [ 1,2,3 ] or [ 1:50 ] ):' sprintf('\t') ] ); 
    if isempty( inputs2Study ),
        inputs2Study = [ 1 : length( constantsVector ) ];
        endLoop = false;
    elseif inputs2Study > length( constantsVector ) | max( inputs2Study ) > length( constantsVector ) | min(inputs2Study) < 1,
        disp( 'Wrong Input(s), try again ...' );
    else
        endLoop = false;
    end
end

% suggesting time steps to study according to Behavior Pattern Index
curvature = zeros( size( netflowsValuesMatrix( : , levels2Study ) ) );
curvature( 2:end ) = diff( netflowsValuesMatrix( : , levels2Study ) ) / timeStepLength;
BPI = sign( curvature( : ) ./ netflowsValuesMatrix( : , levels2Study ) );
if isnan( BPI( end ) ),
    endLoop = true;
    J = [ length( BPI ) ];
    I = length( BPI ) - 1;
    while( endLoop ),
        if ~isnan( BPI( I ) ),
            endLoop = false;
        else
            J = [ J , I ];
            I = I - 1;
        end
    end
    BPI( J ) = BPI( I );
end
endLoop = true;
J_All = find( isnan( BPI ) );
for K = J_All.',
    if isnan( BPI( K ) ),
        J = K;
        I = K + 1;
        while( endLoop ),
            if ~isnan( BPI( I ) ),
                endLoop = false;
            else
                J = [ J , I ];
                I = I + 1;
            end
        end
        BPI( J ) = BPI( I );
    end
end
BPI_spans = diff( BPI );
BPI_spans = find( abs( BPI_spans( : ) ) == 2 );
if isempty( BPI_spans ),
    BPI_spans = [ 1 ; numTimeSteps ];
elseif BPI_spans( 1 ) ~= 1,
    BPI_spans = [ 1 ; BPI_spans ];
elseif BPI_spans( end ) ~= numTimeSteps,
    BPI_spans = [ BPI_spans ; numTimeSteps ];
end
suggestedInternalStep = BPI_spans + [ round( diff( BPI_spans ) / 2 ) ; 0 ];
suggestedInternalStep( end ) = [];

% Plot the level selected to study
plot( modelObjectsValuesMatrix( 1 : numTimeSteps , levels2Study ) , 'LineWidth' , 2 );
set( gca , 'XTick' , BPI_spans );
set( gca , 'XTickLabel' , { num2str( round( ( BPI_spans - 1 ) * timeStepLength * 10 ) / 10 ) } );
set( gca , 'XGrid' , 'on' );
axis tight;
xlabel( 'time' );
title( char( modelObjectsNamesVector( levels2Study ) ) );

% Which time steps to study the selected level behavior at?
endLoop = true;
while ( endLoop )
    disp( [ 'Time Steps range is from 1 to ' int2str( numTimeSteps ) ] );
    disp( [ 'Corresponding to Time Instants range from ' num2str( initialTime ) ' to ' num2str( finalTime ) ] );
    disp( [ 'it is suggested to do analysis at the following time steps: ' sprintf('\n') int2str( suggestedInternalStep.' ) ] );
    disp( [ 'Corresponding to following time instants: ' sprintf('\n') num2str( [ ( suggestedInternalStep - 1 ) * timeStepLength ].' ) ] );
%     disp( [ 'Corresponding to Time Instants range from 1 to ' num2str( ( I - 1 ) * timeStepLength ) ] );
    internalSteps = input( [ 'Enter the time steps, you are intersted' sprintf('\n') 'in studying  (ex.: 30 or [ 1,2,3 ] or [ 1:50 ] ):' sprintf('\t') ] ); 
    if isempty( internalSteps ),
        internalSteps = [ 1 : numTimeSteps ];
        endLoop = false;
    elseif max( internalSteps ) > numTimeSteps | min(internalSteps) < 1,
        disp( 'Wrong Input(s), try again ...' );
    else
        endLoop = false;
    end
end

% Variables Initializations
checkpoint_0 = [];
checkpoint_1 = [];
checkpoint_2 = [];
checkpoint_4 = [];
% % % % % % checkpoint_6 = [];
checkpoint_7 = [];
checkpoint_8 = [];

dominantEigenvaluesMatrix = zeros( numTimeSteps , numLevels ); 
dominantEigenvaluesPositionMatrix = zeros( numTimeSteps , numLevels );
dominancePercentageMatrix = zeros( numTimeSteps , numLevels );
% Compute Jacobians of the model
[ symbolicFullGainMatrix , symbolicLinkGain2InputJacobianMatrix , modelAdjacencyMatrix , modelAdjacencyMatrix2EdgesMatrix ] = ...
    computeSystemJacobians( modelObjectsNamesVector , modelObjectsEquationsVector , constantsVector , constantsValuesVector , inputs2Study );

% Variables Initializations
numLinks = max( max( modelAdjacencyMatrix2EdgesMatrix ) );
numericLinkElasticityMatrix = zeros( numLinks , numTimeSteps );
numericLinkSensitivityByDominantEigenvalueMatrix = zeros( numLinks , numTimeSteps );
numericLinkGainMatrix = zeros( numLinks , numTimeSteps );
numericInputElasticityMatrix = zeros( length( inputs2Study ) , numTimeSteps );

% Finding Set Independent Loop
[ allCyclesVerticesMatrix , independentCyclesVerticesMatrix , independentCyclesEdgesMatrix , numberIndependentCycles ] = ...
    findIndependentCycles( modelAdjacencyMatrix , modelAdjacencyMatrix2EdgesMatrix , modelObjectsNamesVector ); 

% Variables Initializations
signIndependentCyclesMatrix = zeros( numTimeSteps , numberIndependentCycles );

% 'for loop' of the selected analysis time steps
for currentTimeStep = internalSteps ,
    disp( [ 'Step: ' , num2str( currentTimeStep ) ' of: ' , num2str( numTimeSteps ) ] );
    
    % Compute Numeric Full Gain Matrix and Numeric Link Gain to Input Jacobian Matrix
    tempSymbolicLinkGain2InputJacobianMatrix = ...
        subs( symbolicLinkGain2InputJacobianMatrix , sym('TIME') , currentTimeStep );
    numericLinkGain2InputJacobianMatrix = ...
        double( subs( tempSymbolicLinkGain2InputJacobianMatrix , modelObjectsNamesVector , modelObjectsValuesMatrix( currentTimeStep , : ) ) );
    tempSymbolicFullGainMatrix = ...
        subs( symbolicFullGainMatrix , sym('TIME') , ( currentTimeStep * timeStepLength ) + initialTime );
    numericFullGainMatrix = ...
        double( subs( tempSymbolicFullGainMatrix , modelObjectsNamesVector , modelObjectsValuesMatrix( currentTimeStep , : ) ) );
    
    % Polarity of Independent Cycles
    signIndependentCyclesMatrix( currentTimeStep , : ) = sign( computePathsGain( numericFullGainMatrix , independentCyclesVerticesMatrix ) );
    
    [ x , y ] = find( modelAdjacencyMatrix2EdgesMatrix ~= 0 );
    for I = 1 : length( x ),
        numericLinkGainMatrix( modelAdjacencyMatrix2EdgesMatrix( x( I ) , y( I ) ) , currentTimeStep ) = ...
            numericFullGainMatrix( x( I ) , y( I ) );
    end
    
    % The Compact Model Gain Matrix
    % [ A11          A12 ]
    % [                  ] 
    % [ A21          A22 ]
    % 
    %  m *           n * 
    %     m             m
    %
    %  m *           n * 
    %     n             n
    % 
    % m  = length( levelsVector )
    % n  = length( auxiliariesVector )
    % Note: A11 will always be a null matrix
    A12 = numericFullGainMatrix( 1 : numLevels , numLevels+1 : end );
    A21 = numericFullGainMatrix( numLevels+1 : end , 1 : numLevels );
    A22 = numericFullGainMatrix( numLevels+1 : end , numLevels+1 : end );
    numericCompactGainMatrix = A12 * inv( eye( size( A22 ) ) - A22 ) * A21;
    
    % Computing the eigenvalues and eigenvectors of the Compact Gain Matrix
    tempNumericCompactGainMatrix = sym( numericCompactGainMatrix , 'd' );
    [ rightEigenvectorsMatrix , diagonalEigenvaluesMatrix ] = eig( tempNumericCompactGainMatrix );
    rightEigenvectorsMatrix = double( rightEigenvectorsMatrix );
    diagonalEigenvaluesMatrix = double( diagonalEigenvaluesMatrix );
    leftEigenvectorsMatrix = inv( rightEigenvectorsMatrix ).';
    
    % Finding the dominant eigenvalue
    [ dominantEigenvaluesMatrix( currentTimeStep , : ) , dominantEigenvaluesPositionMatrix( currentTimeStep , : ) , dominancePercentageMatrix( currentTimeStep , : ) , tempCheckpoint_0 , tempCheckpoint_1 ] = ...
        findDominantEigenvalue( rightEigenvectorsMatrix , leftEigenvectorsMatrix , diagonalEigenvaluesMatrix , netflowsValuesMatrix( currentTimeStep , : ).' , netflowsValuesMatrix( currentTimeStep + 1 , : ).' , modelObjectsValuesMatrix( currentTimeStep , 1 : numLevels ).' , modelObjectsValuesMatrix( currentTimeStep + 1 , 1 : numLevels ).' , timeStepLength , levels2Study , currentTimeStep );
    checkpoint_0 = [ checkpoint_0 ; tempCheckpoint_0(:).' ];
    checkpoint_1 = [ checkpoint_1 ; tempCheckpoint_1(:).' ];
    
    % Computing the symbolic links elasticity values associated with the
    % dominant eigenvalue
    [ numericLinkElasticityMatrix( : , currentTimeStep ) , numericLinkSensitivityByDominantEigenvalueMatrix( : , currentTimeStep ) , tempCheckpoint_2 , tempCheckpoint_4  , tempCheckpoint_7 , tempCheckpoint_8 ] = ...
        computeLinkElasticity( numericCompactGainMatrix , numericFullGainMatrix , modelAdjacencyMatrix , modelAdjacencyMatrix2EdgesMatrix , rightEigenvectorsMatrix , leftEigenvectorsMatrix , diagonalEigenvaluesMatrix , dominantEigenvaluesPositionMatrix( currentTimeStep , 1 ) , currentTimeStep );
    checkpoint_2 = [ checkpoint_2 ; tempCheckpoint_2(:).' ];
    checkpoint_4 = [ checkpoint_4 ; tempCheckpoint_4(:).' ];
    checkpoint_7 = [ checkpoint_7 ; tempCheckpoint_7(:).' ];
    checkpoint_8 = [ checkpoint_8 ; tempCheckpoint_8(:).' ];
    
    % Computing the symbolic inputs elasticity values associated with the
    % dominant eigenvalue
    [ numericInputElasticityMatrix( : , currentTimeStep ) ] = ...
        computeInputElasticity( numericLinkGainMatrix( : , currentTimeStep ) , numericLinkGain2InputJacobianMatrix , numericLinkElasticityMatrix( : , currentTimeStep ) , constantsValuesVector , inputs2Study , numericLinkSensitivityByDominantEigenvalueMatrix( : , currentTimeStep ) );
   
end

% Computing independent cycles elasticity values associated with dominant
% eigenvalue
independentCyclesElasticityMatrix = ...
    computeIndependentCycleElasticity( independentCyclesEdgesMatrix , numericLinkElasticityMatrix );

% end checkpoint (0)
mean_checkpoint_0 = mean( checkpoint_0 , 1 );
mean_abs_checkpoint_0 = mean( abs( checkpoint_0 ) ,1 );
max_checkpoint_0 = max( checkpoint_0 , [] , 1 );
min_checkpoint_0 = min( checkpoint_0 , [] , 1 );
fid = fopen( [ 'checkpoint_0.csv' ] , 'a' );
fwrite( fid , [ sprintf('\n') 'Mean;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_checkpoint_0( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Mean Abs.;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_abs_checkpoint_0( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Max;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( max_checkpoint_0( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Min;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( min_checkpoint_0( I ) ) ';' ] );
end
fclose( fid );

% end checkpoint (1)
mean_checkpoint_1 = mean( checkpoint_1 , 1 );
mean_abs_checkpoint_1 = mean( abs( checkpoint_1 ) , 1 );
max_checkpoint_1 = max( checkpoint_1 , [] , 1 );
min_checkpoint_1 = min( checkpoint_1 , [] , 1 );
fid = fopen( [ 'checkpoint_1.csv' ] , 'a' );
fwrite( fid , [ sprintf('\n') 'Mean;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_checkpoint_1( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Mean Abs.;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_abs_checkpoint_1( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Max;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( max_checkpoint_1( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Min;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( min_checkpoint_1( I ) ) ';' ] );
end
fclose( fid );

% end checkpoint (2)
mean_checkpoint_2 = mean( checkpoint_2 , 1 );
mean_abs_checkpoint_2 = mean( abs( checkpoint_2 ) , 1 );
max_checkpoint_2 = max( checkpoint_2 , [] , 1 );
min_checkpoint_2 = min( checkpoint_2 , [] , 1 );
fid = fopen( [ 'checkpoint_2.csv' ] , 'a' );
fwrite( fid , [ sprintf('\n') 'Mean;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_checkpoint_2( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Mean Abs.;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_abs_checkpoint_2( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Max;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( max_checkpoint_2( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Min;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( min_checkpoint_2( I ) ) ';' ] );
end
fclose( fid );

% end checkpoint (4)
mean_checkpoint_4 = mean( checkpoint_4 , 1 );
mean_abs_checkpoint_4 = mean( abs( checkpoint_4 ) , 1 );
max_checkpoint_4 = max( checkpoint_4 , [] , 1 );
min_checkpoint_4 = min( checkpoint_4 , [] , 1 );
fid = fopen( [ 'checkpoint_4.csv' ] , 'a' );
fwrite( fid , [ sprintf('\n') 'Mean;' ] );
for I = 1 : 2 * ( numLevels + numAuxiliaries ),
    fwrite( fid , [ num2str( mean_checkpoint_4( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Mean Abs.;' ] );
for I = 1 : 2 * ( numLevels + numAuxiliaries ),
    fwrite( fid , [ num2str( mean_abs_checkpoint_4( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Max;' ] );
for I = 1 : 2 * ( numLevels + numAuxiliaries ),
    fwrite( fid , [ num2str( max_checkpoint_4( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Min;' ] );
for I = 1 : 2 * ( numLevels + numAuxiliaries ),
    fwrite( fid , [ num2str( min_checkpoint_4( I ) ) ';' ] );
end
fclose( fid );

% end checkpoint (7)
mean_checkpoint_7 = mean( checkpoint_7 , 1 );
mean_abs_checkpoint_7 = mean( abs( checkpoint_7 ) , 1 );
max_checkpoint_7 = max( checkpoint_7 , [] , 1 );
min_checkpoint_7 = min( checkpoint_7 , [] , 1 );
fid = fopen( [ 'checkpoint_7.csv' ] , 'a' );
fwrite( fid , [ sprintf('\n') 'Mean;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_checkpoint_7( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Mean Abs.;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_abs_checkpoint_7( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Max;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( max_checkpoint_7( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Min;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( min_checkpoint_7( I ) ) ';' ] );
end
fclose( fid );

% end checkpoint (8)
mean_checkpoint_8 = mean( checkpoint_8 , 1 );
mean_abs_checkpoint_8 = mean( abs( checkpoint_8 ) , 1 );
max_checkpoint_8 = max( checkpoint_8 , [] , 1 );
min_checkpoint_8 = min( checkpoint_8 , [] , 1 );
fid = fopen( [ 'checkpoint_8.csv' ] , 'a' );
fwrite( fid , [ sprintf('\n') 'Mean;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_checkpoint_8( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Mean Abs.;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( mean_abs_checkpoint_8( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Max;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( max_checkpoint_8( I ) ) ';' ] );
end
fwrite( fid , [ sprintf('\n') 'Min;' ] );
for I = 1 : 2 * numLevels,
    fwrite( fid , [ num2str( min_checkpoint_8( I ) ) ';' ] );
end
fclose( fid );

% Printing to output file
printOutputs( levels2Study , inputs2Study , modelAdjacencyMatrix , internalSteps , timeStepLength , dominantEigenvaluesMatrix , dominancePercentageMatrix , numericLinkGainMatrix , numericLinkElasticityMatrix , numericInputElasticityMatrix , independentCyclesElasticityMatrix , allCyclesVerticesMatrix , independentCyclesVerticesMatrix , signIndependentCyclesMatrix , modelObjectsNamesVector , constantsVector , outFileName );

disp( [ sprintf( '\n' ) 'Finishing Analysis' ] );

Contact us