function [Rm,R] = NeighbourhoodComplexity(A)
% Produces the neighbourhood complexity of a graph
% INPUT: A- Adjacency matrix of a simple graph
%
% OUTPUT: Rm- The neighbourhood complexity of the graph
% R- The set of neighbourhood complexities of given degree for the graph
%
% Citation:
% K. Smith, J. Escudero, "The Complex Hierarchical Topology of EEG
% Functional Connectivity", Journal of Neuroscience Methods, under review 2016.
%
% Keith Smith and Javier Escudero Rodriguez
% k.smith@ed.ac.uk and javier.escudero@ed.ac.uk
%
% 1-Nov-2016
degrees = sum(A);
counter = 0;
for i = min(degrees(degrees>0)):max(degrees)
if sum(degrees == i) > 1
comp = [];
counter = counter + 1;
B = A(degrees == i,:); % finds nodes of equal degree i
for j = 1:size(B,1)
comp(j,:) = sort(sum(A(B(j,:) == 1,:)'),2);
R(counter) = mean(var(comp)/(length(A)-1)); % Computes Neighbourhood Complexity of i degree nodes
end
end
end
Rm = mean(R); % Global Neighbourhood Complexity