API
Regressors
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
BackgroundKnowledge
Class to store background knowledge.
Source code in gresit/background_knowledge.py
__init__(full_data_dict)
Initializes the BK object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
full_data_dict
|
dict[str, ndarray]
|
input data without BK. |
required |
target_overwrite(target_dict)
Restrictions on target variable.
target_remove_by_index(target_dict)
Takes array columns in target key, value pair and removes them.
Removal is done by (multiple) index array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_dict
|
dict[str, ndarray]
|
Dict with key equal to groups and values equal to indices. |
required |
Source code in gresit/background_knowledge.py
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
GroupPC
Bases: LearnAlgo
This class provides tools for causal discovery.
Particularly, in the context where data is known to follow a layered structure.
Source code in gresit/group_pc.py
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 |
|
adjacency_matrix
property
Represent the underlying learned PDAG as adjacency matrix.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Adjacency matrix of the PDAG. |
causal_order
property
Returns causal order if PDAG is in fact a DAG.
Else it will return None.
Returns:
Type | Description |
---|---|
list[str] | None
|
list[str] | None: causal order if appropriate. |
skeleton
property
Represent the underlying skeleton as adjacency matrix.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Adjacency matrix of the skeleton. |
__init__(alpha=0.05, test=FisherZVec)
Initiates VectorPC.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha
|
float
|
Acts as a tuning parameter. The significance threshold for the conditional independence test. The smaller, the sparser the resulting graph. Defaults to 0.05. |
0.05
|
test
|
CItest
|
Which CI test to use. |
FisherZVec
|
Source code in gresit/group_pc.py
learn_graph(data_dict, threshold=0.5, layering=None)
Learns the graph from the given data.
If layering is provided it is taken to be unambiguous. If layering is not Null, then the separation sets may never contain variables that appear in future layers to the pair of variables considered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dict
|
dict | ndarray
|
relevant data. |
required |
threshold
|
float
|
The majority vote threshold for deciding on ambiguous collider structures. Defaults to 0.5. |
0.5
|
layering
|
dict[str, list[str]]
|
The layering of the nodes. |
None
|
Returns:
Name | Type | Description |
---|---|---|
PDAG |
PDAG
|
Graph estimate. |
Source code in gresit/group_pc.py
maximally_orient(data, alpha=0.05, threshold=0.5)
Given a skeleton, the following orientation steps are taken.
1. All undirected edges between layers are immediately oriented
according to the given layering.
2. Potential v-structures are ordiented.
3. The remaining undirected edges are oriented according to the four
Meek rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict[str, ndarray]
|
The data. |
required |
alpha
|
float
|
The significance threshold for the conditional independence test. Defaults to 0.05. |
0.05
|
threshold
|
float
|
The majority vote threshold for deciding on ambiguous collder structures. Defaults to 0.5. |
0.5
|
Source code in gresit/group_pc.py
MicroPC
Bases: LearnAlgo
Standard PC stable on micro nodes aggregated after the fact.
Source code in gresit/group_pc.py
adjacency_matrix
property
Adjacency matrix.
causal_order
property
Causal order.
__init__(alpha=0.05)
Inits the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha
|
float
|
Significance level of the test. Defaults to 0.05. |
0.05
|
learn_graph(data_dict, *args, **kwargs)
Learn graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dict
|
_type_
|
description |
required |
*args
|
Any
|
additional args. |
()
|
**kwargs
|
Any
|
additional kwargs. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
PDAG |
GRAPH
|
description |
Source code in gresit/group_pc.py
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
GroupResit
Bases: LearnAlgo
A class representing the groupResit algorithm.
This algorithm is used to learn a DAG based on vector/group valued ANMs.
Source code in gresit/group_resit.py
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 |
|
adjacency_matrix
property
Adjacency matrix.
causal_order
property
Causal order.
__init__(regressor, test, alpha=0.01, pruning_method='murgs', test_size=0.2, local_regression_method='kernel')
Initialize the GroupResit object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
regressor
|
MultivariateRegressor
|
A regressor object. |
required |
test
|
IndependenceTest
|
An independence test object. |
required |
alpha
|
float
|
Alpha |
0.01
|
pruning_method
|
str
|
The pruning method |
'murgs'
|
test_size
|
float
|
Relative size of test-dataset, 0 means no test data |
0.2
|
local_regression_method
|
str
|
Type of local linear smoother to use. Options are
|
'kernel'
|
Source code in gresit/group_resit.py
__repr__()
Repr method.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Description of the object. |
__str__()
Str method.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Human-readable description of the object. |
Source code in gresit/group_resit.py
learn_graph(data_dict, layering=None)
Learn the causal graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dict
|
dict[str, ndarray]
|
A dictionary of np.ndarrays. Key corresponds to group name and values to the corresponding data. |
required |
layering
|
dict[str, list[str]]
|
A dictionary of layering information. Keys correspond to the layer and values to the variable names within each layer. |
None
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
description |
Returns:
Name | Type | Description |
---|---|---|
DAG |
DAG
|
DAG estimate. |
Source code in gresit/group_resit.py
model_selection_with_known_causal_order(pi, data_dict, alpha=0.01, pruning_method='murgs')
Given a known causal order perform model selection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pi
|
list[str]
|
Causal ordering. Entries in |
required |
data_dict
|
dict[str, ndarray]
|
A dictionary of np.ndarrays. Key corresponds to group name and values to the corresponding data. |
required |
alpha
|
float
|
The significance level for the independence test. Defaults to 0.1. |
0.01
|
pruning_method
|
str
|
The pruning method to use. Defaults to "murgs".
other options include |
'murgs'
|
Source code in gresit/group_resit.py
show(title='Group RESIT DAG')
Plot the learned DAG.
The plot is interactive, hovering over the nodes reveals the node labels. Colors get brighter the higher the node degree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
Plot title. Defaults to "Group RESIT DAG". |
'Group RESIT DAG'
|
Raises:
Type | Description |
---|---|
AssertionError
|
Throws error if DAG not yet learned. |
Source code in gresit/group_resit.py
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 |
|
show_interactive(layer_gap=8.0)
Show interactive plot with slider to select sparsity level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer_gap
|
float
|
gap between layers when displaying. Defaults to 8.0. |
8.0
|
Source code in gresit/group_resit.py
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 |
|
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
EarlyStopping
Early stopping to conserve compute resources.
Source code in gresit/torch_models.py
__call__(model, val_loss)
Stopping actions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
NN model |
required |
val_loss
|
float
|
Value of loss function. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if training may be concluded. |
Source code in gresit/torch_models.py
__init__(patience=5, min_delta=0.0, restore_best_weights=True)
Initializes the EarlyStopping class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patience
|
int
|
Number of epochs to wait for the validation error to improve. Defaults to 5. |
5
|
min_delta
|
float
|
Minimum change that should be considered an improvement. Defaults to 0.0. |
0.0
|
restore_best_weights
|
bool
|
Restores the weights to the values they were when the validation set was best. Defaults to True. |
True
|
Source code in gresit/torch_models.py
MLP
Bases: Module
Torch MLP with single-hidden layer and sigmoid non-linearity.
Not too fancy but does what it is supposed to do.
Source code in gresit/torch_models.py
__init__(input_dim, output_dim, hidden_dim=100, dropout=0.0)
Initializes the NN.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim
|
int
|
dim of input layer |
required |
output_dim
|
int
|
dim of output layer. |
required |
hidden_dim
|
int
|
dim of hidden layer. Defaults to 100. |
100
|
dropout
|
float
|
dropout probability. Defaults to 0.0. |
0.0
|
Source code in gresit/torch_models.py
forward(x)
Forward passing the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
training data. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: prediction after pass through nn. |
Source code in gresit/torch_models.py
update_bias(bias_value)
Update bias due to HSIC location invariance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bias_value
|
Tensor
|
description |
required |
Raises:
Type | Description |
---|---|
ValueError
|
description |
Source code in gresit/torch_models.py
MultioutcomeGPR
Bases: MultiRegressor
MultioutcomeGPR Gaussian Process Regression class.
Source code in gresit/torch_models.py
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 |
|
__init__(rng=np.random.default_rng(seed=2024), n_epochs=300, patience=50, learning_rate=0.01, val_size=0.2, batch_size=None, es=True)
Initialize MLP.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Generator
|
description. Defaults to np.random.default_rng(seed=2024). |
default_rng(seed=2024)
|
n_epochs
|
int
|
number of times the data gets passed trough the MLP. Defaults to 6. |
300
|
patience
|
int
|
Minimal number of epochs to train before early stopping applies |
50
|
learning_rate
|
float
|
description. Defaults to 1e-3. |
0.01
|
val_size
|
float
|
Relative size of the validation dataset |
0.2
|
batch_size
|
int
|
Batch size. |
None
|
es
|
bool
|
Early stopping. |
True
|
Source code in gresit/torch_models.py
fit(X, Y, idx_train=None, idx_test=None)
Fit the MLP model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Input data |
required |
Y
|
ndarray
|
Target data |
required |
idx_train
|
ndarray
|
training indices |
None
|
idx_test
|
ndarray
|
test indices |
None
|
Returns:
Name | Type | Description |
---|---|---|
int |
None
|
epoch at which training was stopped. |
Source code in gresit/torch_models.py
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 |
|
plot_training_info()
Plot some summary over the MSE during training.
Source code in gresit/torch_models.py
predict(X_test=None)
Make predictions.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Predictions |
Source code in gresit/torch_models.py
Multioutcome_MLP
Bases: MultiRegressor
Fit simple MLP with one hidden layer.
Source code in gresit/torch_models.py
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 |
|
__init__(rng=np.random.default_rng(seed=2024), loss='mse', dropout_proba=0.6, n_epochs=300, patience=50, learning_rate=0.01, val_size=0.2, batch_size=200, es=True)
Initialize MLP.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Generator
|
description. Defaults to np.random.default_rng(seed=2024). |
default_rng(seed=2024)
|
loss
|
str
|
Standard mse loss is default.
Other options are |
'mse'
|
dropout_proba
|
float
|
description. Defaults to 0.6. |
0.6
|
n_epochs
|
int
|
number of times the data gets passed trough the MLP. Defaults to 6. |
300
|
patience
|
int
|
Minimal number of epochs to train before early stopping applies |
50
|
learning_rate
|
float
|
description. Defaults to 1e-3. |
0.01
|
val_size
|
float
|
Relative size of the validation dataset |
0.2
|
batch_size
|
int
|
Batch size. |
200
|
es
|
bool
|
Early stopping. Defaults to true. |
True
|
Source code in gresit/torch_models.py
fit(X, Y, idx_train=None, idx_test=None)
Fit the MLP model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Input data |
required |
Y
|
ndarray
|
Target data |
required |
idx_train
|
ndarray
|
training indices |
None
|
idx_test
|
ndarray
|
test indices |
None
|
Returns:
Name | Type | Description |
---|---|---|
int |
None
|
epoch at which training was stopped. |
Source code in gresit/torch_models.py
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 |
|
plot_training_info()
Plot some summary over the MSE during training.
Source code in gresit/torch_models.py
predict(X_test=None)
Make predictions.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Predictions |
Source code in gresit/torch_models.py
MultitaskGPModel
Bases: ExactGP
Multitask GPR.
Source code in gresit/torch_models.py
__init__(train_x, train_y, likelihood)
Inits the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_x
|
_type_
|
description |
required |
train_y
|
_type_
|
description |
required |
likelihood
|
_type_
|
description |
required |
Source code in gresit/torch_models.py
forward(x)
Forward pass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
_type_
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
Tensor
|
description |
Source code in gresit/torch_models.py
make_preds_single(model, X)
Helper function for predicting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Model
|
nn model instance |
required |
X
|
Tensor
|
test data |
required |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
Tensor
|
description |
Source code in gresit/torch_models.py
Independence Tests
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
CItest
Abstract meta class for independence tests.
Source code in gresit/independence_tests.py
test(x_data, y_data, z_data=None)
abstractmethod
Abstract method for independence tests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_data
|
ndarray | DataFrame | Series
|
Variables involved in the test |
required |
y_data
|
ndarray | DataFrame | Series
|
Variables involved in the test |
required |
z_data
|
ndarray | DataFrame | Series | None
|
Variables involved in the test |
None
|
Returns:
Type | Description |
---|---|
tuple[float, float]
|
tuple[float, float]: Test statistic and corresponding pvalue (Test decision). |
Source code in gresit/independence_tests.py
DISCO
Bases: Itest
Simple Wrapper class around the squared distance covariance from the dcor class.
Source code in gresit/independence_tests.py
__init__()
test(x_data, y_data)
Test for independence between two vectors Finite joint first moments are assumed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_data
|
ndarray | DataFrame | Series
|
x-data involved in the test |
required |
y_data
|
ndarray | DataFrame | Series
|
y-data involved in the test |
required |
Returns:
Type | Description |
---|---|
tuple[float, str]
|
tuple[float, str]: Distance covariance value and some string to comply with format. |
Source code in gresit/independence_tests.py
FisherZVec
Bases: CItest
Simple extension of standard Fisher-Z test for independence.
Source code in gresit/independence_tests.py
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 |
|
__init__()
test(x_data, y_data, z_data=None, corr_threshold=0.999)
Retrieve (composite) p_value using Fisher z-transformation.
Appropriate when data is jointly Gaussian.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_data
|
ndarray
|
X_data. |
required |
y_data
|
ndarray
|
Y_data. |
required |
z_data
|
ndarray | None
|
Z_data. defaults to None. |
None
|
corr_threshold
|
float
|
Threshold to make sure r in [-1,1]. Defaults to 0.999. |
0.999
|
Returns:
Type | Description |
---|---|
tuple[float, float]
|
tuple[float,float]: test_statistic, p_value |
Source code in gresit/independence_tests.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 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 |
|
HSIC
Bases: Itest
Hilbert-Schmidt Independence Criterion (HSIC) test.
Source code in gresit/independence_tests.py
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 |
|
get_gram_matrix(X, width)
Get the centered gram matrices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
shape (n_samples, n_features)
Training data, where |
required |
width
|
float
|
The bandwidth parameter. |
required |
Returns:
Type | Description |
---|---|
tuple[ndarray, ndarray]
|
tuple[np.ndarray, np.ndarray]: The centered gram matrices. |
Source code in gresit/independence_tests.py
get_kernel_width(X, sample_cut=100)
Calculate the bandwidth to median distance between points.
Use at most 100 points (since median is only a heuristic, and 100 points is sufficient for a robust estimate).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
shape (n_samples, n_features) Training data, |
required |
sample_cut
|
int
|
Number of samples to use for bandwidth calculation. |
100
|
Returns:
Name | Type | Description |
---|---|---|
float |
float64
|
The bandwidth parameter. |
Source code in gresit/independence_tests.py
hsic_test_gamma(X, Y, bw_method='mdbs')
Get the HSIC statistic and p-value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
data, possibly vector-valued. |
required |
Y
|
ndarray
|
data, possibly vector-valued. |
required |
bw_method
|
str
|
The method used to calculate the bandwidth of the HSIC.
* |
'mdbs'
|
Returns:
Type | Description |
---|---|
tuple[float, float]
|
tuple[float, float]: HSIC test statistic and corresponding p-value |
Source code in gresit/independence_tests.py
hsic_teststat(Kc, Lc, n)
Get the HSIC statistic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Kc
|
ndarray
|
Centered gram matrix. |
required |
Lc
|
ndarray
|
Centered gram matrix. |
required |
n
|
int
|
Sample size. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float64
|
HSIC statistic. |
Source code in gresit/independence_tests.py
test(x_data, y_data, bw_method='mdbs')
Test for independence between two vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_data
|
ndarray | DataFrame | Series
|
x-data involved in the test |
required |
y_data
|
ndarray | DataFrame | Series
|
y-data involved in the test |
required |
bw_method
|
str
|
The method used to calculate the bandwidth of the HSIC.
* |
'mdbs'
|
Returns:
Type | Description |
---|---|
tuple[float, float]
|
tuple[float, float]: Test statistic and corresponding pvalue. |
Source code in gresit/independence_tests.py
Itest
Abstract meta class for independence tests.
Source code in gresit/independence_tests.py
test(x_data, y_data)
abstractmethod
Abstract method for independence tests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_data
|
ndarray | DataFrame | Series
|
Variables involved in the test |
required |
y_data
|
ndarray | DataFrame | Series
|
Variables involved in the test |
required |
Returns:
Type | Description |
---|---|
tuple[float, float | str]
|
tuple[float, float | str]: Test statistic and corresponding pvalue (Test decision). |
Source code in gresit/independence_tests.py
KernelCI
Bases: CItest
Kernel HSIC wrapper around causal-learn.
Source code in gresit/independence_tests.py
__init__()
test(x_data, y_data, z_data=None)
KCI test wrapper.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_data
|
ndarray
|
description |
required |
y_data
|
ndarray
|
description |
required |
z_data
|
ndarray | None
|
description. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
tuple[float, float]
|
tuple[float, float]: Test statistic and p_value. |
Source code in gresit/independence_tests.py
xi_vec_corr(x, y)
Compute the correlation coefficient between x and y.
according to the xi coefficient defined by Chatterjee.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
description |
required |
y
|
ndarray
|
description |
required |
Source code in gresit/independence_tests.py
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
ConvergenceError
Bases: Exception
Convenience class for convergence error.
Source code in gresit/model_selection.py
MURGS
Multi-Response Group Sparse Additive Mode (MURGS) class.
Source code in gresit/model_selection.py
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 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 |
|
R_g_hat_update(f_g, Y_data, g)
Update partial residuals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f_g
|
ndarray
|
Current additive components of shape (#samples, #groups, #predictors, #tasks) |
required |
Y_data
|
ndarray
|
Response data of shape (#samples, #tasks) |
required |
g
|
int
|
group in question. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Partial Residuals. |
Source code in gresit/model_selection.py
__init__(group_names=None)
Initializes the object.
Source code in gresit/model_selection.py
__repr__()
__str__()
Print some useful summary.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
description |
Source code in gresit/model_selection.py
block_coordinate_descent(X_data, Y_data, penalty, precalculate_smooths=True, smoothers=None, local_regression_method='kernel', warm_start_f_hat=None)
Block coordinate descent for multitask Sparse Group Lasso.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_data
|
ndarray | dict[str, ndarray]
|
description |
required |
Y_data
|
ndarray
|
description |
required |
penalty
|
float
|
description |
required |
precalculate_smooths
|
bool
|
description. Defaults to True. |
True
|
smoothers
|
ndarray | dict[str, ndarray] | None
|
description. Defaults to None. |
None
|
local_regression_method
|
str
|
Defaults to "loess". Other options currently: "kernel". |
'kernel'
|
warm_start_f_hat
|
ndarray | dict[str, ndarray] | None
|
description. Defaults to None. |
None
|
Source code in gresit/model_selection.py
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 |
|
fit(X_data, Y_data, nlambda=30, lambda_min_ratio=0.005, precalculate_smooths=True, local_regression_method='kernel')
Fit the multitask group SpAM.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_data
|
ndarray
|
description |
required |
Y_data
|
ndarray
|
description |
required |
nlambda
|
int
|
description. Defaults to 30. |
30
|
lambda_min_ratio
|
float
|
description. Defaults to 0.005. |
0.005
|
precalculate_smooths
|
bool
|
description. Defaults to True. |
True
|
local_regression_method
|
str
|
Defaults to "loess". Other options currently: "kernel". |
'kernel'
|
Source code in gresit/model_selection.py
functional_norm(array_data)
Sample estimate of functional norm for arrays of shape.
(#samples, #n_group_entries, #tasks).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array_data
|
ndarray
|
Array input data. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array of functional norm estimates. |
Source code in gresit/model_selection.py
gaussian_kernel_direct_fit(g, d_g, R_g, X_data)
Local regression fit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
int
|
group in question. |
required |
d_g
|
int
|
Number of predictors in group. |
required |
R_g
|
ndarray
|
Partial residuals should be of shape (#n_samples. #n_predictors, #n_tasks) |
required |
X_data
|
ndarray
|
Training data of shape (#n_samples. #n_groups, #n_predictors) |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Fitted local regressions. |
Source code in gresit/model_selection.py
gcv(Y_data)
Generalized cross-validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Y_data
|
ndarray
|
Response data of shape (#n_samples. #n_tasks). |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Value of GCV. |
Source code in gresit/model_selection.py
loess_direct_fit(g, d_g, R_g, X_data)
Local regression fit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
int
|
group in question. |
required |
d_g
|
int
|
Number of predictors in group. |
required |
R_g
|
ndarray
|
Partial residuals should be of shape (#n_samples. #n_predictors, #n_tasks) |
required |
X_data
|
ndarray
|
Training data of shape (#n_samples. #n_groups, #n_predictors) |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Fitted local regressions. |
Source code in gresit/model_selection.py
omega_hat(f_g)
Calculate Omega hat.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f_g
|
ndarray
|
description |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: description |
Source code in gresit/model_selection.py
plot_gcv_path()
Plot GCV path.
Source code in gresit/model_selection.py
plugin_bandwidth(x_j)
Plugin bandwidth for Gaussian Kernel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_j
|
ndarray
|
data. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Selected bandwidth. |
Source code in gresit/model_selection.py
precalculate_smooths(X_data, local_regression_method='kernel')
Precalculate smoother matrices.
Input may be both np.ndarray
and dict
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_data
|
ndarray | dict[str, ndarray]
|
predictor data. |
required |
local_regression_method
|
str
|
Method to use to calculate smoother matrix. Options
currently are |
'kernel'
|
Returns:
Type | Description |
---|---|
ndarray | dict[str, ndarray]
|
np.ndarray | dict[str, np.ndarray]: smooths. |
Source code in gresit/model_selection.py
predict()
Predict the model.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Predicted values of shape (#n_samples, #n_tasks) |
Source code in gresit/model_selection.py
predict_from_linear_smoother(g, smoothing_matrices, R_g)
Local regression fit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
int
|
group in question. |
required |
R_g
|
ndarray
|
Partial residuals should be of shape (#n_samples. #n_predictors, #n_tasks) |
required |
smoothing_matrices
|
ndarray
|
Precalculated smoothing matrices of shape (#n_samples, #n_samples #n_groups, #n_predictors) |
required |
Returns:
Type | Description |
---|---|
ndarray
|
torch.Tensor: Fitted local regressions. |
Source code in gresit/model_selection.py
return_nonzero_groups()
Return the group names of the nonzero groups.
Returns:
Type | Description |
---|---|
list[str]
|
list[str] | str: List of nonzero groups with their actual names if given. |
Source code in gresit/model_selection.py
select_penalty(X_data, Y_data, nlambda=30, lambda_min_ratio=0.005, smoothers=None, precalculate_smooths=True, local_regression_method='kernel')
GCV model selection procedure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_data
|
ndarray
|
description |
required |
Y_data
|
ndarray
|
description |
required |
nlambda
|
int
|
description. Defaults to 30. |
30
|
lambda_min_ratio
|
float
|
description. Defaults to 5e-3. |
0.005
|
precalculate_smooths
|
bool
|
description. Defaults to True. |
True
|
smoothers
|
ndarray | dict[str, ndarray] | None
|
description. Defaults to None. |
None
|
local_regression_method
|
str
|
Defaults to "loess". Other options currently: "kernel". |
'kernel'
|
Source code in gresit/model_selection.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 |
|
smoother_direct_fit(g, d_g, R_g, X_data, local_regression_method)
Direct fit of smoothing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
int
|
description |
required |
d_g
|
int
|
description |
required |
R_g
|
ndarray
|
description |
required |
X_data
|
ndarray
|
description |
required |
local_regression_method
|
str
|
description |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
description |
Returns:
Name | Type | Description |
---|---|---|
_type_ |
ndarray
|
description |
Source code in gresit/model_selection.py
soft_thresholding_update(g, f_g, zero_groups, smooth_fit, s_g_ordered, penalty, m_opt)
Soft-thresholding update.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
int
|
description |
required |
f_g
|
ndarray | dict[str, ndarray]
|
description |
required |
zero_groups
|
list[bool]
|
description |
required |
smooth_fit
|
ndarray
|
description |
required |
s_g_ordered
|
ndarray
|
description |
required |
penalty
|
float
|
description |
required |
m_opt
|
ndarray
|
description |
required |
Returns:
Type | Description |
---|---|
ndarray | dict[str, ndarray]
|
np.ndarray | dict[str, np.ndarray]: description |
Source code in gresit/model_selection.py
update_loop(f_g_hat, d_g, smooth_fit, s_g_ordered, penalty, m_opt)
Inner update loop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f_g_hat
|
ndarray
|
description |
required |
d_g
|
int
|
description |
required |
smooth_fit
|
ndarray
|
description |
required |
s_g_ordered
|
ndarray
|
description |
required |
penalty
|
float
|
description |
required |
m_opt
|
ndarray
|
description |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: description |
Source code in gresit/model_selection.py
Simulation
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Equation
Abstract class for non-linear equations.
Source code in gresit/synthetic_data.py
__call__(x)
abstractmethod
__init__(group_size, input_dim, rng=np.random.default_rng(seed=2024))
Abstract class for non-linear equations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim
|
int
|
parent dimension |
required |
group_size
|
int
|
description. Defaults to 2. |
required |
rng
|
Generator
|
Random number generator. Defaults to default rng. |
default_rng(seed=2024)
|
Source code in gresit/synthetic_data.py
FCNN
Bases: Equation
A randomly initialized fully connected neural net.
Source code in gresit/synthetic_data.py
__call__(x)
Computes the right hand side of the equation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
Input data |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: output data of size n x multioutput_dim |
Source code in gresit/synthetic_data.py
__init__(group_size, input_dim, rng=np.random.default_rng(seed=2024), hidden_layer=10)
A randomly initialized fully connected neural net.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim
|
int
|
parent dimension |
required |
group_size
|
int
|
description. Defaults to 2. |
required |
rng
|
Generator
|
Random number generator. Defaults to None. |
default_rng(seed=2024)
|
hidden_layer
|
int
|
Size of hidden dimension. |
10
|
Source code in gresit/synthetic_data.py
init_weights(m)
Initializes the weights of the neural net.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
Module
|
The layer to be initialized |
required |
Source code in gresit/synthetic_data.py
GaussianProcesses
Bases: Equation
A weighted sum of Gaussian processes.
Source code in gresit/synthetic_data.py
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 |
|
__call__(x)
Depending on the shape of x dimension will be adjusted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float | ndarray
|
Input data |
required |
Raises:
Type | Description |
---|---|
ValueError
|
Gets thrown when input dimensions don't match. |
Returns:
Type | Description |
---|---|
ndarray
|
float | np.ndarray: output data of size n x multioutput_dim |
Source code in gresit/synthetic_data.py
__init__(group_size, input_dim, rng=np.random.default_rng(seed=2024), n_gp=5, sigma=0.3)
A weighted sum of Gaussian processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim
|
int
|
parent dimension |
required |
group_size
|
int
|
description. Defaults to 2. |
required |
rng
|
Generator
|
Random number generator. Defaults to None. |
default_rng(seed=2024)
|
n_gp
|
int
|
Number of processes |
5
|
sigma
|
float
|
The standard deviation of GPs. Note that all GPS have the same std. |
0.3
|
Raises:
Type | Description |
---|---|
ValueError
|
Gets thrown when input dimensions don't match. |
Source code in gresit/synthetic_data.py
from_params(mean_vec, w1, w2, sigma=0.3, rng=np.random.default_rng(seed=2024))
staticmethod
Creates a gaussian process from parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mean_vec
|
ndarray
|
Mean vectors of Gaussian processes with shape=(group_size, num_parents, num_kernels), where num_parents is the dimension of the input variable and num_kernels is the number of Gaussian kernels in one GP. |
required |
w1
|
ndarray
|
Weights of GPs with shape=(num_parents, num_kernels). |
required |
w2
|
ndarray
|
Weights for aggregating GPs with shape=(n,) |
required |
sigma
|
float
|
The standard deviation of GPs. Note that all GPS have the same std. |
0.3
|
rng
|
Generator
|
The random number generator to use. |
default_rng(seed=2024)
|
Source code in gresit/synthetic_data.py
GenChainedData
Bases: GenData
Class to generate chain DAG with nonlinear data following multivariate ANM (mANM).
Source code in gresit/synthetic_data.py
__init__(number_of_nodes=15, equation_cls=GaussianProcesses, equation_kwargs=None, group_size=2, edge_density=0.2, rng=np.random.default_rng(seed=2024), snr=1.0, noise_distribution='gaussian')
Initiate the layered DAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Generator
|
Random number generator. Defaults to None. |
default_rng(seed=2024)
|
number_of_nodes
|
int
|
description. Defaults to 15. |
15
|
equation_cls
|
Equation
|
The type of the equation that should be used. |
GaussianProcesses
|
equation_kwargs
|
dict
|
Arguments for equation. |
None
|
group_size
|
int
|
Number of entries in groups. Defaults to 2. |
2
|
edge_density
|
float
|
description. Defaults to 0.2. |
0.2
|
snr
|
float
|
Signal to noise ratio. Defaults to 1.0. |
1.0
|
noise_distribution
|
str
|
Which distribution to choose for the noise.
defaults to Gaussian noise. Options include: |
'gaussian'
|
Source code in gresit/synthetic_data.py
GenData
Parent class to GenDate classes.
Source code in gresit/synthetic_data.py
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 |
|
__init__(number_of_nodes=15, equation_cls=GaussianProcesses, equation_kwargs=None, group_size=2, edge_density=0.2, rng=np.random.default_rng(seed=2024), snr=1.0, noise_distribution='gaussian')
Initiate parent class DAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Generator
|
Random number generator. Defaults to None. |
default_rng(seed=2024)
|
number_of_nodes
|
int
|
description. Defaults to 15. |
15
|
equation_cls
|
Equation
|
The type of the equation that should be used. |
GaussianProcesses
|
equation_kwargs
|
dict
|
Arguments for equation. |
None
|
group_size
|
int
|
Number of entries in groups. Defaults to 2. |
2
|
edge_density
|
float
|
description. Defaults to 0.2. |
0.2
|
snr
|
float
|
Signal to noise ratio. Defaults to 1.0. |
1.0
|
noise_distribution
|
str
|
Which distribution to choose for the noise.
defaults to Gaussian noise. Options include: |
'gaussian'
|
Source code in gresit/synthetic_data.py
generate_data(num_samples=1000)
Sample data from the layered DAG.
Source code in gresit/synthetic_data.py
GenERData
Bases: GenData
Class to generate general nonlinear data following Erdos-Renyi (ER) graph.
Source code in gresit/synthetic_data.py
__init__(number_of_nodes=15, equation_cls=GaussianProcesses, equation_kwargs=None, group_size=2, edge_density=0.2, rng=np.random.default_rng(seed=2024), snr=1.0, noise_distribution='gaussian')
Initiate the ER DAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Generator
|
Random number generator. Defaults to None. |
default_rng(seed=2024)
|
number_of_nodes
|
int
|
description. Defaults to 15. |
15
|
equation_cls
|
Equation
|
The type of the equation that should be used. |
GaussianProcesses
|
equation_kwargs
|
dict
|
Arguments for equation. |
None
|
group_size
|
int
|
Number of entries in groups. Defaults to 2. |
2
|
edge_density
|
float
|
description. Defaults to 0.2. |
0.2
|
snr
|
float
|
Signal to noise ratio. Defaults to 1.0. |
1.0
|
noise_distribution
|
str
|
Which distribution to choose for the noise.
defaults to Gaussian noise. Options include: |
'gaussian'
|
Source code in gresit/synthetic_data.py
GenLayeredData
Bases: GenData
Class to generate general nonlinear data following multivariate ANM (mANM).
Source code in gresit/synthetic_data.py
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 |
|
__init__(number_of_nodes=15, number_of_layers=3, equation_cls=GaussianProcesses, equation_kwargs=None, group_size=2, edge_density=0.2, rng=np.random.default_rng(seed=2024), snr=1.0, noise_distribution='gaussian')
Initiate the layered DAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Generator
|
Random number generator. Defaults to None. |
default_rng(seed=2024)
|
number_of_nodes
|
int
|
description. Defaults to 15. |
15
|
number_of_layers
|
int
|
description. Defaults to 3. |
3
|
equation_cls
|
Equation
|
The type of the equation that should be used. |
GaussianProcesses
|
equation_kwargs
|
dict
|
Arguments for equation. |
None
|
group_size
|
int
|
Number of entries in groups. Defaults to 2. |
2
|
edge_density
|
float
|
description. Defaults to 0.2. |
0.2
|
snr
|
float
|
Signal to noise ratio. Defaults to 1.0. |
1.0
|
noise_distribution
|
str
|
Which distribution to choose for the noise.
defaults to Gaussian noise. Options include: |
'gaussian'
|
Source code in gresit/synthetic_data.py
all_causal_orderings()
Valid causal ordering of the layered DAG.
Raises:
Type | Description |
---|---|
ValueError
|
If there are no nodes or edges. |
Returns:
Type | Description |
---|---|
list[list[str]]
|
list[list[str]]: list of causal orders. |
Source code in gresit/synthetic_data.py
MultiOutputANM
Class to construct nonlinear multi-outcome data that follows an ANM.
Source code in gresit/synthetic_data.py
__init__(input_dim, equation_cls=GaussianProcesses, equation_kwargs=None, group_size=2, snr=1.0, rng=np.random.default_rng(seed=2024))
Initiates the ANM object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim
|
int
|
parent dimension |
required |
group_size
|
int
|
description. Defaults to 2. |
2
|
rng
|
Generator
|
Random number generator. Defaults to None. |
default_rng(seed=2024)
|
equation_cls
|
Equation
|
The type of the equation that should be used. |
GaussianProcesses
|
equation_kwargs
|
dict
|
Arguments for equation. |
None
|
snr
|
float
|
Signal-to-noise ratio. Defaults to 1.0. |
1.0
|
Source code in gresit/synthetic_data.py
apply_rhs(parent_data, noise_data)
See whether this works.
Source code in gresit/synthetic_data.py
generate_nonlinear_map()
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
BenchMarker
Class to instantiate and run simulations.
Source code in gresit/simulation_utils.py
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 |
|
run_benchmark(params, num_runs=30, metrics=['shd', 'sid', 'ancestor_aid', 'ancester_ordering_aid'], cpdag_strategy='random_dag')
Benchmark run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_runs
|
int
|
description. Defaults to 30. |
30
|
params
|
ExperimenParams
|
Params to benchmark |
required |
metrics
|
list[str]
|
description. Defaults to ["shd", "sid", "ancestor_aid", "ancester_ordering_aid"]. |
['shd', 'sid', 'ancestor_aid', 'ancester_ordering_aid']
|
cpdag_strategy
|
str
|
How to convert CPDAG to DAG to enable fair comparison.
Options are |
'random_dag'
|
Source code in gresit/simulation_utils.py
write_results(results, path)
Write results to JSON files with time signature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results
|
defaultdict[str, defaultdict[str, list[int | float | None]]]
|
Result dict from a benchmark run. |
required |
path
|
str
|
Destination path where to save files. |
required |
Source code in gresit/simulation_utils.py
draw_result_boxplots(result_dict, title='', file_path=None, file_name='example_name')
Draw full set of result boxplots.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_dict
|
dict
|
description |
required |
title
|
str
|
title of the plot. |
''
|
file_path
|
str | None
|
description. Defaults to None. |
None
|
file_name
|
str | None
|
description. Defaults to None. |
'example_name'
|
Source code in gresit/simulation_utils.py
Utils
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Loss functions for training the model.
loss_hsic()
taken from https://github.com/danielgreenfeld3/XIC/blob/master/hsic.py as
used in paper https://arxiv.org/abs/1910.00270
GaussianKernelMatrix(x, sigma=None)
Get gaussian kernel matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
description |
required |
sigma
|
float
|
description. Defaults the median heuristic when None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
_type_ |
Tensor
|
description |
Source code in gresit/losses.py
HSIC(x, y, s_x=None, s_y=None, device='cpu')
Get test statistic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
description |
required |
y
|
Tensor
|
description |
required |
s_x
|
float
|
description. Defaults to None. |
None
|
s_y
|
float
|
description. Defaults to None. |
None
|
device
|
str
|
description. Defaults to "cpu". |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: description |
Source code in gresit/losses.py
loss_disco(x, y_pred, y_true, device='cpu')
Get UCRT loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
description |
required |
y_pred
|
Tensor
|
description |
required |
y_true
|
Tensor
|
description |
required |
device
|
str
|
description. Defaults to "cpu". |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: description |
Source code in gresit/losses.py
loss_hsic(x, y_pred, y_true, device='cpu')
Get HSIC loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
description |
required |
y_pred
|
Tensor
|
description |
required |
y_true
|
Tensor
|
description |
required |
device
|
str
|
description. Defaults to "cpu". |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: description |
Source code in gresit/losses.py
loss_mse(x, y_pred, y_true, device='cpu')
MSE loss.
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: description |
Source code in gresit/losses.py
pairwise_distances(x)
Get pairwise distance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
description |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: description |
Source code in gresit/losses.py
u_distance_cov_squared(a, b, device='cpu', robust=False)
Unbiased squared distance covariance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
Tensor
|
description |
required |
b
|
Tensor
|
description |
required |
device
|
str
|
device to run on. |
'cpu'
|
robust
|
bool
|
if you want to make sure that the joint finite first moment
condition for the distance covariance holds, setting |
False
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: description |
Source code in gresit/losses.py
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
BoostedRegressionTrees
Bases: MultiRegressor
Boosted multi-outcome regression trees.
This is simply a wrapper around the xgboost XGBRegressor
class.
Source code in gresit/regression_techniques.py
__init__()
fit(X, Y)
Fit boosted multi-outcome regression trees to training data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
training data predictors |
required |
Y
|
ndarray
|
training data (multi-) targets |
required |
Source code in gresit/regression_techniques.py
predict(X_test=None)
Predict using fitted boosted multi-outcome regression trees.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_test
|
ndarray
|
Test data to predict on. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Predicted values. |
Source code in gresit/regression_techniques.py
CurdsWhey
Bases: MultiRegressor
Breiman and Friedman's curds and whey multivariate regression model.
When regression problem is of multivariate nature and the outcome variables are related among another, more accurate predictions may be obtained by using a linear combination of the OLS predictors.
Source code in gresit/regression_techniques.py
__init__()
Initializes C&W linear shrinkage method.
fit(X, Y)
Fits the C&W model to the multivariate X and Y.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Matrix of predictors |
required |
Y
|
ndarray
|
Matrix of responses |
required |
Source code in gresit/regression_techniques.py
predict(X_test=None)
Predict response matrix based on X data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_test
|
ndarray
|
Matrix of responses |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: predicted values. |
Source code in gresit/regression_techniques.py
MultiRegressor
Abstract class for multivariate regression.
Source code in gresit/regression_techniques.py
__init__(rng=np.random.default_rng(seed=2024), **kwargs)
fit(X, Y)
abstractmethod
Fit the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Matrix of predictors |
required |
Y
|
ndarray
|
Matrix of responses |
required |
mse(Y_test, X_test)
Mean squared error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Y_test
|
ndarray
|
Test response |
required |
X_test
|
ndarray
|
Test predictors |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
MSE |
Source code in gresit/regression_techniques.py
predict(X_test)
abstractmethod
Predict given data matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_test
|
ndarray
|
data matrix to predict on. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: (Matrix of) predicted values |
split_and_standardize(X, Y, test_size=0.2)
Train test split and standardize data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
predictors |
required |
Y
|
ndarray
|
targets |
required |
test_size
|
float
|
Size of test data |
0.2
|
Returns:
Type | Description |
---|---|
tuple[ndarray, ndarray, ndarray, ndarray]
|
tuple[np.ndarray]: X_train, X_test, Y_train, Y_test |
Source code in gresit/regression_techniques.py
standardize(a)
Standardize data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
ndarray
|
description |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: description |
ReducedRankRegressor
Bases: MultiRegressor
Kernel Reduced Rank Ridge Regression.
Source code in gresit/regression_techniques.py
__init__(rank, alpha=1.0)
Initializes the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rank
|
int
|
Rank constraint. |
required |
alpha
|
float64
|
Regularization parameter. Defaults to 1.0. |
1.0
|
Source code in gresit/regression_techniques.py
__str__()
fit(X, Y)
Fit kRRR model to data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
training data predictors |
required |
Y
|
ndarray
|
training (multivariate) response |
required |
Source code in gresit/regression_techniques.py
predict(X_test=None)
Predict fitted kRRR model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_test
|
ndarray
|
Test data to predict on. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Predicted values. |
Source code in gresit/regression_techniques.py
SimultaneousLinearModel
Bases: MultiRegressor
Class for performing multivariate linear Regression.
Source code in gresit/regression_techniques.py
__init__(rng=np.random.default_rng(seed=2024), alpha=0.1)
Initializes with a ridge penalty equal to 0.1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Generator
|
A random generator |
default_rng(seed=2024)
|
alpha
|
float
|
Penalty term. Defaults to 0.1. |
0.1
|
Source code in gresit/regression_techniques.py
__str__()
fit(X, Y)
Fit multivariate linear regression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
Matrix of predictors |
required |
Y
|
ndarray
|
Matrix of responses |
required |
Source code in gresit/regression_techniques.py
predict(X_test=None)
Predict given data matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_test
|
ndarray
|
data matrix to predict on. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: (Matrix of) predicted values |
Source code in gresit/regression_techniques.py
Utility classes and functions related to gresit.
Copyright (c) 2025 Robert Bosch GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
DAG
Bases: GRAPH
General class for dealing with directed acyclic graph i.e.
graphs that are directed and must not contain any cycles.
Source code in gresit/graphs.py
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 |
|
adjacency_matrix
property
Returns adjacency matrix.
The i,jth entry being one indicates that there is an edge from i to j. A zero indicates that there is no edge.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: adjacency matrix |
causal_order
property
Returns the causal order of the current graph.
Note that this order is in general not unique.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: Causal order |
edges
property
Gives all directed edges in current DAG.
Returns:
Type | Description |
---|---|
list[tuple[str, str]]
|
list[tuple[str,str]]: List of directed edges. |
max_in_degree
property
Maximum in-degree of the graph.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Maximum in-degree |
max_out_degree
property
Maximum out-degree of the graph.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Maximum out-degree |
nodes
property
Get all nods in current DAG.
Returns:
Name | Type | Description |
---|---|---|
list |
list[str]
|
list of nodes. |
num_edges
property
Number of directed edges in current DAG.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of directed edges |
num_nodes
property
Number of nodes in current DAG.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of nodes |
random_state
property
writable
Current random state.
Returns:
Type | Description |
---|---|
Generator
|
np.random.Generator: Generator object. |
sink_nodes
property
Returns all sink nodes, i.e.
nodes with no descendents in particular no children.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: list of sink nodes. |
source_nodes
property
Returns all source nodes, i.e.
nodes with no ancesters in particular no parents.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: list of sink nodes. |
sparsity
property
Sparsity of the graph.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
in [0,1] |
__init__(nodes=None, edges=None)
DAG constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list[str] | None
|
Nodes. Defaults to None. |
None
|
edges
|
list[tuple[str, str]] | None
|
Edges. Defaults to None. |
None
|
Source code in gresit/graphs.py
add_edge(edge)
add_edges_from(edges)
Add multiple edges to DAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges
|
list[tuple[str, str]]
|
Edges to add |
required |
add_node(node)
add_nodes_from(nodes)
Add multiple nodes to DAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list[str]
|
nodes to add |
required |
children(of_node)
Gives all children of node node
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
of_node
|
str
|
node in current DAG. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list[str]
|
of children. |
Source code in gresit/graphs.py
copy()
from_nx(nx_dag, *args, **kwargs)
classmethod
Convert to DAG from nx.DiGraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nx_dag
|
DiGraph
|
DAG in question. |
required |
args
|
Any
|
additional arguments |
()
|
kwargs
|
Any
|
additional arguments |
{}
|
Raises:
Type | Description |
---|---|
TypeError
|
If DAG is not nx.DiGraph |
Returns:
Type | Description |
---|---|
DAG
|
DAG |
Source code in gresit/graphs.py
from_pandas_adjacency(pd_amat, *args, **kwargs)
classmethod
Build DAG from a Pandas adjacency matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pd_amat
|
DataFrame
|
input adjacency matrix. |
required |
args
|
Any
|
Additional arguments. |
()
|
kwargs
|
Any
|
Additional arguments. |
{}
|
Returns:
Type | Description |
---|---|
DAG
|
DAG |
Source code in gresit/graphs.py
induced_subgraph(nodes)
Returns the induced subgraph on the nodes in nodes
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list[str]
|
List of nodes. |
required |
Returns:
Name | Type | Description |
---|---|---|
DAG |
DAG
|
Induced subgraph. |
Source code in gresit/graphs.py
is_acyclic()
Check if the graph is acyclic.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if graph is acyclic. |
is_adjacent(i, j)
Return True if the graph contains an directed edge between i and j.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i
|
str
|
node i. |
required |
j
|
str
|
node j. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if i->j or i<-j |
Source code in gresit/graphs.py
is_clique(potential_clique)
Check every pair of node X potential_clique is adjacent.
parents(of_node)
Gives all parents of node node
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
of_node
|
str
|
node in current DAG. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list[str]
|
of parents. |
Source code in gresit/graphs.py
remove_edge(i, j)
Removes edge in question.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i
|
str
|
tail |
required |
j
|
str
|
head |
required |
Raises:
Type | Description |
---|---|
AssertionError
|
if edge does not exist |
Source code in gresit/graphs.py
remove_node(node)
Remove a node from the graph.
Source code in gresit/graphs.py
show()
to_cpdag()
to_networkx()
Convert to networkx graph.
Returns:
Type | Description |
---|---|
DiGraph
|
nx.MultiDiGraph: Graph with directed and undirected edges. |
Source code in gresit/graphs.py
vstructs()
Retrieve v-structures.
Returns:
Name | Type | Description |
---|---|---|
set |
set[tuple[str, str]]
|
set of all v-structures |
Source code in gresit/graphs.py
GRAPH
Abstract base class for all Graphs in current project.
Source code in gresit/graphs.py
adjacency_matrix
abstractmethod
property
Return adjacency matrix.
Raises:
Type | Description |
---|---|
AssertionError
|
description |
AssertionError
|
description |
ValueError
|
description |
AssertionError
|
description |
AssertionError
|
description |
TypeError
|
description |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Adjacency matrix of underlying graph. |
causal_order
abstractmethod
property
Return causal order.
Raises:
Type | Description |
---|---|
AssertionError
|
description |
AssertionError
|
description |
ValueError
|
description |
AssertionError
|
description |
AssertionError
|
description |
TypeError
|
description |
Returns:
Type | Description |
---|---|
list[str] | None
|
list[str] | None: Causal order of underlying graph. None if not a DAG. |
LayeredDAG
Bases: DAG
Class to construct Layered DAGs.
Layered DAGs L
are DAGs where the Nodes V
follow some natural layering.
In other words, no edge can ever point into any of the earlier layers.
Source code in gresit/graphs.py
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 |
|
layering
property
writable
Current layering dict.
Returns:
Type | Description |
---|---|
dict[str, list[str]] | None
|
dict[str, list[str]]: Layering |
__init__(nodes=None, edges=None, layering=None)
Layered DAG constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list[str] | None
|
Nodes of LDAG. Defaults to None. |
None
|
edges
|
list[tuple[str, str]] | None
|
Edges of LDAG. Defaults to None. |
None
|
layering
|
dict[str, list[str]] | None
|
Layering. Defaults to None. |
None
|
Source code in gresit/graphs.py
copy()
from_nx(nx_dag, layering)
classmethod
Convert to DAG from nx.DiGraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nx_dag
|
DiGraph
|
DAG in question. |
required |
layering
|
dict[str, list[str]]
|
layering of nodes. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
If DAG is not nx.DiGraph |
Returns:
Type | Description |
---|---|
LayeredDAG
|
LayeredDAG |
Source code in gresit/graphs.py
from_pandas_adjacency(pd_amat, layering)
classmethod
Build LayeredDAG from a Pandas adjacency matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pd_amat
|
DataFrame
|
input adjacency matrix. |
required |
layering
|
dict[str, list[str]]
|
layering of nodes. |
required |
Returns:
Type | Description |
---|---|
LayeredDAG
|
LayeredDAG |
Source code in gresit/graphs.py
layer_induced_subgraph(nodes)
Returns the induced subgraph on the nodes in nodes
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list[str]
|
List of nodes. |
required |
Returns:
Name | Type | Description |
---|---|---|
DAG |
DAG
|
Induced subgraph. |
Source code in gresit/graphs.py
PDAG
Bases: GRAPH
Class for dealing with partially directed graph i.e.
graphs that contain both directed and undirected edges.
Source code in gresit/graphs.py
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 |
|
adjacency_matrix
property
Returns adjacency matrix.
The i,jth entry being one indicates that there is an edge from i to j. A zero indicates that there is no edge.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: adjacency matrix |
causal_order
property
Causal order is None.
This is because PDAGs only allow for a partial causal order.
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
None |
dir_edges
property
Gives all directed edges in current PDAG.
Returns:
Type | Description |
---|---|
list[tuple[str, str]]
|
list[tuple[str,str]]: List of directed edges. |
nodes
property
Get all nods in current PDAG.
Returns:
Name | Type | Description |
---|---|---|
list |
list[str]
|
list of nodes. |
num_adjacencies
property
Number of adjacent nodes in current PDAG.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of adjacent nodes |
num_dir_edges
property
Number of directed edges in current PDAG.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of directed edges |
num_nodes
property
Number of nodes in current PDAG.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of nodes |
num_undir_edges
property
Number of undirected edges in current PDAG.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of undirected edges |
undir_edges
property
Gives all undirected edges in current PDAG.
Returns:
Type | Description |
---|---|
list[tuple[str, str]]
|
list[tuple[str,str]]: List of undirected edges. |
__init__(nodes=None, dir_edges=None, undir_edges=None)
PDAG constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list[str] | None
|
Nodes in the PDAG. Defaults to None. |
None
|
dir_edges
|
list[tuple[str, str]] | None
|
directed edges. Defaults to None. |
None
|
undir_edges
|
list[tuple[str, str]] | None
|
undirected edges. Defaults to None. |
None
|
Source code in gresit/graphs.py
children(node)
Gives all children of node node
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
str
|
node in current PDAG. |
required |
Returns:
Name | Type | Description |
---|---|---|
set |
set[str]
|
set of children. |
Source code in gresit/graphs.py
copy()
from_pandas_adjacency(pd_amat)
classmethod
Build PDAG from a Pandas adjacency matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pd_amat
|
DataFrame
|
input adjacency matrix. |
required |
Returns:
Type | Description |
---|---|
PDAG
|
PDAG |
Source code in gresit/graphs.py
is_adjacent(i, j)
Return True if the graph contains an directed or undirected edge between i and j.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i
|
str
|
node i. |
required |
j
|
str
|
node j. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if i-j or i->j or i<-j |
Source code in gresit/graphs.py
is_clique(potential_clique)
Check every pair of node X potential_clique is adjacent.
neighbors(node)
Gives all neighbors of node node
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
str
|
node in current PDAG. |
required |
Returns:
Name | Type | Description |
---|---|---|
set |
set[str]
|
set of neighbors. |
Source code in gresit/graphs.py
parents(node)
Gives all parents of node node
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
str
|
node in current PDAG. |
required |
Returns:
Name | Type | Description |
---|---|---|
set |
set[str]
|
set of parents. |
Source code in gresit/graphs.py
remove_edge(i, j)
Removes edge in question.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i
|
str
|
tail |
required |
j
|
str
|
head |
required |
Raises:
Type | Description |
---|---|
AssertionError
|
if edge does not exist |
Source code in gresit/graphs.py
remove_node(node)
Remove a node from the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
str
|
node to remove |
required |
Source code in gresit/graphs.py
show()
to_allDAGs()
Recursion algorithm which recursively applies the following steps.
1. Orient the first undirected edge found.
2. Apply Meek rules.
3. Recurse with each direction of the oriented edge.
This corresponds to Algorithm 2 in Wienöbst et al. (2023).
References
Wienöbst, Marcel, et al. "Efficient enumeration of Markov equivalent DAGs." Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 37. No. 10. 2023.
Source code in gresit/graphs.py
to_dag()
Algorithm as described in Chickering (2002).
1. From PDAG P create DAG G containing all directed edges from P
2. Repeat the following: Select node v in P s.t.
i. v has no outgoing edges (children) i.e. \\(ch(v) = \\emptyset \\)
ii. \\(neigh(v) \\neq \\emptyset\\)
Then \\( (pa(v) \\cup (neigh(v) \\) form a clique.
For each v that is in a clique and is part of an undirected edge in P
i.e. w - v, insert a directed edge w -> v in G.
Remove v and all incident edges from P and continue with next node.
Until all nodes have been deleted from P.
Returns:
Type | Description |
---|---|
DiGraph
|
nx.DiGraph: DAG that belongs to the MEC implied by the PDAG |
Source code in gresit/graphs.py
to_networkx()
Convert to networkx graph.
Returns:
Type | Description |
---|---|
MultiDiGraph
|
nx.MultiDiGraph: Graph with directed and undirected edges. |
Source code in gresit/graphs.py
to_random_dag()
Provides a random DAG residing in the MEC.
Returns:
Type | Description |
---|---|
DAG
|
nx.DiGraph: random DAG living in MEC |
Source code in gresit/graphs.py
undir_neighbors(node)
Gives all undirected neighbors of node node
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
str
|
node in current PDAG. |
required |
Returns:
Name | Type | Description |
---|---|---|
set |
set[str]
|
set of undirected neighbors. |
Source code in gresit/graphs.py
undir_to_dir_edge(tail, head)
Takes a undirected edge and turns it into a directed one.
tail indicates the starting node of the edge and head the end node, i.e. tail -> head.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tail
|
str
|
starting node |
required |
head
|
str
|
end node |
required |
Raises:
Type | Description |
---|---|
AssertionError
|
if edge does not exist or is not undirected. |
Source code in gresit/graphs.py
vstructs()
Retrieve v-structures.
Returns:
Name | Type | Description |
---|---|---|
set |
set[tuple[str, str]]
|
set of all v-structures |
Source code in gresit/graphs.py
dag2cpdag(dag)
Convertes a DAG into its unique CPDAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dag
|
DiGraph
|
DAG the CPDAG corresponds to. |
required |
Returns:
Name | Type | Description |
---|---|---|
PDAG |
PDAG
|
unique CPDAG |
Source code in gresit/graphs.py
rule_1(pdag)
Applies first Meek rule.
Given the following pattern X -> Y - Z. Orient Y - Z to Y -> Z if X and Z are non-adjacent (otherwise a new v-structure arises).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdag
|
PDAG
|
PDAG before application of rule. |
required |
Returns:
Name | Type | Description |
---|---|---|
PDAG |
PDAG
|
PDAG after application of rule. |
Source code in gresit/graphs.py
rule_2(pdag)
Applies the second Meek rule.
Given the following directed triple X -> Y -> Z where X - Z are indeed adjacent. Orient X - Z to X -> Z otherwise a cycle arises.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdag
|
PDAG
|
PDAG before application of rule. |
required |
Returns:
Name | Type | Description |
---|---|---|
PDAG |
PDAG
|
PDAG after application of rule. |
Source code in gresit/graphs.py
rule_3(pdag)
Apply 3rd Meek rule.
Orient X - Z to X -> Z, whenever there are two triples X - Y1 -> Z and X - Y2 -> Z such that Y1 and Y2 are non-adjacent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdag
|
PDAG
|
PDAG before application of rule. |
required |
Returns:
Name | Type | Description |
---|---|---|
PDAG |
PDAG
|
PDAG after application of rule. |
Source code in gresit/graphs.py
rule_4(pdag)
Apply 4th Meek rule.
Orient X - Y1 to X -> Y1, whenever there are two triples with X - Z and X - Y1 <- Z and X - Y2 -> Z such that Y1 and Y2 are non-adjacent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdag
|
PDAG
|
PDAG before application of rule. |
required |
Returns:
Name | Type | Description |
---|---|---|
PDAG |
PDAG
|
PDAG after application of rule. |
Source code in gresit/graphs.py
vstructs(dag)
Retrieve all v-structures in a DAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dag
|
DiGraph
|
DAG in question |
required |
Returns:
Name | Type | Description |
---|---|---|
set |
set[tuple[str, str]]
|
Set of all v-structures. |