DAG
Source code in fpcmci/graph/DAG.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 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 |
|
autodep_nodes: list
property
Autodependent nodes list
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Autodependent nodes list |
features: list
property
Features list
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Features list |
interventions_links: list
property
Intervention links list
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Intervention link list |
__init__(var_names, min_lag, max_lag, neglect_autodep=False, scm=None)
DAG constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_names |
list
|
description |
required |
min_lag |
int
|
description |
required |
max_lag |
int
|
description |
required |
neglect_autodep |
bool
|
description. Defaults to False. |
False
|
scm |
dict
|
description. Defaults to None. |
None
|
Source code in fpcmci/graph/DAG.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
__scale(score, min_width, max_width, min_score=0, max_score=1)
Scales 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 fpcmci/graph/DAG.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
add_context()
Adds context variables
Source code in fpcmci/graph/DAG.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
add_source(t, s, score, pval, lag)
Adds 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 |
Source code in fpcmci/graph/DAG.py
85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
dag(node_layout='dot', min_width=1, max_width=5, min_score=0, max_score=1, node_size=8, node_color='orange', edge_color='grey', bundle_parallel_edges=True, font_size=12, label_type=LabelType.Lag, save_name=None, img_extention=ImageExt.PNG)
build a dag
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_layout |
str
|
Node layout. Defaults to 'dot'. |
'dot'
|
min_width |
int
|
minimum linewidth. Defaults to 1. |
1
|
max_width |
int
|
maximum linewidth. Defaults to 5. |
5
|
min_score |
int
|
minimum score range. Defaults to 0. |
0
|
max_score |
int
|
maximum score range. Defaults to 1. |
1
|
node_size |
int
|
node size. Defaults to 8. |
8
|
node_color |
str
|
node color. Defaults to 'orange'. |
'orange'
|
edge_color |
str
|
edge color. Defaults to 'grey'. |
'grey'
|
bundle_parallel_edges |
str
|
bundle parallel edge bit. Defaults to True. |
True
|
font_size |
int
|
font size. Defaults to 12. |
12
|
label_type |
LabelType
|
enum to set whether to show the lag time (LabelType.Lag) or the strength (LabelType.Score) of the dependencies on each link/node or not showing the 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
|
Source code in fpcmci/graph/DAG.py
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 |
|
del_source(t, s, lag)
Removes 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 fpcmci/graph/DAG.py
100 101 102 103 104 105 106 107 108 109 110 |
|
fully_connected_dag()
Build a fully connected DAG
Source code in fpcmci/graph/DAG.py
76 77 78 79 80 81 82 |
|
get_SCM()
Returns SCM
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
SCM |
Source code in fpcmci/graph/DAG.py
182 183 184 185 186 187 188 189 190 191 192 193 |
|
get_link_assumptions(autodep_ok=False)
Returnes 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 fpcmci/graph/DAG.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
get_parents()
Returns Parents dict
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Parents dict |
Source code in fpcmci/graph/DAG.py
196 197 198 199 200 201 202 203 204 205 206 207 |
|
get_pval_matrix()
Returns 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 fpcmci/graph/DAG.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
get_skeleton()
Returns 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 fpcmci/graph/DAG.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
get_val_matrix()
Returns 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 fpcmci/graph/DAG.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
make_pretty()
Makes variables' names pretty, i.e. $ varname $
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
pretty DAG |
Source code in fpcmci/graph/DAG.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
remove_context()
Remove context variables
Source code in fpcmci/graph/DAG.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
remove_unneeded_features()
Removes isolated nodes
Source code in fpcmci/graph/DAG.py
113 114 115 116 117 118 119 120 121 122 |
|
ts_dag(tau, min_width=1, max_width=5, min_score=0, max_score=1, node_size=8, node_proximity=2, node_color='orange', edge_color='grey', font_size=12, save_name=None, img_extention=ImageExt.PNG)
build a timeseries dag
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tau |
int
|
max time lag |
required |
min_width |
int
|
minimum linewidth. Defaults to 1. |
1
|
max_width |
int
|
maximum linewidth. Defaults to 5. |
5
|
min_score |
int
|
minimum score range. Defaults to 0. |
0
|
max_score |
int
|
maximum score range. Defaults to 1. |
1
|
node_size |
int
|
node size. Defaults to 8. |
8
|
node_proximity |
int
|
node proximity. Defaults to 2. |
2
|
node_color |
str
|
node color. Defaults to 'orange'. |
'orange'
|
edge_color |
str
|
edge color. Defaults to 'grey'. |
'grey'
|
font_size |
int
|
font size. Defaults to 12. |
12
|
save_name |
str
|
Filename path. If None, plot is shown and not saved. Defaults to None. |
None
|
Source code in fpcmci/graph/DAG.py
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 |
|
Source code in fpcmci/graph/Node.py
5 6 7 8 9 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 |
|
autodependency_links: list
property
Returns list of autodependency links
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Returns list of autodependency links |
get_max_autodependent: float
property
Returns max score of autodependent link
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Returns max score of autodependent link |
has_child: bool
property
Returns 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
Returns 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
Returns 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
Returns 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
Returns 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
Returns 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
Returns 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
Returns list of source names
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
Returns list of source names |
__init__(name, neglect_autodep)
Node class contructer
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 fpcmci/graph/Node.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|