---
title: "CommunityModularity"
language: "en"
type: "Symbol"
summary: "As of Version 10, all the functionality of the GraphUtilities package is built into the Wolfram System. >>"
keywords: 
- network analysis graph partition graph partitioning
canonical_url: "https://reference.wolfram.com/language/GraphUtilities/ref/CommunityModularity.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Graphs & Networks"
    link: "https://reference.wolfram.com/language/guide/GraphsAndNetworks.en.md"
  - 
    title: "Graph Visualization"
    link: "https://reference.wolfram.com/language/guide/GraphVisualization.en.md"
  - 
    title: "Computation on Graphs"
    link: "https://reference.wolfram.com/language/guide/ComputationOnGraphs.en.md"
  - 
    title: "Graph Construction & Representation"
    link: "https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md"
  - 
    title: "Graphs and Matrices"
    link: "https://reference.wolfram.com/language/guide/GraphsAndMatrices.en.md"
  - 
    title: "Graph Properties & Measurements"
    link: "https://reference.wolfram.com/language/guide/GraphPropertiesAndMeasurements.en.md"
  - 
    title: "Graph Operations and Modifications"
    link: "https://reference.wolfram.com/language/guide/GraphModifications.en.md"
  - 
    title: "Statistical Analysis"
    link: "https://reference.wolfram.com/language/guide/RandomGraphs.en.md"
  - 
    title: "Social Network Analysis"
    link: "https://reference.wolfram.com/language/guide/SocialNetworks.en.md"
  - 
    title: "Graph Properties"
    link: "https://reference.wolfram.com/language/guide/GraphProperties.en.md"
  - 
    title: "Mathematical Data Formats"
    link: "https://reference.wolfram.com/language/guide/MathematicalDataFormats.en.md"
  - 
    title: "Discrete Mathematics"
    link: "https://reference.wolfram.com/language/guide/DiscreteMathematics.en.md"
related_functions: 
  - 
    title: "GraphAssortativity"
    link: "https://reference.wolfram.com/language/ref/GraphAssortativity.en.md"
related_tutorials: 
  - 
    title: "Upgrading from Graph Utilities Package"
    link: "https://reference.wolfram.com/language/Compatibility/tutorial/GraphUtilities.en.md"
---
## GraphUtilities\`

# CommunityModularity

