Data¶
dataclasses
¶
VariableType
dataclass
¶
Dataclass for storing type information of the input variables
Source code in vambn/data/dataclasses.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
__eq__(__value)
¶
Test if two VariableTypes are equal
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__value |
VariableType
|
Second VariableType object |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True or false |
Source code in vambn/data/dataclasses.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
reverse_scale(x)
¶
Use the variable's scaler to invert the transformation so that the original input format is restored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
tensor
|
The transformed input tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Inverse transformed output |
Source code in vambn/data/dataclasses.py
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 |
|
check_equal_types(a, b)
¶
Check if two lists of variable types are equal
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
List[VariableType]
|
First list of variable types |
required |
b |
List[VariableType]
|
Second list of variable types |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if equal, False otherwise |
Source code in vambn/data/dataclasses.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
get_input_dim(types)
¶
Get the input dimension of a list of variable types
Parameters:
Name | Type | Description | Default |
---|---|---|---|
types |
List[VariableType]
|
List of variable types |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Sum of input dimensions |
Source code in vambn/data/dataclasses.py
96 97 98 99 100 101 102 103 104 105 106 |
|
datasets
¶
IterDataset
¶
Bases: Dataset
Source code in vambn/data/datasets.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
ndim: int
property
¶
Input dimensionality of the dataset.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Dimensionality of the dataset. |
__getitem__(idx)
¶
Get the data and the missing mask for a specific index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Index of the sample. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: Data and missing mask for the sample. |
Source code in vambn/data/datasets.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
__init__(data, missing_mask, types)
¶
Initialize the IterDataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Tensor containing the data. |
required |
missing_mask |
Tensor
|
Tensor with the corresponding missing mask (0=missing, 1=available). |
required |
types |
List[VariableType]
|
List of VariableType, each specifying dtype, ndim, and nclasses. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If data or missing_mask is not 2-dimensional, or if data contains NaN values. |
Source code in vambn/data/datasets.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
__len__()
¶
Get the number of samples in the dataset.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of samples. |
Source code in vambn/data/datasets.py
71 72 73 74 75 76 77 78 |
|
subset(idx)
¶
Create a subset of the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
List[int]
|
Indices of the samples to be selected. |
required |
Returns:
Name | Type | Description |
---|---|---|
IterDataset |
IterDataset
|
Subset of the dataset. |
Source code in vambn/data/datasets.py
80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
to(device)
¶
Move the dataset to a specified device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device
|
The device to move the dataset to. |
required |
Returns:
Name | Type | Description |
---|---|---|
IterDataset |
IterDataset
|
The dataset moved to the specified device. |
Source code in vambn/data/datasets.py
104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
LongitudinalDataset
¶
Bases: Dataset
Dataset for longitudinal data, where each sample consists of multiple visits/timepoints.
Attributes:
Name | Type | Description |
---|---|---|
data |
Tensor
|
Tensor containing the data. |
missing_mask |
Tensor
|
Tensor indicating missing data (0=missing, 1=available). |
types |
List[VariableType]
|
List of VariableType objects containing dtype, ndim, and nclasses. |
Source code in vambn/data/datasets.py
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 |
|
ndim: int
property
¶
Input dimensionality of the dataset.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Input dimensionality of the dataset. |
num_visits: int
property
¶
Number of visits/timepoints in the dataset.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of visits/timepoints. |
__getitem__(idx)
¶
Get the longitudinal data and the missing mask for a specific index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Index of the sample. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: 3D tensor with the data and 3D tensor with the missing mask for the sample. |
Source code in vambn/data/datasets.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
__init__(data, missing_mask, types)
¶
Initialize the LongitudinalDataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Tensor containing the data. |
required |
missing_mask |
Tensor
|
Tensor indicating missing data (0=missing, 1=available). |
required |
types |
List[VariableType]
|
List of VariableType objects containing dtype, ndim, and nclasses. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
Source code in vambn/data/datasets.py
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 |
|
__len__()
¶
Number of samples in the dataset.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of samples. |
Source code in vambn/data/datasets.py
189 190 191 192 193 194 195 196 |
|
subset(idx)
¶
Create a subset of the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
List[int]
|
Indices of the samples to be selected. |
required |
Returns:
Name | Type | Description |
---|---|---|
LongitudinalDataset |
LongitudinalDataset
|
Subset of the dataset. |
Source code in vambn/data/datasets.py
198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
to(device)
¶
Move the dataset to the specified device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device
|
The device to which the data and mask should be moved. |
required |
Returns:
Name | Type | Description |
---|---|---|
LongitudinalDataset |
LongitudinalDataset
|
The dataset on the specified device. |
Source code in vambn/data/datasets.py
160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
ModuleDataset
dataclass
¶
A class to represent a module dataset.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the dataset. |
data |
DataFrame
|
The data of the dataset. |
mask |
DataFrame
|
The mask for the dataset. |
variable_types |
List[VariableType]
|
The variable types for the dataset. |
scalers |
Tuple[Optional[StandardScaler | LogStdScaler]]
|
The scalers for the dataset. |
columns |
List[str]
|
The columns of the dataset. |
subjects |
List[str]
|
The subjects in the dataset. |
visit_number |
int
|
The visit number. Defaults to 1. |
id_name |
Optional[str]
|
The ID name for the dataset. Defaults to None. |
ndim |
int
|
The number of dimensions. Defaults to -1. |
device |
device
|
The device to use. Defaults to torch.device("cpu"). |
move_to_device |
bool
|
Whether to move the data to the specified device. Defaults to True. |
Source code in vambn/data/datasets.py
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 |
|
input_data: Tensor
property
¶
Get the input data as a tensor with nan values replaced by 0.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
Data tensor. |
input_mask: Tensor
property
¶
Get the input mask as a tensor with nan values replaced by 0.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
Mask tensor. |
pytorch_dataset: IterDataset
property
¶
Get a PyTorch compatible dataset based on the given data and mask.
Returns:
Name | Type | Description |
---|---|---|
IterDataset |
IterDataset
|
PyTorch compatible dataset. |
__post_init__()
¶
Validate and initialize the dataset attributes after the object is created.
Raises:
Type | Description |
---|---|
Exception
|
If the length of variable_types does not match the number of columns in data. |
Exception
|
If the length of columns does not match the number of columns in data or variable_types. |
Exception
|
If the length of subjects does not match the number of rows in data. |
Source code in vambn/data/datasets.py
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 |
|
__str__()
¶
String representation of the ModuleDataset object.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string representation of the ModuleDataset. |
Source code in vambn/data/datasets.py
388 389 390 391 392 393 394 395 |
|
subset(idx)
¶
Subset the data and mask by a list of indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
List[int] | ndarray
|
Indices of the samples to be selected. |
required |
Returns:
Name | Type | Description |
---|---|---|
ModuleDataset |
ModuleDataset
|
New ModuleDataset object with the subsetted data and mask. |
Source code in vambn/data/datasets.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
to(device)
¶
Move the dataset to a specific device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device
|
Device to be used. |
required |
Returns:
Name | Type | Description |
---|---|---|
ModuleDataset |
ModuleDataset
|
Dataset on the specified device. |
Source code in vambn/data/datasets.py
301 302 303 304 305 306 307 308 309 310 311 312 |
|
to_pandas()
¶
Convert the data and mask to pandas DataFrame.
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Data and mask as pandas DataFrame. |
Source code in vambn/data/datasets.py
375 376 377 378 379 380 381 382 383 384 385 386 |
|
VambnDataset
¶
Bases: Dataset
Dataset for the VAMBN model.
Attributes:
Name | Type | Description |
---|---|---|
modules |
List[ModuleDataset]
|
List of module datasets. |
module_names |
List[str]
|
List of unique module names. |
num_patients |
int
|
Number of patients in the dataset. |
visits_per_module |
Optional[dict]
|
Dictionary of visits per module. |
selected_modules |
List[str]
|
List of selected modules. |
selected_visits |
List[int]
|
List of selected visits. |
num_timepoints |
int
|
Number of timepoints. |
subj |
List[str]
|
List of subject IDs. |
device |
device
|
Device to use for tensor operations. |
Source code in vambn/data/datasets.py
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 |
|
is_longitudinal: bool
property
¶
Check if the dataset is longitudinal.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the dataset is longitudinal, False otherwise. |
num_modules: int
property
¶
Get the number of modules in the dataset.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of modules. |
__getitem__(idx)
¶
Get the data and mask for a specific index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Index of the sample. |
required |
Returns:
Type | Description |
---|---|
tuple[list[Tensor], list[Tensor]]
|
tuple[list[Tensor], list[Tensor]]: Data and mask tensors. |
Source code in vambn/data/datasets.py
477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
__init__(modules)
¶
Initialize the VambnDataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modules |
List[ModuleDataset]
|
Modules to be included in the dataset. |
required |
Raises:
Type | Description |
---|---|
Exception
|
If no modules are provided or if the number of rows in the modules do not match. |
Source code in vambn/data/datasets.py
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 |
|
__len__()
¶
Get the number of samples in the dataset.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of samples. |
Source code in vambn/data/datasets.py
491 492 493 494 495 496 497 498 |
|
__str__()
¶
String representation of the VambnDataset object.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string representation of the VambnDataset. |
Source code in vambn/data/datasets.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
get_iter_dataset(name)
¶
Get a PyTorch compatible dataset for a given module name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Module name. |
required |
Returns:
Type | Description |
---|---|
IterDataset | LongitudinalDataset
|
IterDataset | LongitudinalDataset: Either an IterDataset or a LongitudinalDataset depending on the number of visits. |
Source code in vambn/data/datasets.py
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 |
|
get_longitudinal_data(selection)
¶
Get longitudinal data for a specific module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection |
str
|
Module name. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: Data and mask tensors. |
Source code in vambn/data/datasets.py
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 |
|
get_module(name)
¶
Get the ModuleDataset for a given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the module with visit number. |
required |
Returns:
Name | Type | Description |
---|---|---|
ModuleDataset |
ModuleDataset
|
ModuleDataset object with the given name. |
Raises:
Type | Description |
---|---|
Exception
|
If the module is not found or multiple modules with the same name are found. |
Source code in vambn/data/datasets.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
|
get_module_data(selection)
¶
Get the ModuleDataset for a given name without considering visit number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection |
str
|
Name of the module. |
required |
Returns:
Type | Description |
---|---|
List[ModuleDataset]
|
List[ModuleDataset]: List of all ModuleDataset objects with the given name sorted by visit number. |
Source code in vambn/data/datasets.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
|
get_modules(name)
¶
Get the modules with the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the module. |
required |
Returns:
Type | Description |
---|---|
List[ModuleDataset]
|
List[ModuleDataset]: ModuleDataset objects with the given name sorted by visit number. |
Source code in vambn/data/datasets.py
463 464 465 466 467 468 469 470 471 472 473 474 475 |
|
select_modules(selection=None, visits=None)
¶
Select certain modules and visits from the existing dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection |
Optional[List[str]]
|
Module names. Defaults to None. |
None
|
visits |
Optional[List[int]]
|
Visit numbers. Defaults to None. |
None
|
Source code in vambn/data/datasets.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
|
subset(ratio)
¶
Subset the dataset by a given ratio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ratio |
float
|
Ratio of the subset to be returned. |
required |
Returns:
Name | Type | Description |
---|---|---|
VambnDataset |
VambnDataset
|
Subset of the dataset. |
Source code in vambn/data/datasets.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 |
|
subset_by_idx(selected_idx)
¶
Subset the dataset by a given list of indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_idx |
List[int]
|
Indices of the samples to be selected. |
required |
Returns:
Name | Type | Description |
---|---|---|
VambnDataset |
VambnDataset
|
Subset of the dataset. |
Source code in vambn/data/datasets.py
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
|
to(device)
¶
Move the dataset to a specific device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
device
|
Device to be used. |
required |
Returns:
Name | Type | Description |
---|---|---|
VambnDataset |
VambnDataset
|
Dataset on the specified device. |
Source code in vambn/data/datasets.py
449 450 451 452 453 454 455 456 457 458 459 460 461 |
|
to_pandas(module_name=None)
¶
Convert the data and mask to pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name |
Optional[str]
|
Name of the module to convert. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Data and mask as pandas DataFrame. |
Source code in vambn/data/datasets.py
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 |
|
train_test_split(test_ratio)
¶
Generate a train and test split of the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_ratio |
float
|
Ratio of the dataset to be used as the test set. |
required |
Returns:
Type | Description |
---|---|
Tuple[VambnDataset, VambnDataset]
|
Tuple[VambnDataset, VambnDataset]: Train and test split. |
Source code in vambn/data/datasets.py
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
|
helpers
¶
filter_data(data, missingness_threshold, selected_columns, variance_threshold=0.1)
¶
Filter data by removing columns with zero variance and too many missing values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Input data. |
required |
missingness_threshold |
float
|
Threshold for missingness. |
required |
selected_columns |
List[str] | None
|
Columns to keep. |
required |
variance_threshold |
float
|
Minimum variance. Defaults to 0.1. |
0.1
|
Returns:
Type | Description |
---|---|
Tuple[DataFrame, Set[str]]
|
Tuple[pd.DataFrame, Set[str]]: Dataframe with filtered columns and set of selected columns. |
Source code in vambn/data/helpers.py
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 |
|
load_vambn_data(data_folder, selected_visits=None, selected_modules=None)
¶
Load the data from the preprocessed folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_folder |
Path
|
Folder containing the preprocessed data. |
required |
selected_visits |
Optional[List[int]]
|
List of visits to select. Defaults to None. |
None
|
selected_modules |
Optional[List[str]]
|
List of modules to select. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the data folder or any required data file is not found. |
Returns:
Name | Type | Description |
---|---|---|
VambnDataset |
VambnDataset
|
Dataset with the loaded data. |
Source code in vambn/data/helpers.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
prepare_data(data, grouping, output_path, missingness_threshold, max_visit_dict, selected_modules, module_wise_features, selected_visits=None, scaling=True, variance_threshold=0.1)
¶
Prepare data for VAMBN and save it in the respective output folder.
The function performs the following steps
- Iterate over the modules and timepoints/visits.
- Filter out columns with zero variance and too many missing values.
- Keep track of missing values and create a mask (1 = missing, 0 = not missing).
- Impute missing data for standalone variables.
- Save imputed and raw data, as well as types and missing mask for each module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Input data. |
required |
grouping |
DataFrame
|
DataFrame containing grouping information. |
required |
output_path |
Path
|
Path to save the processed data. |
required |
missingness_threshold |
float
|
Threshold for missingness. |
required |
max_visit_dict |
Dict[str, int]
|
Dictionary with maximum visit number for each module. |
required |
selected_modules |
List[str] | None
|
List of modules to select. |
required |
module_wise_features |
Dict[str, Optional[Set[str]]] | None
|
Features for each module. |
required |
selected_visits |
List[int] | None
|
List of visits to select. Defaults to None. |
None
|
scaling |
bool
|
Whether to apply scaling. Defaults to True. |
True
|
variance_threshold |
float
|
Minimum variance threshold. Defaults to 0.1. |
0.1
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Prepared data. |
Source code in vambn/data/helpers.py
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 |
|
make_data
¶
extract_module_characteristics(name)
¶
Extract the module name and visit from a given file name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
File name. |
required |
Returns:
Type | Description |
---|---|
Tuple[str, str]
|
Tuple[str, str]: Module name and visit. |
Raises:
Type | Description |
---|---|
ValueError
|
If the module name or visit cannot be extracted from the file name. |
Source code in vambn/data/make_data.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
make(data_file, grouping_file, groups_file, config_json, output_path, missingness_threshold=50, variance_threshold=0.1, log_file=None, scaling=True)
¶
Process and prepare data for VAMBN analysis.
The function performs the following steps
- Set up logging.
- Load configuration settings.
- Ensure output directories exist.
- Read and preprocess input data.
- Filter data based on missingness and variance thresholds.
- Prepare data for VAMBN analysis and save it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_file |
Path
|
Path to the data file. |
required |
grouping_file |
Path
|
Path to the grouping file. |
required |
groups_file |
Path
|
Path to the file containing module groups. |
required |
config_json |
Path
|
Path to the configuration JSON file. |
required |
output_path |
Path
|
Path to save the processed data. |
required |
missingness_threshold |
int
|
Threshold for missingness. Defaults to 50. |
50
|
variance_threshold |
float
|
Minimum variance threshold. Defaults to 0.1. |
0.1
|
log_file |
Optional[Path]
|
Path to the log file. Defaults to None. |
None
|
scaling |
bool
|
Whether to apply scaling. Defaults to True. |
True
|
Source code in vambn/data/make_data.py
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 |
|
merge_csv_files(folder, files, suffix)
¶
Read preprocessed CSV files and merge them by a given column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder |
Path
|
Folder where the files are located. |
required |
files |
List[Path]
|
Paths to the files. |
required |
suffix |
str
|
Suffix of the files to merge (e.g., '_imp.csv'). |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If no files are provided or if the number of processed files does not match the number of provided files. |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Merged dataframe. |
Source code in vambn/data/make_data.py
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 |
|
merge_imputed_data(input_folder, merged_data, transformed_data_path, log_file=None, log_level=20)
¶
Merge imputed data into a single CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_folder |
Path
|
Folder where the files are located. |
required |
merged_data |
Path
|
File where the merged data should be stored. |
required |
transformed_data_path |
Path
|
Path to save the transformed data. |
required |
log_file |
Optional[Path]
|
Optional file for logging. Defaults to None. |
None
|
log_level |
int
|
Logging level. Defaults to 20. |
20
|
Source code in vambn/data/make_data.py
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 |
|
merge_raw_data(input_folder, output_file, log_file=None, log_level=20)
¶
Merge raw data into a single CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_folder |
Path
|
Folder where the files are located. |
required |
output_file |
Path
|
File where the merged data should be stored. |
required |
log_file |
Optional[Path]
|
Optional file for logging. Defaults to None. |
None
|
log_level |
int
|
Logging level. Defaults to 20. |
20
|
Source code in vambn/data/make_data.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
merge_stalone_data(input_folder, output_file, log_file=None, log_level=20)
¶
Merge imputed data into a single CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_folder |
Path
|
Folder where the files are located. |
required |
output_file |
Path
|
File where the merged data should be stored. |
required |
log_file |
Optional[Path]
|
Optional file for logging. Defaults to None. |
None
|
log_level |
int
|
Logging level. Defaults to 20. |
20
|
Source code in vambn/data/make_data.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
modular(decoded_folder, input_file, output_data)
¶
Gather data from decoded files and merge them with the stalone data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decoded_folder |
Path
|
Path to the folder containing the decoded files. |
required |
input_file |
Path
|
Path to the stalone data. |
required |
output_data |
Path
|
Path to the output file. |
required |
Source code in vambn/data/make_data.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
read_and_merge(files)
¶
Read all files and merge them on the columns SUBJID and VISIT.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
files |
List[Path]
|
List of files to read. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Merged dataframe. |
Source code in vambn/data/make_data.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
traditional(decoded_folders, input_file, output_data)
¶
Gather data from decoded files and merge them with the stalone data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decoded_folders |
List[Path]
|
List of folders containing the decoded files. |
required |
input_file |
Path
|
Path to the stalone data. |
required |
output_data |
Path
|
Path to the output file. |
required |
Source code in vambn/data/make_data.py
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 |
|
scalers
¶
LogStdScaler
¶
Bases: BaseEstimator
, TransformerMixin
A custom scaler that applies a log transformation followed by standard scaling.
This class is deprecated and will be removed soon.
Attributes:
Name | Type | Description |
---|---|---|
scaler |
StandardScaler
|
The standard scaler used after the log transformation. |
Source code in vambn/data/scalers.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
__init__()
¶
Initializes the LogStdScaler.
Source code in vambn/data/scalers.py
17 18 19 20 21 22 23 24 25 |
|
__str__()
¶
Returns a string representation of the LogStdScaler.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation. |
Source code in vambn/data/scalers.py
78 79 80 81 82 83 84 85 |
|
fit(X, y=None)
¶
Fits the scaler to the data after applying a log transformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
array - like
|
The data to fit. |
required |
y |
None
|
Ignored. |
None
|
Returns:
Name | Type | Description |
---|---|---|
LogStdScaler |
The fitted scaler. |
Source code in vambn/data/scalers.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
inverse_transform(X, y=None)
¶
Inversely transforms the data using the fitted scaler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
array - like
|
The data to inverse transform. |
required |
y |
None
|
Ignored. |
None
|
Returns:
Type | Description |
---|---|
array-like: The inversely transformed data. |
Source code in vambn/data/scalers.py
64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
transform(X, y=None)
¶
Transforms the data using the fitted scaler after applying a log transformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
array - like
|
The data to transform. |
required |
y |
None
|
Ignored. |
None
|
Returns:
Type | Description |
---|---|
array-like: The transformed data. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the scaler has not been fitted yet. |
Source code in vambn/data/scalers.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|