Graph Utils
Graph Utils
discretize_edges(edgelist, time_scale, store_unix=False, freq_weight=False)
util function for discretizing edgelist, expected timestamp on edges are unixtimestamp this func supports discretization of edge timestamp 1. by providing the number of intervals (int), it will equally divide the data into that number of intervals. Note that the last bin can have less duration than others. 2. by providing a time granularity (str), it will divide the data into intervals based on the given granularity, i.e. "hourly", "daily", "weekly", "monthly", "yearly", the starting time of the dataset is consider the start of the first interval Parameters: edgelist: dict, dictionary of edges time_scale: int or str, time interval to discretize the graph store_unix: bool, whether to return the converted timestamps in unix format freq_weight: bool, whether to weight the edges based on their frequency Returns: output list: the first item in the list is always the updated edgelist (dict, dictionary of edges with discretized timestamps) and the second item is the converted timestamps in unix format (list) if store_unix is True
Source code in tgx/utils/graph_utils.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
is_discretized(edgelist, max_timestamps=10000)
Check if an edgelist is discretized or not.
Source code in tgx/utils/graph_utils.py
233 234 235 236 237 238 239 240 241 242 243 |
|
node_list(dict_edgelist)
create a list of nodes from edgelist dictionary
Source code in tgx/utils/graph_utils.py
179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
subsampling(graph, node_list=[], selection_strategy='random', N=100)
Subsampling a part of graph by only monitoring the contacts from specific nodes' list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
object
|
graph object |
required |
node_list
|
Optional[list]
|
list, a set of nodes to extract their contacts from the graph |
[]
|
selection_strategy
|
str
|
str, currently supports random sampling |
'random'
|
N
|
Optional[int]
|
int, number of nodes to be randomly sampled from graph |
100
|
Returns:
Name | Type | Description |
---|---|---|
new_edgelist |
dict
|
dict, a dictionary of edges corresponding to nodes in the node_list |
Source code in tgx/utils/graph_utils.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
train_test_split(data, val=False, ratio=[85, 15])
Generate train/test split for the data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
dictionary of data |
required |
val
|
bool
|
whether we want to have a validation split as well |
False
|
ratio
|
list
|
list indication the ratio of the data in split. Sum of the list components should be 100. |
[85, 15]
|
Returns:
Type | Description |
---|---|
dict
|
two (train/test) or three (train/val/test) data dictionaries |
Source code in tgx/utils/graph_utils.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|