Coder Social home page Coder Social logo

Comments (2)

wiheto avatar wiheto commented on June 23, 2024

I do not fully understand the following code (because of variable names):

staticcommunities= teneto.communitydetection.temporal_louvain(G, intersliceweight=0.1, n_iter=1)

Does not look like this is "staticcommunities".

Also, the teneto communitydetection's intersliceweight is not necessarily in line with some other implementations. Something I've needed to look back on but never had the time.

But in essence this looks fine.

If you think something is wrong, let me know.

from teneto.

balandongiv avatar balandongiv commented on June 23, 2024

Thanks for the quick response. I had amended the variables names for clarity.

But, upon Googling, I found there is a dedicated function to measure 'consensus_iterative' written in Matlab from this weebly website.

function [S2, Q2, X_new3, qpc] = consensus_iterative(C)
%CONSENSUS_ITERATIVE     Construct a consensus (representative) partition
%using the iterative thresholding procedure
%
%   [S2 Q2 X_new3 qpc] = CONSENSUS_ITERATIVE(C) identifies a single
%   representative partition from a set of C partitions, based on
%   statistical testing in comparison to a null model. A thresholded nodal
%   association matrix is obtained by subtracting a random nodal
%   association matrix (null model) from the original matrix. The
%   representative partition is then obtained by using a Generalized
%   Louvain algorithm with the thresholded nodal association matrix.
%
%   NOTE: This code requires genlouvain.m to be on the MATLAB path
%
%   Inputs:     C,      pxn matrix of community assignments where p is the
%                       number of optimizations and n the number of nodes
%
%   Outputs:    S2,     pxn matrix of new community assignments
%               Q2,     associated modularity value
%               X_new3, thresholded nodal association matrix
%               qpc,    quality of the consensus (lower == better)
%               
%
%   Bassett, D. S., Porter, M. A., Wymbs, N. F., Grafton, S. T., Carlson,
%   J. M., & Mucha, P. J. (2013). Robust detection of dynamic community
%   structure in networks. Chaos: An Interdisciplinary Journal of Nonlinear
%   Science, 23(1), 013142.

npart = numel(C(:,1)); % number of partitions
m = numel(C(1,:)); % size of the network

% initialize
C_rand3 = zeros(size(C)); % permuted version of C
X = zeros(m,m); % Nodal association matrix for C
X_rand3 = X; % Random nodal association matrix for C_rand3

%% NODAL ASSOCIATION MATRIX

% try a random permutation approach
for i = 1:npart;
    pr = randperm(m);
    C_rand3(i,:) = C(i,pr); % C_rand3 is the same as C, but with each row permuted
end

% Calculate the nodal association matrices X and
% X_rand3
for i = 1:npart;
    ii=i
    tic
    for k = 1:m
        for p = 1:m;
            % element (i,j) indicate the number of times node i and node j
            % have been assigned to the same community
            if isequal(C(i,k),C(i,p))
                X(k,p) = X(k,p) + 1;
            else
                X(k,p) = X(k,p) + 0;
            end
            
            % element (i,j) indicate the number of times node i and node j
            % are expected to be assigned to the same community by chance
            if isequal(C_rand3(i,k),C_rand3(i,p))
                X_rand3(k,p) = X_rand3(k,p)+1;
            else
                X_rand3(k,p) = X_rand3(k,p)+ 0;
            end
        end
    end
    toc
end

%% THRESHOLDING
% keep only associated assignments that occur more often than expected in
% the random data
X_new3 = zeros(m,m);
X_new3(X>max(max(triu(X_rand3,1)))) = X(X>max(max(triu(X_rand3,1))));

%% GENERATE THE REPRESENTATIVE PARTITION
% recompute optimal partition on this new matrix of kept community
% association assignments
for i = 1:npart;
    ii=i
    [S2(i,:) Q2(i)] = multislice_static_unsigned(X_new3,1);
end

% define the quality of the consensus
qpc = sum(sum(abs(diff(S2))));

Now im confuse whether it is correct to get the consensus partition using the line below

# Get the community/consensus partition
communities_static= teneto.communitydetection.temporal_louvain(tnet_static, intersliceweight=0.1, n_iter=1)

or using the logic as in the consensus_iterative.

Sorry for out-topic question, but appreciate if you can share some insight to a beginner like myself

from teneto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.