Home > matpower7.0 > extras > syngrid > lib > nsw_clusterSW_clstrs.m

nsw_clusterSW_clstrs

PURPOSE ^

PURPOSE: analyze and show the correlation between node degree and node

SYNOPSIS ^

function [clsts,clsts_size,n_clsts] = nsw_clusterSW_clstrs(nodes_rwd,d0,n,nodes_rwd_list)

DESCRIPTION ^

 PURPOSE:  analyze and show the correlation between node degree and node
           rewires.
 USAGE:
 INPUTS:
           link_ids - the link list;
           nodes_rwd - vector (n by 1): rewires count for each node
           n - total number of nodes
           d0  -  distance criteria to decide a rewired link;
 OUTPUTS:  co_degrwd - correlation coefficient between node degrees and
                       rewires count.

 by wzf, 2008

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [clsts,clsts_size,n_clsts] = nsw_clusterSW_clstrs(nodes_rwd,d0,n,nodes_rwd_list)
0002 % PURPOSE:  analyze and show the correlation between node degree and node
0003 %           rewires.
0004 % USAGE:
0005 % INPUTS:
0006 %           link_ids - the link list;
0007 %           nodes_rwd - vector (n by 1): rewires count for each node
0008 %           n - total number of nodes
0009 %           d0  -  distance criteria to decide a rewired link;
0010 % OUTPUTS:  co_degrwd - correlation coefficient between node degrees and
0011 %                       rewires count.
0012 %
0013 % by wzf, 2008
0014 
0015 %   SynGrid
0016 %   Copyright (c) 2008, 2017-2018, Electric Power and Energy Systems (EPES) Research Lab
0017 %   by Zhifang Wang, Virginia Commonwealth University
0018 %
0019 %   This file is part of SynGrid.
0020 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0021 
0022 if(isempty(nodes_rwd) && nargin ==4)
0023     pos = nodes_rwd_list;
0024 else
0025     pos = find(nodes_rwd>0);
0026 end
0027 if(isempty(pos))
0028     return;
0029 end
0030 clsts={};clsts_size =[];
0031 k=1;cls_k=[];last = 0;
0032 while(~isempty(pos))
0033     if(last ==0 || pos(1)==last+1)
0034         last = pos(1); %append this node to current cluster
0035         cls_k = [cls_k last];
0036     else
0037         clsts{k,1}=cls_k;
0038         clsts_size = [clsts_size; length(cls_k)];
0039         last = pos(1);
0040         k=k+1; cls_k =[last]; % start a new cluster
0041     end
0042     pos = pos(2:length(pos));
0043 end
0044 clsts{k,1}=cls_k;clsts_size = [clsts_size; length(cls_k)];
0045 %k=k-1;
0046 % cls_1 = clsts{1};
0047 % cls_k = clsts{k};
0048 % if( k>1 & any(cls_1==1) & any(cls_k==n))
0049 %     clsts{1}=[cls_k cls_1 ];
0050 %     clsts_size(1)=clsts_size(1)+clsts_size(k);
0051 %     clsts = clsts{1:k-1,:};
0052 %     clsts_size = clsts_size(1:k-1);
0053 %     k = k-1;
0054 % end
0055 n_clsts = k;
0056 
0057 % plot the results
0058 plot_result = 0; % whether to show the figure or not
0059 if(plot_result)
0060     disp([num2str(n_clsts),' clusters are shown below:']);
0061     meansize_txt = ['mean of cluster size =',num2str(mean(clsts_size))];
0062     disp(meansize_txt);
0063     for k=1:n_clsts
0064         str1 = sprintf('%3.0f-cluster (%3.0f node(s)):',k , clsts_size(k));
0065         form2 = [];
0066         for m = 1:clsts_size(k)
0067             form2 = [form2,'%7.0f '];
0068         end
0069         str2 = sprintf(form2,clsts{k}');
0070         %str3 = ['      (total: ',num2str(clsts_size(k)),' node(s))'];
0071         disp([str1, str2]);
0072     end
0073     figure; hist(clsts_size,1:max(clsts_size)+1);
0074     xlabel('cluster size'); ylabel('n_c_l');
0075     title(meansize_txt);
0076 end

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005