Skip to main content

Python implementation of the LAGO method for dynamic community detection in temporal networks. Derived functions such as the Longitudinal Modularity are also provided.

Project description

Dynamic Community Detection: LAGO

This library is a python implementation of the LAGO method for dynamic community detection on temporal networks.

Getting started using pip

pip install dcd-lago

Link Streams and Dynamic Communities

Link stream (or stream graph) model enables temporal network to have perfect temporal precision of temporal links (also called edges or interactions).

Community detection is an essential task in static network analysis. It consists in grouping nodes so there is more edges within groups than between them. Adapating this task to temporal networks means that groups may evolve over time and yet be consistent over time. We call this task Dynamic Community Detection.

Link Stream example with two dynamic communities

Figure 1: Link stream made up of 5 nodes (a, ...,e) with time interactions over time represented with vertical dashed lines. Two dynamic communities are displayed in blue and green.

LAGO (Longitudinal Agglomerative Greedy Optimization) is a method to detect dynamic communities on link streams which is inspired from most used community detection methods on static graphs. It is based on the greedy optimization of the Longitudinal Modularity, an adaptation of the Modularity quality function for communities on static networks.

Usage

from lago import LinkStream, lago_communities
## Declare time links according to the following format:
# <source node>, <target node>, <time instant>
## Values must be integers

time_links = [
    [2, 3, 0],
    [0, 1, 2],
    [2, 3, 3],
    [3, 4, 5],
    [2, 3, 6],
    [2, 4, 7],
    [0, 1, 8],
    [1, 2, 9],
    [3, 4, 9],
    [0, 2, 10],
    [1, 2, 11],
    [3, 4, 13],
    [1, 2, 14],
    [2, 4, 16],
    [0, 1, 17],
    [0, 1, 18],
    [2, 3, 18],
    [3, 4, 19],
]
## Initiate empty temporal network (as a link stream)
my_linkstream = LinkStream()

## Add time links to the link stream
my_linkstream.add_links(time_links)

# NOTE time links can also be imported from txt files with the read_txt() method

## Display linkstream informations
print(f"The link stream consists of {my_linkstream.nb_edges} temporal edges (or time links) accross {my_linkstream.nb_nodes} nodes and {my_linkstream.network_duration} time steps, of which only {my_linkstream.nb_timesteps} contain activity.")
## Compute dynamic communities
dynamic_communities = lago_communities(
    my_linkstream,
    nb_iter=3, # run LAGO 3 times and return best result
    )

# Each dynamic community is represented by a list of (<node>, <time instant>)

print(f"{len(dynamic_communities)} dynamic communities have been found")

Plot Dynamic Communities

from lago import plot_dynamic_communities

fig = plot_dynamic_communities(
        linkstream=my_linkstream,
        communities=dynamic_communities,
    )
fig.show()

Compute Longitudinal Modularity Score

from lago import longitudinal_modularity

## Compute Longitudinal Modularity score
## (the higher the better / maximum is 1)
long_mod_score = longitudinal_modularity(
    my_linkstream, 
    dynamic_communities,
    )

print(f"Dynamic communities detected on the linkstream have a Longitudinal Modularity score of {long_mod_score} ")

Advanced Parameters

LAGO is a greedy method for optimizing Longitudinal Modularity, which is a quality function for dynamic communities on temporal networks. Both have many options which affects both speed and communities shapes.

Longitudinal Modularity

lex (Longitudinal Expectation): Can be either Joint-Membership (JM) or Mean-Membership (MM). From a theoretical aspect, JM expects dynamic communities to have a very consistent duration of existence, whereas MM allows greater freedom in the temporal evolution of communities. Authors lack perspective on the impact of the choice on real data. Defaults to "MM".

omega: Time resolution Parameter indicating the required level of community continuity over time. Higher values lead to more smoothness in communities changes. Defaults to 2.

LAGO

refinement: In greedy search optimization, a refinement strategy can improve results but increases computation time. Defaults to STEM.

Refinement Improvement Time of execution
None - -
Single Time Node Movements (STNM) + +
Single Time Edge Movements (STEM) ++ ++

refinement_in: Whether to apply refinement strategy within the main optimization loop or not. If activated, results may be improved but requires more computation time. Defaults to True.

fast_exploration: lighter exploration loop. If activated, it significantly reduces the time of execution but may result in poorer results. Defaults to True.

Feedback

LAGO method and the python library are constantly improving. If you have any questions, suggestions or issues, please add them to GitHub issues.

References

LAGO Method

Discovering Communities in Continuous-Time Temporal Networks by Optimizing L-Modularity (preprint)

@misc{brabant2025discoveringcommunitiescontinuoustimetemporal,
      title={Discovering Communities in Continuous-Time Temporal Networks by Optimizing L-Modularity}, 
      author={Victor Brabant and Angela Bonifati and Rémy Cazabet},
      year={2025},
      eprint={2510.00741},
      archivePrefix={arXiv},
      primaryClass={cs.SI},
      url={https://arxiv.org/abs/2510.00741}, 
}

Longitudinal Modularity

Longitudinal Modularity, a Modularity for Link Streams

@article{Brabant2025,
  title = {Longitudinal modularity,  a modularity for link streams},
  volume = {14},
  ISSN = {2193-1127},
  url = {http://dx.doi.org/10.1140/epjds/s13688-025-00529-x},
  DOI = {10.1140/epjds/s13688-025-00529-x},
  number = {1},
  journal = {EPJ Data Science},
  publisher = {Springer Science and Business Media LLC},
  author = {Brabant,  Victor and Asgari,  Yasaman and Borgnat,  Pierre and Bonifati,  Angela and Cazabet,  Rémy},
  year = {2025},
  month = feb 
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dcd_lago-1.0.2.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dcd_lago-1.0.2-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file dcd_lago-1.0.2.tar.gz.

File metadata

  • Download URL: dcd_lago-1.0.2.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for dcd_lago-1.0.2.tar.gz
Algorithm Hash digest
SHA256 4e053b8c694019c7944aa14c9e040e8bc6b1b4bcdd27988700d119a5418ec2c5
MD5 d089a5cef87dbaeb80f8de0651bad24e
BLAKE2b-256 3f8d2bd0632bc655147776158b3f5573dfb017d5813bca3c7e547d9c4b970a47

See more details on using hashes here.

File details

Details for the file dcd_lago-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: dcd_lago-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for dcd_lago-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2f0ac3851b4d31b2d782fb2381efaf33f05d3d8ab9320098bd9c1fa93866844c
MD5 1012838a6f4e99a23df4633dde10ca72
BLAKE2b-256 b3ea34ca59c3c83747926f538b0aeb3317aa222b2c9a7d2ace0ce315cb27a082

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page