Home > utilities > sdpastats.m

# sdpastats

## PURPOSE

SDPASTATS gets some statistics (& vision) how the given SDPA problem looks

## SYNOPSIS

function []=sdpastats(filename)

## DESCRIPTION

     SDPASTATS gets some statistics (& vision) how the given SDPA problem looks
     for example:
        sdpastats('datafiles/arch0.dat-s');

## CROSS-REFERENCE INFORMATION

This function calls:

- readsdpa READSDPA - Read a linear SDP problem from a Sparse SDPA file

This function is called by:

## SUBFUNCTIONS

- function [der]=sparsetype(der,A)

## SOURCE CODE

    0001 function []=sdpastats(filename)
    0002 % SDPASTATS gets some statistics (& vision) how the given SDPA problem looks
    0003 % for example:
    0004 %    sdpastats('datafiles/arch0.dat-s');
    0005
    0006 % This file is a part of PENLAB package distributed under GPLv3 license
    0007 % Copyright (c) 2013 by  J. Fiala, M. Kocvara, M. Stingl
    0008 % Last Modified: 27 Nov 2013
    0009
    0010   % read the file in
    0011   disp(['Reading the input file: ',filename]);
    0012   tic;
    0013   sdpdata=readsdpa(filename);
    0014   toc
    0015   Nx=sdpdata.Nx;
    0016   Na=sdpdata.Na;
    0017
    0018   % create nonzero pattern of all matrices in A
    0019   A=cell(Na,1);
    0020   Ader=cell(Na,1);
    0021   Adim=zeros(Na,1);
    0022   Adep=zeros(Na,1);
    0023   dim=0;
    0024   rowall=[];
    0025   colall=[];
    0026   for k=1:Na
    0027     Akx=spones(sdpdata.A{k,1});
    0028     Ader{k}=zeros(5,1);
    0029     for i=sdpdata.Adep{k}
    0030       Akx = Akx + spones(sdpdata.A{k,i+1});
    0031       Ader{k}=sparsetype(Ader{k},sdpdata.A{k,i+1});
    0032     end
    0033     %figure;spy(Akx);
    0034     n=size(Akx,1);
    0035     A{k}=Akx;
    0036     Adep(k)=length(sdpdata.Adep{k});
    0037     Adim(k)=n;
    0038     [row,col]=find(Akx);
    0039     rowall=[rowall;row+dim];
    0040     colall=[colall;col+dim];
    0041     dim=dim+n;
    0042   end
    0043
    0044   Aall=sparse(rowall,colall,ones(size(rowall)),dim,dim);
    0045   %figure;
    0046   spy(Aall);
    0047
    0048   fprintf('Nx = %5i,  NA = %5i\n',Nx,Na);
    0049   fprintf('  k:   dim sparsity  #dep    %%dep  |  <5%% <10%% <25%% <50%% >50%%\n');
    0050   for k=1:Na
    0051     sparsity=nnz(A{k})/Adim(k)/Adim(k)*100;
    0052     pct=Adep(k)/Nx*100;
    0053     fprintf('%3i: %5i  %5.1f%%  %5i  %5.1f%%  | %4i %4i %4i %4i %4i\n',k,Adim(k),sparsity,Adep(k),pct,Ader{k});
    0054   end
    0055
    0056 end
    0057
    0058 %%%%%
    0059 % count which 'category' the given matrix falls into w.r.t. its density
    0060 % categoriesL: 5%, 10%, 25%, 50%, >50%
    0061 function [der]=sparsetype(der,A)
    0062   nz=nnz(A);
    0063   n=size(A,1);
    0064   nnzmax=n*n;
    0065   if (nz<0.05*nnzmax)
    0066     der(1)=der(1)+1;
    0067   elseif (nz<0.1*nnzmax)
    0068     der(2)=der(2)+1;
    0069   elseif (nz<0.25*nnzmax)
    0070     der(3)=der(3)+1;
    0071   elseif (nz<0.5*nnzmax)
    0072     der(4)=der(4)+1;
    0073   else
    0074     der(5)=der(5)+1;
    0075   end
    0076 end
    0077