%US state MDS (weighted correlations) 

cors=weightedcorrs(myset, w);
A=cors;
n=size(cors,2);

%Select threshold
threshold=0.75;

A(A <= threshold) = 0;
A(A > threshold) = 1;


%Identify the T-MDS---------------------------------
n=length(A);
f = ones(1,n); 
b=ones(n,1); 
intcon=1:n;
lb=zeros(n,1);
ub=ones(n,1);
[x,fval,exitflag,output]= intlinprog(f,intcon,-A,-b,[],[],lb,ub);
S = find(x);
%------------------------------------------- 

%Number of isolated nodes and which ones
s=sum(A);
NoofIsol=sum(s(:) == 1); 
Isolated=find(s==1);
Nodedegree=(s-1)';

%find dominant nodes
x2=x;
x2(Isolated)=0;
domnumbers=find(x2==1);
domstates=labels(domnumbers)';

%Calculate average node gegree 
cors2=cors;
cors2(cors2 <= threshold) = 0;
cors2=cors2-eye(n);
NoofEdges=(nnz(cors2))/2;
avgdegree=(2*NoofEdges)/n; %n is the number of states
CompleteEdges=(n*(n-1))/2;
Density=NoofEdges/CompleteEdges;
minmaxcors(1)=min(min(cors));
corstemp=cors-eye(n);
minmaxcors(2)=max(max(corstemp));

%calculate average correlation coefficient
cors3=cors;
cors3(cors3<0)=0;
count=0;
sumcors=0;
for i=1:n^2
    if cors3(i)>0 
        count=count+1;
        sumcors=sumcors+cors3(i);
    end
end
avgcor=sumcors/count;
