How to quantify time-dependent network flexibility in igraph

Thanks for the confirmation @vtraag.

For future reader, the flexibility for membership produced by find_partition_temporal can be calculated with code attach at the bottom of this thread.

For future reader on how to calculate flexibility

Idea based on maksim/dyconnmap package :

github.com

import leidenalg as la
import igraph as ig
import numpy as np

A1 = np.array ( [[0., 0., 0., 0., 0, 0, 0], [5., 0., 0., 0., 0, 0, 0], [1., 0., 0., 0., 0, 0, 0],
                 [0., 1., 2., 0., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0],
                 [0., 0., 0., 0., 1, 1, 0]] )

A2 = np.array ( [[0., 0., 0., 0., 0, 0, 0], [5., 0., 0., 0., 0, 0, 0], [1., 0., 0., 0., 0, 0, 0],
                 [0., 1., 2., 0., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0], [0., 0., 1., 1., 0, 0, 0],
                 [0., 0., 0., 0., 1, 1, 0]] )

A3 = np.array ( [[0., 0., 0., 0., 0, 0, 0], [0., 0., 0., 0., 0, 0, 0], [0., 0., 0., 0., 0, 0, 0],
                 [0., 1., 2., 0., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0], [0., 0., 0., 1., 0, 0, 0],
                 [0., 0., 0., 0., 1, 1, 0]] )

G_1 = ig.Graph.Weighted_Adjacency ( A1.tolist () )
G_2 = ig.Graph.Weighted_Adjacency ( A2.tolist () )
G_3 = ig.Graph.Weighted_Adjacency ( A3.tolist () )
G_1.vs ['id'] = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
G_2.vs ['id'] = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
G_3.vs ['id'] = ['A', 'B', 'C', 'D', 'E', 'F', 'G']



gamma = 0.05
membership, improvement = la.find_partition_temporal ( [G_1, G_2, G_3], la.CPMVertexPartition,
                                                       interslice_weight=0.1, resolution_parameter=gamma )
ntime_membership=np.array(membership)

def flexibility_index (x):

    l = len ( x )

    counter = 0
    for k in range ( l - 1 ):
        if x [k] != x [k + 1]:
            counter += 1

    fi = counter / np.float32 ( l - 1 )

    return fi

flexibility_accross_time=[ flexibility_index (ntime_membership[:,x]) for x in range(ntime_membership.shape[1])]