Skip to main content

Python implementation of the LAGO method...

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.4.tar.gz (21.2 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.4-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dcd_lago-1.0.4.tar.gz
  • Upload date:
  • Size: 21.2 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.4.tar.gz
Algorithm Hash digest
SHA256 79aae949a54d1a154085cfcdec9904335571b64c5db80453788a91cd1cefc950
MD5 7af13b0da6f7627a1822f5e49da11c5c
BLAKE2b-256 1b578d1e10589a8c3fb6804eae5f5a45c808c137d615daae77c46278393a5dc7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dcd_lago-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 28.0 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 56a3712b1789091075c60f60d1f89cc34d082a0af299acf5ee19e7ad62ff67bb
MD5 97d62f9f8e807f0fdc23d288bed68c71
BLAKE2b-256 68fbcf5224d97cd50dd29e20feeda98c489f13d5afc36636999df7a0f6fcb4a6

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