# How to quantify time-dependent network flexibility in igraph

**URL:** <https://igraph.discourse.group/t/how-to-quantify-time-dependent-network-flexibility-in-igraph/843>\
**Category:** Usage\
**Tags:** Python\
**Created:** [5 September 2021 15:47 UTC](https://igraph.discourse.group/t/how-to-quantify-time-dependent-network-flexibility-in-igraph/843 "2021-09-05T15:47:08Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![balandongiv](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/balandongiv/32/553_2.png) [@balandongiv](https://igraph.discourse.group/u/balandongiv)\
**Post date:** [7 September 2021 14:20 UTC](https://igraph.discourse.group/t/how-to-quantify-time-dependent-network-flexibility-in-igraph/843/5 "2021-09-07T14:20:15Z")

</div>

Thanks for the confirmation [@vtraag](https://igraph.discourse.group/u/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](https://github.com/makism/dyconnmap/blob/abe5cc10d2ddcde8526e9bf517861c5955d983ad/dyconnmap/chronnectomics/flexibility_index.py)

```auto
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])]

```

---

_[View the full topic](https://igraph.discourse.group/t/how-to-quantify-time-dependent-network-flexibility-in-igraph/843)._
