Graph
This module provides the Node class.
Classes
Node: class for facilitating the handling and the creation of nodes for a DAG.
Node
Node class.
Source code in causalflow/graph/Node.py
10 11 12 13 14 15 16 17 18 19 20 21 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 |
|
autodependency_links: list
property
Return list of autodependency links.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Returns list of autodependency links. |
get_max_autodependent: float
property
Return max score of autodependent link.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Returns max score of autodependent link. |
has_child: bool
property
Return True if the node has at least one child.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the node has at least one child. Otherwise False. |
has_only_context: bool
property
Return True if the node has ONLY the context variable as parent.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the node has ONLY the context variable as parent. Otherwise False. |
is_autodependent: bool
property
Return True if the node is autodependent.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the node is autodependent. Otherwise False. |
is_exogenous: bool
property
Return True if the node has no parents.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the node has no parents. Otherwise False. |
is_isolated: bool
property
Return True if the node is isolated.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the node is isolated. Otherwise False. |
is_only_autodep: bool
property
Return True if the node is ONLY auto-dependent.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the node is ONLY auto-dependent. Otherwise False. |
is_only_autodep_context: bool
property
Return True if the node has ONLY the context variable and itself as parent.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if the node has ONLY the context variable and itself as parent. Otherwise False. |
sourcelist: list
property
Return list of source names.
Returns:
Name | Type | Description |
---|---|---|
list |
str
|
Returns list of source names. |
__init__(name, neglect_autodep)
Class contructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
node name. |
required |
neglect_autodep |
bool
|
flag to decide whether to to skip the node if it is only auto-dependent. |
required |
Source code in causalflow/graph/Node.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
This module provides the DAG class.
Classes
DAG: class for facilitating the handling and the creation of DAGs.
DAG
DAG class.
Source code in causalflow/graph/DAG.py
17 18 19 20 21 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 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
|
autodep_nodes: list
property
Return the autodependent nodes list.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Autodependent nodes list. |
features: list
property
Return features list.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Features list. |
interventions_links: list
property
Return the intervention links list.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Intervention link list. |
max_auto_score: float
property
Return maximum score of an auto-dependency link.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
maximum score of an auto-dependency link. |
max_cross_score: float
property
Return maximum score of an cross-dependency link.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
maximum score of an cross-dependency link. |
pretty_features: list
property
Return list of features with LaTeX symbols.
Returns:
Name | Type | Description |
---|---|---|
list |
str
|
list of feature names. |
__add_edge(min_width, max_width, min_score, max_score, edges, edge_width, arrows, r, t, s, s_node, t_node)
Add edge to a graph. Support method for dag and ts_dag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_width |
int
|
minimum linewidth. Defaults to 1. |
required |
max_width |
int
|
maximum linewidth. Defaults to 5. |
required |
min_score |
int
|
minimum score range. Defaults to 0. |
required |
max_score |
int
|
maximum score range. Defaults to 1. |
required |
edges |
list
|
list of edges. |
required |
edge_width |
dict
|
dictionary containing the width for each edge of the graph. |
required |
arrows |
dict
|
dictionary containing a bool for each edge of the graph describing if the edge is directed or not. |
required |
r |
DAG
|
DAG. |
required |
t |
str or tuple
|
target node. |
required |
s |
str or tuple
|
source node. |
required |
s_node |
str
|
source node. |
required |
t_node |
str
|
target node. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
link type associated to this edge not included in our LinkType list. |
Source code in causalflow/graph/DAG.py
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 |
|
__get_fixed_edges(ax, x_disp, Gcont, node_size, pos, node_c, font_size, cont_arrows, edge_color, tail_color, cont_edge_width, scale)
Fix edge paths at t-tau_max.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax |
Axes
|
figure axis. |
required |
x_disp |
float
|
node displacement along x. Defaults to 1.5. |
required |
Gcont |
DiGraph
|
Direct Graph containing only contemporaneous links. |
required |
node_size |
int
|
node size. |
required |
pos |
dict
|
node layout. |
required |
node_c |
str / list
|
node color. If a string, all the nodes will have the same colour. If a list (same dimension of features), each colour will have the specified colour. |
required |
font_size |
int
|
font size. |
required |
cont_arrows |
dict
|
edge-arrows dictionary . |
required |
edge_color |
str
|
edge color. |
required |
tail_color |
str
|
tail color. |
required |
cont_edge_width |
dict
|
edge-width dictionary. |
required |
scale |
tuple
|
graph scale. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
new edge paths |
Source code in causalflow/graph/DAG.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
|
__init__(var_names, min_lag, max_lag, neglect_autodep=False, scm=None)
DAG constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_names |
list
|
variable list. |
required |
min_lag |
int
|
minimum time lag. |
required |
max_lag |
int
|
maximum time lag. |
required |
neglect_autodep |
bool
|
bit to neglect nodes when they are only autodependent. Defaults to False. |
False
|
scm |
dict
|
Build the DAG for SCM. Defaults to None. |
None
|
Source code in causalflow/graph/DAG.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
__scale(score, min_width, max_width, min_score=0, max_score=1)
Scale the score of the cause-effect relationship strength to a linewitdth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
score |
float
|
score to scale. |
required |
min_width |
float
|
minimum linewidth. |
required |
max_width |
float
|
maximum linewidth. |
required |
min_score |
int
|
minimum score range. Defaults to 0. |
0
|
max_score |
int
|
maximum score range. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
float
|
scaled score. |
Source code in causalflow/graph/DAG.py
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
|
add_context()
Add context variables.
Source code in causalflow/graph/DAG.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
add_source(t, s, score, pval, lag, mode=LinkType.Directed.value)
Add source node to a target node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
str
|
target node name. |
required |
s |
str
|
source node name. |
required |
score |
float
|
dependency score. |
required |
pval |
float
|
dependency p-value. |
required |
lag |
int
|
dependency lag. |
required |
mode |
LinkType
|
link type. E.g., Directed --> |
LinkType.Directed.value
|
Source code in causalflow/graph/DAG.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
dag(node_layout='dot', min_auto_width=0.25, max_auto_width=0.75, min_cross_width=0.5, max_cross_width=1.5, node_size=4, node_color='orange', edge_color='grey', tail_color='black', font_size=8, label_type=LabelType.Lag, save_name=None, img_extention=ImageExt.PNG)
Build a dag, first with contemporaneous links, then lagged links.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_layout |
str
|
Node layout. Defaults to 'dot'. |
'dot'
|
min_auto_width |
float
|
minimum border linewidth. Defaults to 0.25. |
0.25
|
max_auto_width |
float
|
maximum border linewidth. Defaults to 0.75. |
0.75
|
min_cross_width |
float
|
minimum edge linewidth. Defaults to 0.5. |
0.5
|
max_cross_width |
float
|
maximum edge linewidth. Defaults to 1.5. |
1.5
|
node_size |
int
|
node size. Defaults to 4. |
4
|
node_color |
str
|
node color. Defaults to 'orange'. |
'orange'
|
edge_color |
str
|
edge color for contemporaneous links. Defaults to 'grey'. |
'grey'
|
tail_color |
str
|
tail color. Defaults to 'black'. |
'black'
|
font_size |
int
|
font size. Defaults to 8. |
8
|
label_type |
LabelType
|
Show the lag time (LabelType.Lag), the strength (LabelType.Score), or no labels (LabelType.NoLabels). Default LabelType.Lag. |
LabelType.Lag
|
save_name |
str
|
Filename path. If None, plot is shown and not saved. Defaults to None. |
None
|
img_extention |
ImageExt
|
Image Extension. Defaults to PNG. |
ImageExt.PNG
|
Source code in causalflow/graph/DAG.py
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 |
|
del_source(t, s, lag)
Remove source node from a target node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
str
|
target node name. |
required |
s |
str
|
source node name. |
required |
lag |
int
|
dependency lag. |
required |
Source code in causalflow/graph/DAG.py
138 139 140 141 142 143 144 145 146 147 148 |
|
get_Adj(indexed=False)
Return Adjacency dictionary.
If indexed = True: example {0: [(0, -1), (1, -2)], 1: [], ...} If indexed = False: example {"X_0": [(X_0, -1), (X_1, -2)], "X_1": [], ...}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indexed |
bool
|
If true, returns the SCM with index instead of variables' names. Otherwise it uses variables' names. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
SCM. |
Source code in causalflow/graph/DAG.py
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
|
get_Graph()
Return Graph dictionary. E.g. {X1: {(X2, -2): '-->'}, X2: {(X3, -1): '-?>'}, X3: {(X3, -1): '-->'}}.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
graph dictionary. |
Source code in causalflow/graph/DAG.py
833 834 835 836 837 838 839 840 841 842 843 844 |
|
get_graph_matrix()
Return graph matrix.
Graph matrix contains information about the link type. E.g., -->, <->, ..
Returns:
Type | Description |
---|---|
np.array
|
np.array: graph matrix. |
Source code in causalflow/graph/DAG.py
791 792 793 794 795 796 797 798 799 800 801 802 803 804 |
|
get_link_assumptions(autodep_ok=False)
Return link assumption dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
autodep_ok |
bool
|
If true, autodependecy link assumption = -->. Otherwise -?>. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
link assumption dictionary. |
Source code in causalflow/graph/DAG.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 |
|
get_pval_matrix()
Return pval matrix.
Pval matrix contains information about the pval of the links componing the causal model.
Returns:
Type | Description |
---|---|
np.array
|
np.array: pval matrix |
Source code in causalflow/graph/DAG.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
|
get_skeleton()
Return skeleton matrix.
Skeleton matrix is composed by 0 and 1. 1 <- if there is a link from source to target 0 <- if there is not a link from source to target
Returns:
Type | Description |
---|---|
np.array
|
np.array: skeleton matrix |
Source code in causalflow/graph/DAG.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
|
get_val_matrix()
Return val matrix.
Val matrix contains information about the strength of the links componing the causal model.
Returns:
Type | Description |
---|---|
np.array
|
np.array: val matrix. |
Source code in causalflow/graph/DAG.py
759 760 761 762 763 764 765 766 767 768 769 770 771 772 |
|
make_pretty()
Make variables' names pretty, i.e. $ varname $ with '{' after '_' and '}' at the end of the string.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
pretty DAG. |
Source code in causalflow/graph/DAG.py
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 |
|
remove_context()
Remove context variables.
Source code in causalflow/graph/DAG.py
181 182 183 184 185 186 187 188 189 190 191 |
|
remove_unneeded_features()
Remove isolated nodes.
Source code in causalflow/graph/DAG.py
151 152 153 154 155 156 157 158 |
|
ts_dag(min_cross_width=1, max_cross_width=5, node_size=8, x_disp=1.5, y_disp=0.2, text_disp=0.1, node_color='orange', edge_color='grey', tail_color='black', font_size=8, save_name=None, img_extention=ImageExt.PNG)
Build a timeseries dag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_cross_width |
int
|
minimum linewidth. Defaults to 1. |
1
|
max_cross_width |
int
|
maximum linewidth. Defaults to 5. |
5
|
node_size |
int
|
node size. Defaults to 8. |
8
|
x_disp |
float
|
node displacement along x. Defaults to 1.5. |
1.5
|
y_disp |
float
|
node displacement along y. Defaults to 0.2. |
0.2
|
text_disp |
float
|
text displacement along y. Defaults to 0.1. |
0.1
|
node_color |
str / list
|
node color. If a string, all the nodes will have the same colour. If a list (same dimension of features), each colour will have the specified colour. Defaults to 'orange'. |
'orange'
|
edge_color |
str
|
edge color. Defaults to 'grey'. |
'grey'
|
tail_color |
str
|
tail color. Defaults to 'black'. |
'black'
|
font_size |
int
|
font size. Defaults to 8. |
8
|
save_name |
str
|
Filename path. If None, plot is shown and not saved. Defaults to None. |
None
|
img_extention |
ImageExt
|
Image Extension. Defaults to PNG. |
ImageExt.PNG
|
Source code in causalflow/graph/DAG.py
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 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
|
This module provides the PAG class.
Classes
PAG: class for facilitating the handling and the creation of PAGs.
PAG
PAG class.
Source code in causalflow/graph/PAG.py
13 14 15 16 17 18 19 20 21 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 |
|
__init__(dag, tau_max, latents)
Class constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dag |
DAG
|
DAG to convert. |
required |
tau_max |
int
|
max time lag. |
required |
latents |
list[str]
|
list of latent variables. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
latent must be a string |
Source code in causalflow/graph/PAG.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
alreadyChecked(source, target)
Check if a link has been already checked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
str
|
source node |
required |
target |
str
|
target node |
required |
Returns:
Type | Description |
---|---|
(bool, tuple)
|
tuple containing if the link has been checked and, if so, their separation set. Otherwise None. |
Source code in causalflow/graph/PAG.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
convert2Graph()
Convert a PAG to a graph representation.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Graph representation of a PAG. |
Source code in causalflow/graph/PAG.py
39 40 41 42 43 44 45 46 47 48 49 50 |
|
createDAG(link_assumptions, tau_max)
staticmethod
Create a DAG represented by a Baysian Network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
link_assumptions |
dict
|
DAG link assumptions. |
required |
tau_max |
int
|
max time lag. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
source not well defined. |
Returns:
Name | Type | Description |
---|---|---|
BayesianNetwork |
BayesianNetwork
|
DAG represented by a Baysian Network. |
Source code in causalflow/graph/PAG.py
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 |
|
find_all_paths(start, goal, path=[])
Find all path from start to goal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start |
str
|
starting node. |
required |
goal |
str
|
goal node. |
required |
path |
list
|
Found paths. Defaults to []. |
[]
|
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
paths |
Source code in causalflow/graph/PAG.py
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 |
|
find_colliders()
Find colliders.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
colliders. |
Source code in causalflow/graph/PAG.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
find_d_separators(source, target)
Find D-Separation set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
str
|
source node. |
required |
target |
str
|
target node. |
required |
Returns:
Type | Description |
---|---|
(bool, set)
|
(True, separation set) if source and target are d-separated. Otherwise (False, empty set). |
Source code in causalflow/graph/PAG.py
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 |
|
find_latent_confounders()
Find latent confounders.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
latent confounders. |
Source code in causalflow/graph/PAG.py
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 |
|
find_triples_containing_link(ambiguous_link)
Find all triples containing a link.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ambiguous_link |
tuple
|
ambiguous_link |
required |
Returns:
Name | Type | Description |
---|---|---|
set |
set
|
triples containing the specified link. |
Source code in causalflow/graph/PAG.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
tsDAG2tsDPAG()
Convert a DAG to a Time-series DPAG.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Time-series DPAG. |
Source code in causalflow/graph/PAG.py
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 |
|
update_link_type(parent, target, linktype)
Update link type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
str
|
parent node. |
required |
target |
str
|
target node |
required |
linktype |
str
|
link type. E.g. --> or -?>. |
required |
Source code in causalflow/graph/PAG.py
232 233 234 235 236 237 238 239 240 241 242 243 |
|