Visibility Graph Community Detection¶
Submodule pyiomica.visibilityGraphCommunityDetection
Visibility Graph Community detection functions.
Functions:
|
Calculate adjacency matrix of visibility graph, create the networkx.Graph network. |
|
Calculate community structure by shortest path length algorithm. |
- createVisibilityGraph(data, times, graph_type='natural', weight=None, withsign=False)[source]¶
Calculate adjacency matrix of visibility graph, create the networkx.Graph network.
- Parameters:
- data: 2d numpy.array
Data to process
- times: 1d numpy.array
Times corresponding to provided data points
- weight: str, Default None
- Type of normalization:
None: no weighted
‘time’: weight = abs(times[i] - times[j])
‘tan’: weight = abs((data[i] - data[j])/(times[i] - times[j])) + 10**(-8)
‘distance’: weight = A[i, j] = A[j, i] = ((data[i] - data[j])**2 + (times[i] - times[j])**2)**0.5
- graph_type: str, Default ‘natural’
- Type of the visibility graph:
“horizontal”, Horizontal Visibility Graph
“natural”, Natural Visibility Graph
“dual_horizontal”, Dual Perspective Horizontal Visibility Graph
“dual_natural”, Dual Perspective Natural Visibility Graph
withsign: boolean, Default False
Whether to return the sign of adjacency matrix, the link from normal perspective VG is positive, the link from reflected perspective VG is negative
- Returns: tuple
- Tuple of two objects:
- networkx.Graph
Graph of networkx type
- 2d numpy.array
Adjacency matrix
- Usage:
A = createVisibilityGraph(data, times)
- communityDetectByPathLength(G, outputTimePoints=False, setSourceTarget=None, direction=None, cutoff=None)[source]¶
Calculate community structure by shortest path length algorithm.
- Parameters:
- G: networkx.Graph
Graph of networkx type
- outputTimePoints:boolean, default False
Whether to output timepoints for communities or indices
- setSourceTarget:list, default None
List for nodes to consider to use when finding weighted shortest path. First element used for source (starting node), and last for target (ending node)
- direction:str, default None
- The direction that nodes aggregate to communities:
None: no specific direction, e.g. both sides.
‘left’: nodes can only aggregate to the left side hubs, e.g. early hubs
‘right’: nodes can only aggregate to the right side hubs, e.g. later hubs
- cutoff: int, float or str, Default None
Cutoff is used to combine initial communities, e.g. whenever the shortest path length of two adjacent hub nodes is smaller than cutoff, the communities with the two hub nodes will be combined:
int or float: the percentile of all shortest path length distribution, between 0 ~ 100
‘auto’: use optimized cutoff
None: no cutoff
- Returns:
- list of list
Detected communities in the form of nested list.
- Usage:
c = communityDetectByPathLength(G)