multi_order_model
MultiOrderModel
¶
MultiOrderModel based on torch_geometric.Data.
Source code in src/pathpyG/core/multi_order_model.py
22 23 24 25 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 120 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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
__str__
¶
Return a string representation of the higher-order graph.
estimate_order
¶
Selects the optimal maximum order of a multi-order network model for the observed paths, based on a likelihood ratio test with p-value threshold of p By default, all orders up to the maximum order of the multi-order model will be tested.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dag_data
|
DAGData
|
The path statistics data for which to estimate the optimal order. |
required |
max_order
|
int
|
The maximum order to consider during the estimation process. If not provided, the maximum order of the multi-order model is used. |
None
|
significance_threshold
|
float
|
The p-value threshold for the likelihood ratio test. An order is accepted if the improvement in likelihood is significant at this threshold. |
0.01
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The estimated optimal maximum order for the multi-order network model. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the provided max_order is larger than the maximum order of the multi-order model or if the input DAGData does not have the same set of nodes as the multi-order network |
Source code in src/pathpyG/core/multi_order_model.py
from_PathData
staticmethod
¶
Creates multiple higher-order De Bruijn graphs modelling paths in PathData.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_data
|
pathpyG.core.path_data.PathData
|
|
required |
max_order
|
int
|
The maximum order of the MultiOrderModel that should be computed |
1
|
mode
|
str
|
The process that we assume. Can be "diffusion" or "propagation". |
'propagation'
|
cached
|
bool
|
Whether to save the aggregated higher-order graphs smaller than max order in the MultiOrderModel. |
True
|
Returns:
Name | Type | Description |
---|---|---|
MultiOrderModel |
pathpyG.core.multi_order_model.MultiOrderModel
|
The MultiOrderModel. |
Source code in src/pathpyG/core/multi_order_model.py
from_temporal_graph
staticmethod
¶
Creates multiple higher-order De Bruijn graph models for paths in a temporal graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
pathpyG.core.temporal_graph.TemporalGraph
|
The temporal graph. |
required |
delta
|
float | int
|
The maximum time difference between two consecutive edges in a path. |
1
|
max_order
|
int
|
The maximum order of the MultiOrderModel that should be computed. |
1
|
weight
|
str
|
The edge attribute to use as edge weight. |
'edge_weight'
|
cached
|
bool
|
Whether to save the aggregated higher-order graphs smaller than max order in the MultiOrderModel. |
True
|
event_graph
|
torch.Tensor
|
precomputed event graph edge index for given delta to be used for model generation. Useful to prevent the same event graph |
None
|
Returns:
Name | Type | Description |
---|---|---|
MultiOrderModel |
pathpyG.core.multi_order_model.MultiOrderModel
|
A multi-order model where each layer is a De Bruijn graph with order k. |
Source code in src/pathpyG/core/multi_order_model.py
get_intermediate_order_log_likelihood
¶
Compute the intermediate order log likelihood.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
pathpyG.core.multi_order_model.MultiOrderModel
|
Multi-order model. |
required |
dag_graph
|
torch_geometric.data.Data
|
Input DAG graph data. |
required |
order
|
int
|
Order of the intermediate log likelihood. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Intermediate order log likelihood. |
Source code in src/pathpyG/core/multi_order_model.py
get_mon_dof
¶
The degrees of freedom for the kth layer of a multi-order model. This depends on the number of different paths of exactly length k
in the graph.
Therefore, we can obtain these values by summing the entries of the k
-th power of the binary adjacency matrix of the graph.
Finally, we must consider that, due the conservation of probablility, all non-zero rows of the transition matrix of the higher-order network must sum to one.
This poses one additional constraint per row that respects the condition, which should be removed from the total count of degrees of freedom.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
pathpyG.core.multi_order_model.MultiOrderModel
|
The multi-order model. |
required |
max_order
|
int
|
The maximum order up to which model layers shall be taken into account. Defaults to None, meaning it considers all available layers. |
None
|
assumption
|
str
|
If set to 'paths', only paths in the first-order network topology will be considered for the degree of freedom calculation. If set to 'ngrams', all possible n-grams will be considered, independent of whether they are valid paths in the first-order network or not. Defaults to 'paths'. |
'paths'
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The degrees of freedom for the multi-order model. |
Raises:
Type | Description |
---|---|
AssertionError
|
If max_order is larger than the maximum order of the multi-order network. |
ValueError
|
If the assumption is not 'paths' or 'ngrams'. |
Source code in src/pathpyG/core/multi_order_model.py
get_mon_log_likelihood
¶
Compute the likelihood of the walks given a multi-order model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
pathpyG.core.multi_order_model.MultiOrderModel
|
The multi-order model. |
required |
dag_graph
|
torch_geometric.data.Data
|
Dataset containing the walks. |
required |
max_order
|
int
|
The maximum order up to which model layers shall be taken into account. Defaults to 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The log likelihood of the walks given the multi-order model. |
Source code in src/pathpyG/core/multi_order_model.py
get_zeroth_order_log_likelihood
¶
Compute the zeroth order log likelihood.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dag_graph
|
torch_geometric.data.Data
|
Input DAG graph data. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Zeroth order log likelihood. |
Source code in src/pathpyG/core/multi_order_model.py
iterate_lift_order
staticmethod
¶
Lift order by one and save the result in the layers dictionary of the object. This is a helper function that should not be called directly. Only use for edge_indices after the special cases have been handled e.g. in the from_temporal_graph (filtering non-time-respecting paths of order 2).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_index
|
torch.Tensor
|
The edge index of the (k-1)-th order graph. |
required |
node_sequence
|
torch.Tensor
|
The node sequences of the (k-1)-th order graph. |
required |
edge_weight
|
torch.Tensor | None
|
The edge weights of the (k-1)-th order graph. |
None
|
k
|
The order of the graph that should be computed. |
required | |
aggr
|
str
|
The aggregation method to use. One of "src", "dst", "max", "mul". |
'src'
|
save
|
bool
|
Whether to compute the aggregated graph and later save it in the layers dictionary. |
True
|
Source code in src/pathpyG/core/multi_order_model.py
likelihood_ratio_test
¶
Perform a likelihood ratio test to compare two models of different order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dag_graph
|
torch_geometric.data.Data
|
The input DAG graph data. |
required |
max_order_null
|
int
|
The maximum order of the null hypothesis model. Defaults to 0. |
0
|
max_order
|
int
|
The maximum order of the alternative hypothesis model. Defaults to 1. |
1
|
assumption
|
str
|
The assumption to use for the degrees of freedom calculation. Can be 'paths' or 'ngrams'. Defaults to 'paths'. |
'paths'
|
significance_threshold
|
float
|
The significance threshold for the test. Defaults to 0.01. |
0.01
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple
|
A tuple containing a boolean indicating whether the null hypothesis is rejected and the p-value of the test. |
Source code in src/pathpyG/core/multi_order_model.py
to_dbgnn_data
¶
Convert the MultiOrderModel to a De Bruijn graph for the given maximum order
that can be used in pathpyG.nn.dbgnn.DBGNN
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_order
|
int
|
The maximum order of the De Bruijn graph to be computed. |
2
|
mapping
|
str
|
The mapping to use for the bipartite edge index. One of "last", "first", or "both". |
'last'
|
Returns:
Name | Type | Description |
---|---|---|
Data |
torch_geometric.data.Data
|
The De Bruijn graph data. |