r"""
Correlated Louvain Community Detection.
This module extends the standard Louvain algorithm by incorporating an
absolute phenotype-correlation objective into the modularity maximization
process.
References:
Abdel-Hafiz et al. (2022), "Significant Subgraph Detection in
Multi-omics Networks for Disease Pathway Identification,"
Frontiers in Big Data.
Notes:
**Hybrid Modularity Objective**
The algorithm optimizes connectivity and phenotype correlation
simultaneously using the following weighted objective function:
.. math::
Q_{hybrid} = k_L Q + (1 - k_L) \rho
Where:
* :math:`Q`: Standard modularity (internal connectivity).
* :math:`\\rho`: Absolute Pearson correlation of the community's
first principal component (PC1) with phenotype :math:`Y`.
* :math:`k_L`: User-defined weight on modularity (Suggested: 0.2).
Algorithm:
The hierarchical loop and Phase 2 (network aggregation) remain
identical to the standard Louvain method. The modification occurs
exclusively in **Phase 1 (Local Optimization)**.
When evaluating the movement of node :math:`v` from community :math:`D`
to community :math:`C`, the gain is calculated as:
.. math::
\Delta_{hybrid} = k_L \Delta Q + (1 - k_L) \Delta \\rho
The correlation gain :math:`\Delta \\rho` is defined as the change in
total correlation across affected communities:
.. math::
\Delta \\rho = [|\\rho(D \setminus \{v\})| + |\\rho(C \cup \{v\})|] - [|\\rho(D)| + |\\rho(C)|]
"""
from typing import Any, Dict, FrozenSet, List, Optional, Set, Tuple, Union
import numpy as np
import pandas as pd
import networkx as nx
from .louvain import Louvain
from ..utils import get_logger
logger = get_logger(__name__)