A measure of assortativity is modularity, that we already encountered in community detection.
\[Q = \frac{1}{2m} \sum_{i,j} \left(a_{i,j} - \frac{k_i k_j}{2m}\right) \delta(c_i, c_j)\]
The modularity takes positive values if there are more edges between same-type vertices than expected, and negative values if there are less.
We can normalize modularity by dividing it by the maximum value it can have, that is the modularity of a perfectly mixed network, which is a network where all edges run between nodes of the same type.
In this network, the actual number of edges with nodes of the same type is of course \(m\), hence the modularity results:
\[Q_{max} = \frac{1}{2 m} \left( 2m - \sum_{i,j} \frac{k_i k_j}{2m} \delta(c_i, c_j) \right)\]
and the normalized modularity is:
\[\frac{Q}{Q_{max}} = \frac{\sum_{i,j} (a_{i,j} - k_i k_j / 2m) \delta(c_i, c_j)}{2m - \sum_{i,j} (k_i k_j / 2m) \delta(c_i, c_j)}\]