⚠ As of Version 10, all the functionality of the ``GraphUtilities`` package is built into the Wolfram System. [`>>`](https://reference.wolfram.com/language/ref/GraphAssortativity.en.md)

CommunityModularity[g, partition] gives the community modularity of a partition.

CommunityModularity[g, assignment] gives the community modularity of an assignment.

## Details and Options

* ``CommunityModularity`` functionality is now available in the built-in Wolfram Language function ``GraphAssortativity``.

* To use ``CommunityModularity``, you first need to load the [Graph Utilities Package](https://reference.wolfram.com/language/GraphUtilities/guide/GraphUtilitiesPackage.en.md) using ``Needs["GraphUtilities`"]``.

* A community in a network is a group of vertices such that there is a higher density of edges within the group than between them.

* Given a graph $g=\{V,E\}$, let the vertex set $V$ be partitioned into $k$ subsets $``V``=⋃Subscript[``V``, ``i``]$ such that each subset belongs to one community. The community modularity $Q$ of this partition is defined as
$``Q``=Underoverscript[∑, ``i``=1, ``k``](Subscript[``e``, ``ii``] - Subscript[``a``, ``ii``]^2)$, where $Subscript[``e``, ``ii``]$ is the percentage of edges that have both ends in community $Subscript[``V``, ``i``]$, and $Subscript[``a``, ``i``]$ is the percentage of edges that start from community $Subscript[``V``, ``i``]$. In other words, 
$Subscript[``e``, ``ii``]= | {(``u``, ``v``) | ``u``∈Subscript[``V``, ``i``], ``v``∈Subscript[``V``, ``i``], (``u``, ``v``)∈``E``} |  /  | ``E`` | $ and $Subscript[``a``, ``i``]= | {(``u``, ``v``) | ``u``∈Subscript[``V``, ``i``], (``u``, ``v``)∈``E``} |  /  | ``E`` | $.

* The community modularity $Q$ is a number less than or equal to 1. A large positive value indicates that the vertex partition gives significant community structure.

* The following option can be given:

[Weighted](https://reference.wolfram.com/language/GraphUtilities/ref/Weighted.en.md) 	[`False`](https://reference.wolfram.com/language/ref/False.en.md)	whether edges with higher weights are preferred during matching

---

## Examples (3)

### Basic Examples (2)

This defines a small graph:

```wl
In[1]:= Needs["GraphUtilities`"]

In[2]:= g = {1 -> 2, 2 -> 3, 3 -> 1, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 4};

In[3]:= GraphPlot[g, VertexLabeling -> True]

Out[3]= [image]
```

This gives the community modularity, assuming a partition ``{{1, 2, 3}, {4, 5, 6}}`` :

```wl
In[4]:= CommunityModularity[g, {{1, 2, 3}, {4, 5, 6}}]

Out[4]= 0.346939
```

---

``CommunityModularity`` has been superseded by ``GraphAssortativity`` :

```wl
In[1]:= g = Graph[{1 -> 2, 2 -> 3, 3 -> 1, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 4}]

Out[1]= [image]

In[2]:= N[GraphAssortativity[g, {{1, 2, 3}, {4, 5, 6}}, "Normalized" -> False]]

Out[2]= 0.367347
```

### Options (1)

#### Weighted (1)

This defines a graph with edge weights:

```wl
In[1]:= Needs["GraphUtilities`"]

In[2]:= m = {{0, 1, 0, 10}, {1, 0, 0, 0}, {0, 0, 0, 1}, {10, 0, 1, 0}};

In[3]:= GraphPlot[m, VertexLabeling -> True, EdgeRenderingFunction -> ({Line[#], Text[m[[First[#4], Last[#4]]], LineScaledCoordinate[#], Background -> White]}&)]

Out[3]= [image]
```

The community modularity of partition ``{{1, 2}, {3, 4}}``, ignoring edge weights:

```wl
In[4]:= CommunityModularity[m, {{1, 2}, {3, 4}}]

Out[4]= 0.166667
```

The community modularity of partition ``{{1, 2}, {3, 4}}``, taking into account edge weights:

```wl
In[5]:= CommunityModularity[m, {{1, 2}, {3, 4}}, Weighted -> True]

Out[5]= -0.239583
```

When taking into account edge weights, partition ``{{1, 4}, {2, 3}}`` has higher community modularity:

```wl
In[6]:= CommunityModularity[m, {{1, 4}, {2, 3}}, Weighted -> True]

Out[6]= -0.0138889
```

## See Also

* [`GraphAssortativity`](https://reference.wolfram.com/language/ref/GraphAssortativity.en.md)
* [CommunityStructureAssignment](https://reference.wolfram.com/language/GraphUtilities/ref/CommunityStructureAssignment.en.md)
* [CommunityStructurePartition](https://reference.wolfram.com/language/GraphUtilities/ref/CommunityStructurePartition.en.md)
* [MinCut](https://reference.wolfram.com/language/GraphUtilities/ref/MinCut.en.md)

## Tech Notes

* [Upgrading from Graph Utilities Package](https://reference.wolfram.com/language/Compatibility/tutorial/GraphUtilities.en.md)
* [Graph Utilities Package](https://reference.wolfram.com/language/GraphUtilities/tutorial/GraphUtilities.en.md)

## Related Guides

* [Graph Utilities Package](https://reference.wolfram.com/language/GraphUtilities/guide/GraphUtilitiesPackage.en.md)
* [Graphs & Networks](https://reference.wolfram.com/language/guide/GraphsAndNetworks.en.md)
* [Graph Visualization](https://reference.wolfram.com/language/guide/GraphVisualization.en.md)
* [Computation on Graphs](https://reference.wolfram.com/language/guide/ComputationOnGraphs.en.md)
* [Graph Construction & Representation](https://reference.wolfram.com/language/guide/GraphConstructionAndRepresentation.en.md)
* [Graphs and Matrices](https://reference.wolfram.com/language/guide/GraphsAndMatrices.en.md)
* [Graph Properties & Measurements](https://reference.wolfram.com/language/guide/GraphPropertiesAndMeasurements.en.md)
* [Graph Operations and Modifications](https://reference.wolfram.com/language/guide/GraphModifications.en.md)
* [Statistical Analysis](https://reference.wolfram.com/language/guide/RandomGraphs.en.md)
* [Social Network Analysis](https://reference.wolfram.com/language/guide/SocialNetworks.en.md)
* [Graph Properties](https://reference.wolfram.com/language/guide/GraphProperties.en.md)
* [Mathematical Data Formats](https://reference.wolfram.com/language/guide/MathematicalDataFormats.en.md)
* [Discrete Mathematics](https://reference.wolfram.com/language/guide/DiscreteMathematics.en.md)