No project description provided
Project description
Network Community Detection and Visualization
This repository provides a set of functions to perform community detection on networks using algorithms like Girvan-Newman and Louvain. Additionally, it includes utilities to calculate modularity and visualize the detected communities with various layouts.
Functions Overview
1. calculate_modularity(G, partition)
This function calculates the modularity of a given partition of a graph G. Modularity is a measure of the strength of division of a network into communities.
-
Parameters:
G(networkx.Graph): The input graph.partition(list of sets or dict): The partition of the graph where each set (or dict) represents a community.
-
Returns:
float: The modularity score.
2. get_modularity(G, partition)
This function calculates the modularity of the current partition using an alternative method based on node degrees and community assignments.
-
Parameters:
G(networkx.Graph): The graph for which modularity is to be calculated.partition(dict): A dictionary where keys are nodes and values are community labels.
-
Returns:
float: The modularity score.
3. local_optimization_step(H, Q_max)
This function performs a local optimization step on the graph to maximize modularity by moving nodes to neighboring communities.
-
Parameters:
H(networkx.Graph): The graph with community assignments as node attributes.Q_max(float): The current maximum modularity.
-
Returns:
float: The updated maximum modularity after the optimization step.
4. network_aggregation_step(H)
This function performs the network aggregation step by collapsing communities into super-nodes and recalculating edge weights between communities.
-
Parameters:
H(networkx.Graph): The graph where each node has a 'community' attribute.
-
Returns:
networkx.Graph: A new graph where nodes represent communities from the previous step.
5. reindex_communities(partition)
This function reindexes the communities in the partition so that community labels are continuous.
-
Parameters:
partition(dict): A dictionary where keys are nodes and values are community labels.
-
Returns:
dict: A new partition where community labels are reindexed.
6. louvain_method(G, init=None)
This function runs the Louvain method for community detection on a graph.
-
Parameters:
G(networkx.Graph): The input graph where nodes and edges define the structure.init(dict): Optional initial partition.
-
Returns:
dict: The final partition of the graph with node assignments to communities.
7. vis_network_spring(G, best_partition, layout_type="spring_layout")
This function visualizes a network with a specified layout, coloring nodes by community.
-
Parameters:
G(networkx.Graph): The graph to visualize.best_partition(dict): A partition of the graph nodes (community assignments).layout_type(str): The layout algorithm to use. Options are "spring_layout", "shell_layout", and "kamada_kawai_layout".
-
Returns:
None: Displays the network graph.
8. vis_network_agg_spring(G, best_partition, layout1="shell_layout", iterations=1)
This function visualizes a network using an aggregated layout approach. The first layout is either 'shell_layout' or 'kamada_kawai_layout', and the second layout is always 'spring_layout' for a specified number of iterations.
-
Parameters:
G(networkx.Graph): The graph to visualize.best_partition(dict): A partition of the graph nodes (community assignments).layout1(str): The first layout algorithm to use, either 'shell_layout' or 'kamada_kawai_layout'.iterations(int): The number of iterations for the 'spring_layout' adjustment.
-
Returns:
None: Displays the network graph.
9. vis_network_partition_process(G, pos=None, method="girvan_newman", w=5.0, h=4.0, nrows=6, ncols=6, iterations_limit=None)
This function visualizes the partitioning process of a network using the Girvan-Newman algorithm.
-
Parameters:
G(networkx.Graph): The input graph.pos(dict or None): Positions for the nodes in the graph. If None, default spring_layout will be used.method(str): Only "girvan_newman" is supported.w(float): Width of each subplot.h(float): Height of each subplot.nrows(int): Number of rows in the grid of subplots.ncols(int): Number of columns in the grid of subplots.iterations_limit(int): Limit the number of iterations to display.
-
Returns:
None: Displays the partitioning process.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file netd-0.1.tar.gz.
File metadata
- Download URL: netd-0.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0585174c208282462dd2872d04987bfdbbebd999c8e501805f44b39c4d300c01
|
|
| MD5 |
dccd3cff582af3408a6370da0cbe57ce
|
|
| BLAKE2b-256 |
fa3e5b9bcb83bd3f1d3ce93a8499059cf93d786fee7905cf89c202087641dc5f
|
File details
Details for the file netd-0.1-py3-none-any.whl.
File metadata
- Download URL: netd-0.1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
113774e074d332e28cac4b5e4248b6bdd40ea61614fcf7da7c80fc4b390b0c5a
|
|
| MD5 |
7d5b2ab39dcaee1a0ca687177a0ae23c
|
|
| BLAKE2b-256 |
b0258bffb35e24611e030ea59d9f59c213ae0dd9f177beffbb2219c7699e7d9f
|