Base Module
BaseAutoencoder
Bases: ABC, Module
Interface for building autoencoder models.
Defines standard methods for encoding data to a latent space and decoding back to the original space. Includes a weight initialization method for stable training. Intended to be extended by specific autoencoder variants like VAE.
Attributes:
| Name | Type | Description |
|---|---|---|
input_dim |
Number of input features. |
|
config |
Configuration object containing model architecture parameters. |
|
_encoder |
Optional[Module]
|
Encoder network. |
_decoder |
Optional[Module]
|
Decoder network. |
ontologies |
Ontology information, if provided for Ontix |
|
feature_order |
For Ontix |
Source code in src/autoencodix/base/_base_autoencoder.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
__init__(config, input_dim, ontologies=None, feature_order=None)
Initializes the BaseAutoencoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[DefaultConfig]
|
Configuration object containing model parameters. If None, a default configuration will be used. |
required |
input_dim
|
Union[int, Tuple[int, ...]]
|
Number of input features. |
required |
ontologies
|
Optional[Union[Tuple, Dict]]
|
Ontology information, if provided for Ontix |
None
|
feature_order
|
Optional[Union[Tuple, Dict]]
|
For Ontix |
None
|
Source code in src/autoencodix/base/_base_autoencoder.py
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 | |
decode(x)
abstractmethod
Decodes the latent representation back to the input space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The latent tensor to be decoded. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The decoded tensor, reconstructed from the latent space. |
Source code in src/autoencodix/base/_base_autoencoder.py
100 101 102 103 104 105 106 107 108 109 110 | |
encode(x)
abstractmethod
Encodes the input into the latent space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The input tensor to be encoded. |
required |
Returns:
| Type | Description |
|---|---|
Union[Tensor, Tuple[Tensor, Tensor]]
|
The encoded latent space representation, or mu and logvar for VAEs. |
Source code in src/autoencodix/base/_base_autoencoder.py
70 71 72 73 74 75 76 77 78 79 80 81 82 | |
forward(x)
abstractmethod
Combines encoding and decoding steps for the autoencoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The input tensor to be processed. |
required |
Returns:
| Type | Description |
|---|---|
ModelOutput
|
The reconstructed input tensor and any additional information, |
ModelOutput
|
depending on the model type. |
Source code in src/autoencodix/base/_base_autoencoder.py
112 113 114 115 116 117 118 119 120 121 122 123 | |
get_latent_space(x)
abstractmethod
Returns the latent space representation of the input.
Method for unification of getting a latent space between Variational and Vanilla Autoencoders. This method is a wrapper around the encode method, or the reparameterization method for VAE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The input tensor to be encoded. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The latent space representation of the input tensor. |
Source code in src/autoencodix/base/_base_autoencoder.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
BaseDataset
Bases: ABC, Dataset
Interface to guide implementation for custom PyTorch datasets.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
The dataset content (can be a torch.Tensor or other data structure). |
|
config |
Optional configuration object. |
|
sample_ids |
Optional list of identifiers for each sample. |
|
feature_ids |
Optional list of identifiers for each feature. |
|
mytype |
Enum
|
Enum indicating the dataset type (should be set in subclasses). |
Source code in src/autoencodix/base/_base_dataset.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
__init__(data, config=None, sample_ids=None, feature_ids=None)
Initializes the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[Tensor, List[ImgData], spmatrix]
|
The data to be used by the dataset. |
required |
config
|
Optional[Any]
|
Optional configuration parameters. |
None
|
sample_ids
|
Optional[List[Any]]
|
Optional identifiers for each sample. |
None
|
feature_ids
|
Optional[List[Any]]
|
Optional identifiers for each feature. |
None
|
mytype
|
Enum indicating the dataset type (should be set in subclasses). |
required |
Source code in src/autoencodix/base/_base_dataset.py
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 | |
__len__()
Returns the number of samples in the dataset.
Returns:
| Type | Description |
|---|---|
int
|
The number of samples in the dataset. |
Source code in src/autoencodix/base/_base_dataset.py
55 56 57 58 59 60 61 62 63 64 | |
get_input_dim()
Gets the input dimension of the dataset (n_features)
Returns:
| Type | Description |
|---|---|
Union[int, Tuple[int, ...]]
|
The input dimension of the dataset's feature space. |
Source code in src/autoencodix/base/_base_dataset.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
BaseEvaluator
Bases: ABC
Source code in src/autoencodix/base/_base_evaluator.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
evaluate(*args)
abstractmethod
Evaluate the Autoencodix pipeline on defined machine learning tasks.
Subclasses must implement this method to perform evaluation using the provided arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list for evaluation parameters. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
The evaluation result. |
Source code in src/autoencodix/base/_base_evaluator.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
BaseLoss
Bases: Module, ABC
Provides common loss computation functionality for autoencoders.
Implements standard loss calculations including reconstruction loss, KL divergence, and Maximum Mean Discrepancy (MMD), while requiring subclasses to implement the specific forward method.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Configuration parameters for the loss function. |
|
recon_loss |
Module
|
Module for computing reconstruction loss (MSE or BCE). |
reduction_fn |
Function to apply reduction (mean or sum). |
|
compute_kernel |
Function to compute kernel for MMD loss. |
|
annealing_scheduler |
Helper for loss calculation with annealing. |
Source code in src/autoencodix/base/_base_loss.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
__init__(config, annealing_scheduler=None)
Initializes the loss module with the specified configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DefaultConfig
|
Configuration parameters for the loss function. |
required |
annealing_scheduler
|
Helper class for loss calculation with annealing. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If unsupported loss reduction or reconstruction loss type is specified. |
Source code in src/autoencodix/base/_base_loss.py
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 | |
compute_kl_loss(mu, logvar)
Computes KL divergence loss between N(mu, logvar) and N(0, 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
Tensor
|
Mean tensor. |
required |
logvar
|
Tensor
|
Log variance tensor. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The KL divergence loss value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If mu and logvar do not have the same shape. |
Source code in src/autoencodix/base/_base_loss.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
compute_mmd_loss(z, true_samples)
Computes Maximum Mean Discrepancy loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Samples from the encoded distribution. |
required |
true_samples
|
Tensor
|
Samples from the prior distribution. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The MMD loss value. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If unsupported loss reduction type is specified. |
Source code in src/autoencodix/base/_base_loss.py
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 | |
compute_paired_loss(latentspaces, sample_ids)
Calculates the paired distance loss across all pairs of modalities in a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latentspaces
|
dict[str, Tensor]
|
A dictionary mapping modality names to their latent space tensors. e.g., {'RNA': tensor_rna, 'ATAC': tensor_atac} |
required |
sample_ids
|
dict[str, list]
|
A dictionary mapping modality names to their list of sample IDs. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
A single scalar tensor representing the total paired loss. |
Source code in src/autoencodix/base/_base_loss.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 | |
compute_variational_loss(mu, logvar, z=None, true_samples=None)
Computes either KL or MMD loss based on configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
Optional[Tensor]
|
Mean tensor for variational loss. |
required |
logvar
|
Optional[Tensor]
|
Log variance tensor for variational loss. |
required |
z
|
Optional[Tensor]
|
Encoded samples for MMD loss. |
None
|
true_samples
|
Optional[Tensor]
|
Prior samples for MMD loss. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
The computed variational loss. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required parameters are missing or if mu and logvar have shape mismatch. |
NotImplementedError
|
If unsupported VAE loss type is specified. |
Source code in src/autoencodix/base/_base_loss.py
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 | |
forward(*args, **kwargs)
abstractmethod
Calculates the loss for the autoencoder.
This method must be implemented by subclasses to define the specific loss computation logic for the autoencoder. The implementation should compute the total loss as well as any individual loss components (e.g., reconstruction loss, KL divergence, etc.) based on the model's output and the provided targets.
Returns:
| Type | Description |
|---|---|
Any
|
|
Any
|
|
Any
|
|
Note
Subclasses must implement this method to define the specific loss computation logic for their use case.
Source code in src/autoencodix/base/_base_loss.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
BasePipeline
Bases: ABC
Provides a standardized interface for building model pipelines.
Implements methods for preprocessing data, training models, making predictions, evaluating performance, and visualizing results. Subclasses customize behavior by providing specific implementations for processing, training, evaluation, and visualization. For example when using the Stackix Model, we would use the StackixPreprocessor Type for preprocessing.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Configuration for the pipeline's components and behavior. |
|
preprocessed_data |
Optional[DatasetContainer]
|
Pre-split and processed data that can be provided by user. |
raw_user_data |
Union[DataPackage, AnnData, MuData, DataFrame, dict]
|
Raw input data for processing (DataFrames, MuData, etc.). |
result |
Storage container for all pipeline outputs. |
|
_preprocessor |
Component that filters, scales, and cleans data. |
|
_visualizer |
Component that generates visual representations of results. |
|
_dataset_type |
Base class for dataset implementations. |
|
_trainer_type |
Base class for trainer implementations. |
|
_model_type |
Base class for model architecture implementations. |
|
_loss_type |
Base class for loss function implementations. |
|
_datasets |
Optional[DatasetContainer]
|
Split datasets after preprocessing. |
_evaluator |
Optional[DatasetContainer]
|
Component that assesses model performance. Not implemented yet |
_data_splitter |
Component that divides data into train/validation/test sets. |
|
_ontologies |
Tuple of dictionaries containing the ontologies to be used to construct sparse decoder layers. If a list is provided, it is assumed to be a list of file paths to ontology files. First item in list or tuple will be treated as first layer (after latent space) and so on. |
Source code in src/autoencodix/base/_base_pipeline.py
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 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 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 | |
__init__(dataset_type, trainer_type, model_type, loss_type, datasplitter_type, preprocessor_type, data, visualizer=None, evaluator=None, result=None, config=None, custom_split=None, ontologies=None, masking_fn=None, masking_fn_kwargs={}, **kwargs)
Initializes the pipeline with components and configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_type
|
Type[BaseDataset]
|
Class for dataset implementations. |
required |
trainer_type
|
Type[BaseTrainer]
|
Class for model training implementations. |
required |
model_type
|
Type[BaseAutoencoder]
|
Class for model architecture implementations. |
required |
loss_type
|
Type[BaseLoss]
|
Class for loss function implementations. |
required |
datasplitter_type
|
Type[DataSplitter]
|
Class for data splitting implementation. |
required |
preprocessor_type
|
Type[BasePreprocessor]
|
Class for data preprocessing implementation. |
required |
visualizer
|
Optional[BaseVisualizer]
|
Component for generating visualizations. |
None
|
data
|
Optional[Union[DataPackage, DatasetContainer, AnnData, MuData, DataFrame, dict]]
|
Input data to be processed or already processed data. |
required |
evaluator
|
Optional[BaseEvaluator]
|
Component for assessing model performance. |
None
|
result
|
Optional[Result]
|
Storage container for pipeline outputs. |
None
|
config
|
Optional[DefaultConfig]
|
Configuration parameters for all pipeline components. |
None
|
custom_split
|
Optional[Dict[str, ndarray]]
|
User-provided data splits (train/validation/test). |
None
|
**kwargs
|
dict
|
Additional keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If inputs have incorrect types. |
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
decode(latent)
Transforms latent space representations back to input space.
Handles various input formats for the latent representation and returns the decoded data in a matching format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent
|
Union[Tensor, AnnData, DataFrame]
|
Latent space representation to decode. |
required |
Returns:
| Type | Description |
|---|---|
Union[Tensor, AnnData, DataFrame]
|
Decoded data in a format matching the input. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If no model has been trained or input type is invalid. |
ValueError
|
If latent dimensions are incompatible with the model. |
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
evaluate(ml_model_class=linear_model.LogisticRegression(), ml_model_regression=linear_model.LinearRegression(), params=[], metric_class='roc_auc_ovo', metric_regression='r2', reference_methods=[], split_type='use-split', n_downsample=10000)
TODO
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
fit(config=None, **kwargs)
Trains the model on preprocessed data.
Creates and configures a trainer instance, then executes the training process using the preprocessed datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[Union[None, DefaultConfig]]
|
Optional custom configuration for training. |
None
|
**kwargs
|
Additional configuration parameters as keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If datasets aren't available for training. |
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
generate(n_samples=None, latent_prior=None, split='test', epoch=-1)
Generates new samples from the model's latent space.
This method allows for the generation of new data samples by sampling from the model's latent space. Users can either provide a custom latent prior or specify the number of samples to generate. If a custom latent prior is provided, its batch dimension must be compatible with n_samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
Optional[int]
|
The number of samples to generate. |
None
|
latent_prior
|
Optional[Union[ndarray, Tensor]]
|
Optional custom latent prior distribution. If provided, this will be used for sampling instead of the learned distribution. The prior must either be a single latent vector or a batch of latent vectors matching n_samples. |
None
|
split
|
str
|
The split to sample from (train, valid, test), default is test. |
'test'
|
epoch
|
int
|
The epoch to sample from, default is the last epoch (-1). |
-1
|
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: The generated samples in the input space. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If n_samples is not a positive integer or if the latent prior has incompatible dimensions. |
TypeError
|
If latent_prior is not a numpy array or tensor. |
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
load(file_path)
classmethod
Loads a pipeline from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path to the saved pipeline. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The loaded pipeline instance. |
Source code in src/autoencodix/base/_base_pipeline.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 | |
predict(data=None, config=None, from_key=None, to_key=None, **kwargs)
Generates predictions using the trained model.
Uses the trained model to make predictions on test data or new data provided by the user. Processes the results and stores them in the result container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Optional[Union[DataPackage, DatasetContainer, AnnData, MuData]]
|
Optional new data for predictions. |
None
|
config
|
Optional[Union[None, DefaultConfig]]
|
Optional custom configuration for prediction. |
None
|
**kwargs
|
Additional configuration parameters as keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If required components aren't initialized. |
ValueError
|
If no test data is available or data format is invalid. |
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
preprocess(config=None, **kwargs)
Filters, normalizes and prepares data for model training.
Processes raw input data into the format required by the model and creates train/validation/test splits as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[Union[None, DefaultConfig]]
|
Optional custom configuration for preprocessing. |
None
|
**kwargs
|
Additional configuration parameters as keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If preprocessor is not initialized. |
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
run(data=None)
Executes the complete pipeline from preprocessing to visualization.
Runs all pipeline steps in sequence and returns the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Optional[Union[DatasetContainer, DataPackage]]
|
Optional data for prediction (overrides test data). |
None
|
Returns:
| Type | Description |
|---|---|
Result
|
Complete pipeline results. |
Source code in src/autoencodix/base/_base_pipeline.py
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
sample_latent_space(n_samples, split='test', epoch=-1)
Samples latent space points from the learned distribution.
If n_samples is not provided, this method returns one latent point per
sample in the specified split (legacy behavior). If n_samples is given,
it draws samples from the aggregated posterior distribution of the split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
split
|
str
|
The split to sample from (train, valid, test), default is test. |
'test'
|
epoch
|
int
|
The epoch to sample from, default is the last epoch (-1). |
-1
|
n_samples
|
int
|
Optional number of latent points to sample. If None, returns one latent point per available sample in the split. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
z |
Tensor
|
torch.Tensor - The sampled latent space points. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the model has not been trained or latent statistics have not been computed. |
TypeError
|
If mu or logvar are not numpy arrays. |
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
save(file_path, save_all=False)
Saves the pipeline to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path where the pipeline should be saved. |
required |
Source code in src/autoencodix/base/_base_pipeline.py
1036 1037 1038 1039 1040 1041 1042 1043 | |
show_result(split='all', **kwargs)
Displays key visualizations of model results.
This method generates the following visualizations: 1. Loss Curves: Displays the absolute loss curves to provide insights into the model's training and validation performance over epochs. 2. Latent Space Ridgeline Plot: Visualizes the distribution of the latent space representations across different dimensions, offering a high-level overview of the learned embeddings. 3. Latent Space 2D Scatter Plot: Projects the latent space into two dimensions for a detailed view of the clustering or separation of data points.
These visualizations help in understanding the model's performance and the structure of the latent space representations.
Source code in src/autoencodix/base/_base_pipeline.py
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 | |
visualize(config=None, **kwargs)
Creates visualizations of model results and performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[Union[None, DefaultConfig]]
|
Optional custom configuration for visualization. |
None
|
**kwargs
|
Additional configuration parameters. |
{}
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If visualizer is not initialized. |
Source code in src/autoencodix/base/_base_pipeline.py
960 961 962 963 964 965 966 967 968 969 970 971 972 973 | |
BasePreprocessor
Bases: ABC
Contains logic for data preprocessing in the Autoencodix framework.
This class defines the general preprocessing workflow and provides
methods for handling different data modalities and data cases.
Subclasses should implement the preprocess method to perform
specific preprocessing steps.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
A DefaultConfig object containing preprocessing configurations. |
|
processed_data |
A dictionary to store processed DataPackage objects for each data split. |
|
bulk_genes_to_keep |
Optional[Dict[str, List[str]]]
|
Optional list of genes to keep for bulk data. |
bulk_scalers |
Optional[Dict[str, Any]]
|
Optional dictionary of scalers for bulk data. |
sc_genes_to_keep |
Optional[Dict[str, List[str]]]
|
Optional dictionary mapping modality keys to lists of genes to keep for single-cell data. |
sc_scalers |
Optional[Dict[str, Dict[str, Any]]]
|
Optional dictionary mapping modality keys to scalers for single-cell data. |
sc_general_genes_to_keep |
Optional[Dict[str, List]]
|
Optional dictionary mapping modality keys to lists of genes to keep filtered by non-SC specific methods. |
data_readers |
Dict[Enum, Any]
|
A dictionary mapping DataCase enum values to data reader instances for different modalities. |
_dataset_container |
Optional[DatasetContainer]
|
Optional DatasetContainer to hold the processed datasets. |
Source code in src/autoencodix/base/_base_preprocessor.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 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 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 | |
__init__(config, ontologies=None)
Initializes the BasePreprocessor with a configuration object.
Args
config: A DefaultConfig object containing preprocessing configurations. ontologies: Ontology information, if provided for Ontix.
Source code in src/autoencodix/base/_base_preprocessor.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
preprocess(raw_user_data=None, predict_new_data=False)
abstractmethod
To be implemented by subclasses for specific preprocessing steps. Args: raw_user_data: Users can provide raw data. This is an alternative way of providing data via filepaths in the config. If this param is passed, we skip the data reading step. predict_new_data: Indicates whether the user wants to predict with unseen data. If this is the case, we don't split the data and only prerpocess.
Source code in src/autoencodix/base/_base_preprocessor.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
BaseTrainer
Bases: ABC
General training logic for all autoencoder models.
This class sets up the model, optimizer, and data loaders. It also handles reproducibility and model-specific configurations. Subclasses must implement model training and prediction logic.
Attributes:
| Name | Type | Description |
|---|---|---|
_trainset |
The dataset used for training. |
|
_validset |
The dataset used for validation, if provided. |
|
_result |
An object to store and manage training results. |
|
_config |
Configuration object containing training hyperparameters and settings. |
|
_model_type |
The autoencoder model class to be trained. |
|
_loss_fn |
Instantiated loss function specific to the model. |
|
_trainloader |
DataLoader for the training dataset. |
|
_validloader |
DataLoader for the validation dataset, if provided. |
|
_model |
The instantiated model architecture. |
|
_optimizer |
The optimizer used for training. |
|
_fabric |
Lightning Fabric wrapper for device and precision management. |
|
ontologies |
Ontology information, if provided for Ontix |
Source code in src/autoencodix/base/_base_trainer.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 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 | |
purge()
abstractmethod
Cleans up any resources used during training, such as cached data or large attributes.
Source code in src/autoencodix/base/_base_trainer.py
245 246 247 248 | |
BaseVisualizer
Bases: ABC
Defines the interface for visualizing training results.
Attributes:
| Name | Type | Description |
|---|---|---|
plots |
A nested dictionary to store various plots. |
Source code in src/autoencodix/base/_base_visualizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
save_plots(path, which='all', format='png')
Save specified plots to the given path in the specified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The directory path where the plots will be saved. |
required |
which
|
Union[str, list]
|
A list of plot names to save or a string specifying which plots to save. If 'all', all plots in the plots dictionary will be saved. If a single plot name is provided as a string, only that plot will be saved. |
'all'
|
format
|
str
|
The file format in which to save the plots (e.g., 'png', 'jpg'). |
'png'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the 'which' parameter is not a list or a string. |
Source code in src/autoencodix/base/_base_visualizer.py
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 | |
show_evaluation(param, metric, ml_alg=None)
Displays the evaluation plot for a specific clinical parameter, metric, and optionally ML algorithm. Args: param: clinical parameter to visualize. metric: metric to visualize. ml_alg: ML algorithm to visualize. If None, plots all available algorithms. Returns: None
Source code in src/autoencodix/base/_base_visualizer.py
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 | |
show_loss(plot_type='absolute')
Display the loss plot. Args: plot_type: Type of loss plot to display. Options are "absolute" or "relative". Options are "absolute" for the absolute loss plot and "relative" for the relative loss plot. Defaults to "absolute". Returns: None
Source code in src/autoencodix/base/_base_visualizer.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |