HIVAE¶
config
¶
HivaeConfig
dataclass
¶
Bases: ModelConfig
Configuration class for HIVAE models.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Name of the configuration. Typically the module name. |
variable_types |
VarTypes
|
Definition of the variable types. See VarTypes. |
dim_s |
int
|
Dimension of the latent space S. |
dim_y |
int
|
Dimension of the Y space. |
dim_z |
int
|
Dimension of the latent space Z. |
mtl_methods |
Tuple[str, ...]
|
Methods for multi-task learning. Tested possibilities are combinations of "identity", "gradnorm", "graddrop". Further implementations and details can be found in the mtl.py file. |
use_imputation_layer |
bool
|
Flag to use imputation layer. |
dropout |
float
|
Dropout rate. |
n_layers |
Optional[int]
|
Number of layers. Needed for longitudinal data. |
num_timepoints |
int
|
Number of timepoints for longitudinal data. Default is 1. |
Source code in vambn/modelling/models/hivae/config.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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
input_dim
cached
property
¶
Gets the input dimension based on variable types.
Returns:
Name | Type | Description |
---|---|---|
int |
The input dimension. |
is_longitudinal: bool
cached
property
¶
Checks if the data is longitudinal.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the data has more than one timepoint, False otherwise. |
__post_init__()
¶
Converts mtl_methods to a tuple if it is a list.
Source code in vambn/modelling/models/hivae/config.py
84 85 86 87 |
|
ModularHivaeConfig
dataclass
¶
Bases: ModelConfig
Configuration class for Modular HIVAE models.
Attributes:
Name | Type | Description |
---|---|---|
module_config |
Tuple[DataModuleConfig]
|
Configuration for the data modules. See DataModuleConfig. |
dim_s |
int | Tuple[int, ...] | Dict[str, int]
|
Dimension of the latent space S. |
dim_z |
int
|
Dimension of the latent space Z. |
dim_ys |
int
|
Dimension of the YS space. |
dim_y |
int | Tuple[int, ...] | Dict[str, int]
|
Dimension of the Y space. |
mtl_method |
Tuple[str, ...]
|
Methods for multi-task learning. Tested possibilities are combinations of "identity", "gradnorm", "graddrop". Further implementations and details can be found in the mtl.py file. |
use_imputation_layer |
bool
|
Flag to use imputation layer. |
dropout |
float
|
Dropout rate. |
n_layers |
int
|
Number of layers. |
shared_element |
str
|
Shared element type. Possible values are "none", "sharedLinear", "concatMtl", "concatIndiv", "avgMtl", "maxMtl", "encoder", "encoderMtl". Default is "none". |
Source code in vambn/modelling/models/hivae/config.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 |
|
__post_init__()
¶
Validates and sets up the configuration after initialization.
Raises:
Type | Description |
---|---|
Exception
|
If the number of layers is less than 1. |
Source code in vambn/modelling/models/hivae/config.py
40 41 42 43 44 45 46 47 48 49 50 |
|
decoder
¶
Decoder
¶
Bases: Module
HIVAE Decoder class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_types |
VarTypes
|
List of VariableType objects. See VarTypes in data/dataclasses.py. |
required |
s_dim |
int
|
Dimension of s space. |
required |
z_dim |
int
|
Dimension of z space. |
required |
y_dim |
int
|
Dimension of y space. |
required |
mtl_method |
Tuple[str, ...]
|
List of methods to use for multi-task learning. Assessed possibilities are combinations of "identity", "gradnorm", "graddrop". Further implementations and details can be found in the mtl.py file. Defaults to ("identity",). |
('identity')
|
decoder_shared |
Module
|
Shared decoder module. Defaults to nn.Identity(). |
Identity()
|
Attributes:
Name | Type | Description |
---|---|---|
prior_s_val |
Parameter
|
Prior distribution for s values. |
prior_loc_z |
ModifiedLinear
|
Linear layer for z prior distribution. |
s_dim |
int
|
Dimension of s space. |
z_dim |
int
|
Dimension of z space. |
y_dim |
int
|
Dimension of y space. |
variable_types |
VarTypes
|
List of variable types. |
decoder_shared |
Module
|
Shared decoder module. |
internal_layer_norm |
Module
|
Layer normalization module. |
heads |
ModuleList
|
List of head modules for each variable type. |
mtl_methods |
Tuple[str, ...]
|
Methods for multi-task learning. |
_mtl_module_y |
Module
|
Multi-task learning module for y. |
_mtl_module_s |
Module
|
Multi-task learning module for s. |
moo_block |
MultiMOOForLoop
|
Multi-task learning block. |
_decoding |
bool
|
Decoding flag. |
Source code in vambn/modelling/models/hivae/decoder.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 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 |
|
colnames: List[str]
cached
property
¶
Gets the column names of the data.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of column names. |
decoding: bool
property
writable
¶
bool: Flag indicating whether the model is in decoding mode.
prior_s: torch.distributions.OneHotCategorical
property
¶
Gets the prior distribution for s.
Returns:
Type | Description |
---|---|
OneHotCategorical
|
torch.distributions.OneHotCategorical: Prior distribution for s. |
__init__(variable_types, s_dim, z_dim, y_dim, mtl_method=('identity'), decoder_shared=nn.Identity())
¶
Initialize the HIVAE Decoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_types |
List[VariableType]
|
List of VariableType objects. |
required |
s_dim |
int
|
Dimension of s space. |
required |
z_dim |
int
|
Dimension of z space. |
required |
y_dim |
int
|
Dimension of y space. |
required |
mtl_method |
Tuple[str]
|
List of methods to use for multi-task learning. |
('identity')
|
Source code in vambn/modelling/models/hivae/decoder.py
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 |
|
decode(encoding_z, encoding_s, normalization_params)
¶
Decoding logic for the decoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding_z |
Tensor
|
Encoding for z. |
required |
encoding_s |
Tensor
|
Encoding for s. |
required |
normalization_params |
NormalizationParameters
|
Parameters for normalization. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Decoded samples. |
Raises:
Type | Description |
---|---|
ValueError
|
If no samples were drawn. |
Source code in vambn/modelling/models/hivae/decoder.py
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 |
|
forward(data, mask, encoder_output, normalization_parameters)
¶
Forward pass of the decoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data. |
required |
mask |
Tensor
|
Mask for the data. |
required |
encoder_output |
EncoderOutput
|
Output from the encoder. |
required |
normalization_parameters |
NormalizationParameters
|
Parameters for normalization. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
Output from the decoder. |
Source code in vambn/modelling/models/hivae/decoder.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
kl_s(encoder_output)
¶
Computes the KL divergence for s.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoder_output |
EncoderOutput
|
Encoder output. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: KL divergence for s. |
Source code in vambn/modelling/models/hivae/decoder.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
kl_z(mean_qz, std_qz, mean_pz, std_pz)
¶
Computes the KL divergence for z.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mean_qz |
Tensor
|
Mean of the posterior distribution. |
required |
std_qz |
Tensor
|
Standard deviation of the posterior distribution. |
required |
mean_pz |
Tensor
|
Mean of the prior distribution. |
required |
std_pz |
Tensor
|
Standard deviation of the prior distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: KL divergence for z. |
Source code in vambn/modelling/models/hivae/decoder.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
prior_z(loc)
¶
Gets the prior distribution for z.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loc |
Tensor
|
Location parameter for z. |
required |
Returns:
Type | Description |
---|---|
Normal
|
torch.distributions.Normal: Prior distribution for z. |
Source code in vambn/modelling/models/hivae/decoder.py
155 156 157 158 159 160 161 162 163 164 |
|
LstmDecoder
¶
Bases: Decoder
LSTM-based HIVAE Decoder class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_types |
VarTypes
|
List of VariableType objects. See VarTypes in data/dataclasses.py. |
required |
s_dim |
int
|
Dimension of s space. |
required |
z_dim |
int
|
Dimension of z space. |
required |
y_dim |
int
|
Dimension of y space. |
required |
num_timepoints |
int
|
Number of timepoints. |
required |
n_layers |
int
|
Number of LSTM layers. Defaults to 1. |
1
|
mtl_method |
Tuple[str, ...]
|
List of methods to use for multi-task learning.
Assessed possibilities are combinations of "identity", "gradnorm", "graddrop". |
('identity')
|
decoder_shared |
Module
|
Shared decoder module. Defaults to nn.Identity(). |
Identity()
|
Attributes:
Name | Type | Description |
---|---|---|
num_timepoints |
int
|
Number of timepoints. |
n_layers |
int
|
Number of LSTM layers. |
lstm_decoder |
LSTM
|
LSTM decoder module. |
fc |
Linear
|
Fully connected layer. |
Source code in vambn/modelling/models/hivae/decoder.py
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 |
|
__init__(variable_types, s_dim, z_dim, y_dim, num_timepoints, n_layers=1, mtl_method=('identity'), decoder_shared=nn.Identity())
¶
HIVAE Decoder
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_array |
ndarray
|
Array containing the data type information (type, class, ndim) |
required |
s_dim |
int
|
Dimension of s space |
required |
z_dim |
int
|
Dimension of z space |
required |
y_dim |
int
|
Dimension of y space |
required |
num_timepoints |
int
|
Number of num_timepoints. |
required |
mtl_method |
Tuple[str]
|
List of methods to use for multi-task learning. Defaults to ["gradnorm", "pcgrad"]. |
('identity')
|
Source code in vambn/modelling/models/hivae/decoder.py
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 |
|
decode(encoding_z, encoding_s, normalization_params)
¶
Decoding logic for 3D data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding_z |
Tensor
|
Encoding for z. |
required |
encoding_s |
Tensor
|
Encoding for s. |
required |
normalization_params |
NormalizationParameters
|
Parameters for normalization. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor: Decoded samples. |
Source code in vambn/modelling/models/hivae/decoder.py
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 |
|
forward(data, mask, encoder_output, normalization_parameters)
¶
Forward pass of the LSTM decoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data. |
required |
mask |
Tensor
|
Mask for the data. |
required |
encoder_output |
EncoderOutput
|
Output from the encoder. |
required |
normalization_parameters |
NormalizationParameters
|
Parameters for normalization. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
Output from the decoder. |
Source code in vambn/modelling/models/hivae/decoder.py
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 |
|
encoder
¶
Encoder
¶
Bases: Module
HIVAE Encoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
int
|
Dimension of input data (e.g., columns in dataframe). |
required |
dim_s |
int
|
Dimension of s space. |
required |
dim_z |
int
|
Dimension of z space. |
required |
Attributes:
Name | Type | Description |
---|---|---|
input_dim |
int
|
Dimension of input data. |
dim_s |
int
|
Dimension of s space. |
dim_z |
int
|
Dimension of z space. |
encoder_s |
ModifiedLinear
|
Linear layer for s encoding. |
encoder_z |
Module
|
Identity layer for z encoding. |
param_z |
ModifiedLinear
|
Linear layer for z parameterization. |
_tau |
float
|
Temperature parameter for Gumbel softmax. |
_decoding |
bool
|
Flag indicating whether the model is in decoding mode. |
Source code in vambn/modelling/models/hivae/encoder.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 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 |
|
decoding: bool
property
writable
¶
bool: Flag indicating whether the model is in decoding mode.
tau: float
property
writable
¶
float: Temperature parameter for Gumbel softmax.
__init__(input_dim, dim_s, dim_z)
¶
HIVAE Encoder
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
int
|
Dimension of input data (e.g. columns in dataframe) |
required |
dim_s |
int
|
Dimension of s space |
required |
dim_z |
int
|
Dimension of z space |
required |
Source code in vambn/modelling/models/hivae/encoder.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 |
|
forward(x)
¶
Forward pass of the encoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
Normalized input data. |
required |
Raises:
Type | Description |
---|---|
Exception
|
If samples contain NaN values. |
Returns:
Name | Type | Description |
---|---|---|
EncoderOutput |
EncoderOutput
|
Contains samples, logits, and parameters. |
Source code in vambn/modelling/models/hivae/encoder.py
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 |
|
q_s(probs)
¶
Creates a Gumbel distribution for s.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
probs |
Tensor
|
Probabilities for the Gumbel distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
GumbelDistribution |
GumbelDistribution
|
Gumbel distribution. |
Source code in vambn/modelling/models/hivae/encoder.py
117 118 119 120 121 122 123 124 125 126 |
|
q_z(loc, scale)
staticmethod
¶
Creates a normal distribution for z.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loc |
Tensor
|
Mean of the distribution. |
required |
scale |
Tensor
|
Standard deviation of the distribution. |
required |
Returns:
Type | Description |
---|---|
Normal
|
dists.Normal: Normal distribution. |
Source code in vambn/modelling/models/hivae/encoder.py
104 105 106 107 108 109 110 111 112 113 114 115 |
|
LstmEncoder
¶
Bases: Module
Encoder for longitudinal input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dimension |
int
|
Dimension of input data. |
required |
dim_s |
int
|
Dimension of s space. |
required |
dim_z |
int
|
Dimension of z space. |
required |
n_layers |
int
|
Number of LSTM layers. |
required |
hidden_size |
Optional[int]
|
Size of the hidden layer. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
dim_s |
int
|
Dimension of s space. |
dim_z |
int
|
Dimension of z space. |
hidden_size |
int
|
Size of the hidden layer. |
lstm |
LSTM
|
LSTM layer. |
encoder |
Encoder
|
Encoder module. |
Source code in vambn/modelling/models/hivae/encoder.py
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 |
|
forward(input_data)
¶
Forward pass of the LSTM encoder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data |
Tensor
|
Time points/visits x batch size x variables/input size. |
required |
Returns:
Name | Type | Description |
---|---|---|
EncoderOutput |
EncoderOutput
|
Output for each time point. |
Source code in vambn/modelling/models/hivae/encoder.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
q_s(probs)
¶
Creates a Gumbel distribution for s.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
probs |
Tensor
|
Probabilities for the Gumbel distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
GumbelDistribution |
GumbelDistribution
|
Gumbel distribution. |
Source code in vambn/modelling/models/hivae/encoder.py
249 250 251 252 253 254 255 256 257 258 |
|
q_z(loc, scale)
¶
Creates a normal distribution for z.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loc |
Tensor
|
Mean of the distribution. |
required |
scale |
Tensor
|
Standard deviation of the distribution. |
required |
Returns:
Type | Description |
---|---|
Normal
|
dists.Normal: Normal distribution. |
Source code in vambn/modelling/models/hivae/encoder.py
237 238 239 240 241 242 243 244 245 246 247 |
|
gan_hivae
¶
GanHivae
¶
Bases: AbstractGanModel[Tensor, Tensor, HivaeOutput, HivaeEncoding]
GAN-enhanced HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_types |
VarTypes
|
Types of variables. |
required |
input_dim |
int
|
Dimension of input data. |
required |
dim_s |
int
|
Dimension of s space. |
required |
dim_z |
int
|
Dimension of z space. |
required |
dim_y |
int
|
Dimension of y space. |
required |
n_layers |
int
|
Number of layers. |
required |
noise_size |
int
|
Size of the noise vector. Defaults to 10. |
10
|
num_timepoints |
Optional[int]
|
Number of time points. Defaults to None. |
None
|
module_name |
Optional[str]
|
Name of the module. Defaults to "GanHivae". |
'GanHivae'
|
mtl_method |
Tuple[str, ...]
|
Methods for multi-task learning. Defaults to ("identity",). |
('identity')
|
use_imputation_layer |
bool
|
Whether to use an imputation layer. Defaults to False. |
False
|
individual_model |
bool
|
Whether to use individual models. Defaults to True. |
True
|
Attributes:
Name | Type | Description |
---|---|---|
noise_size |
int
|
Size of the noise vector. |
is_longitudinal |
bool
|
Flag for longitudinal data. |
model |
Hivae or LstmHivae
|
HIVAE model. |
generator |
Generator
|
GAN generator. |
discriminator |
Discriminator
|
GAN discriminator. |
device |
device
|
Device to run the model on. |
one |
Parameter
|
Parameter for GAN training. |
mone |
Parameter
|
Parameter for GAN training. |
Source code in vambn/modelling/models/hivae/gan_hivae.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 |
|
colnames: Tuple[str]
cached
property
¶
Gets the column names of the data.
Returns:
Type | Description |
---|---|
Tuple[str]
|
Tuple[str]: Column names. |
decoding: bool
property
writable
¶
bool: Flag indicating whether the model is in decoding mode.
normalization_parameters: NormalizationParameters
property
writable
¶
NormalizationParameters: Parameters for normalization.
tau: float
property
writable
¶
float: Temperature parameter for Gumbel softmax.
decode(encoding)
¶
Decodes the given encoding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding |
HivaeEncoding
|
Encoding to decode. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Decoded data. |
Source code in vambn/modelling/models/hivae/gan_hivae.py
333 334 335 336 337 338 339 340 341 342 |
|
decoder_part(data, mask, encoder_output)
¶
Performs the decoder part of the forward pass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data. |
required |
mask |
Tensor
|
Data mask. |
required |
encoder_output |
EncoderOutput
|
Output from the encoder. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
Model output. |
Source code in vambn/modelling/models/hivae/gan_hivae.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
encoder_part(data, mask)
¶
Performs the encoder part of the forward pass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data. |
required |
mask |
Tensor
|
Data mask. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor, EncoderOutput]
|
Tuple[torch.Tensor, torch.Tensor, EncoderOutput]: Encoder output and modified inputs. |
Source code in vambn/modelling/models/hivae/gan_hivae.py
319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
forward(data, mask)
¶
Forward pass of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data. |
required |
mask |
Tensor
|
Data mask. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
Model output. |
Source code in vambn/modelling/models/hivae/gan_hivae.py
287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
GanModularHivae
¶
Bases: AbstractGanModularModel[Tuple[Tensor, ...], Tuple[Tensor, ...], ModularHivaeOutput, ModularHivaeEncoding]
GAN-enhanced Modular HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_config |
Tuple[DataModuleConfig]
|
Configuration for the data modules. |
required |
dim_s |
int | Dict[str, int]
|
Dimension of s space. |
required |
dim_z |
int
|
Dimension of z space. |
required |
dim_ys |
int
|
Dimension of YS space. |
required |
dim_y |
int | Dict[str, int]
|
Dimension of y space. |
required |
noise_size |
int
|
Size of the noise vector. Defaults to 10. |
10
|
shared_element_type |
str
|
Type of shared element. Defaults to "none". |
'none'
|
mtl_method |
Tuple[str, ...]
|
Methods for multi-task learning. Defaults to ("identity",). |
('identity')
|
use_imputation_layer |
bool
|
Whether to use an imputation layer. Defaults to False. |
False
|
Attributes:
Name | Type | Description |
---|---|---|
module_configs |
Tuple[DataModuleConfig]
|
Configuration for the data modules. |
mtl_method |
Tuple[str, ...]
|
Methods for multi-task learning. |
use_imputation_layer |
bool
|
Whether to use an imputation layer. |
dim_s |
int | Dict[str, int]
|
Dimension of s space. |
dim_z |
int
|
Dimension of z space. |
dim_ys |
int
|
Dimension of YS space. |
dim_y |
int | Dict[str, int]
|
Dimension of y space. |
model |
ModularHivae
|
Modular HIVAE model. |
generators |
ModuleList
|
List of GAN generators. |
discriminators |
ModuleList
|
List of GAN discriminators. |
device |
device
|
Device to run the model on. |
one |
Parameter
|
Parameter for GAN training. |
mone |
Parameter
|
Parameter for GAN training. |
noise_size |
int
|
Size of the noise vector. |
Source code in vambn/modelling/models/hivae/gan_hivae.py
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 |
|
colnames: Tuple[str, ...]
cached
property
¶
Gets the column names for a specific module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name |
str
|
Name of the module. |
required |
Returns:
Type | Description |
---|---|
Tuple[str, ...]
|
Tuple[str, ...]: Column names. |
decoding: bool
property
writable
¶
bool: Flag indicating whether the model is in decoding mode.
tau: float
property
writable
¶
float: Temperature parameter for Gumbel softmax.
decode(encoding)
¶
Decodes the given encoding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding |
ModularHivaeEncoding
|
Encoding to decode. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[Tensor, ...]: Decoded data. |
Source code in vambn/modelling/models/hivae/gan_hivae.py
708 709 710 711 712 713 714 715 716 717 |
|
forward(data, mask)
¶
Forward pass of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tuple[Tensor]
|
Input data. |
required |
mask |
Tuple[Tensor]
|
Data mask. |
required |
Returns:
Name | Type | Description |
---|---|---|
ModularHivaeOutput |
ModularHivaeOutput
|
Model output. |
Source code in vambn/modelling/models/hivae/gan_hivae.py
694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
heads
¶
BaseModuleHead
¶
Bases: Generic[ParameterType, DistributionType]
, Module
, ABC
Base class for different data types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
Dataclass containing the type information. |
required |
dim_s |
int
|
Dimension of s space. |
required |
dim_z |
int
|
Dimension of z space. |
required |
dim_y |
int
|
Dimension of y space. |
required |
Attributes:
Name | Type | Description |
---|---|---|
types |
VariableType
|
Dataclass containing the type information. |
dim_s |
int
|
Dimension of s space. |
dim_z |
int
|
Dimension of z space. |
dim_y |
int
|
Dimension of y space. |
internal_pass |
ModifiedLinear
|
Internal pass module. |
Properties
num_parameters (int): Number of parameters.
Methods:
Name | Description |
---|---|
forward |
Tensor, samples_s: Tensor) -> ParameterType: Forward pass of the module. |
dist |
ParameterType) -> DistributionType: Compute the distribution given the parameters. |
log_prob |
Tensor, params: Optional[ParameterType] = None) -> Tensor: Compute the log probability of the data given the parameters. |
sample |
Sample from the distribution. |
rsample |
Sample using the reparameterization trick. |
mode |
Compute the mode of the distribution. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the distribution is not initialized. |
Source code in vambn/modelling/models/hivae/heads.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 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 |
|
mode: Tensor
property
¶
Compute the mode of the distribution.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The mode of the distribution. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the distribution is not initialized. |
num_parameters: int
property
¶
Number of parameters.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of parameters. |
__init__(variable_type, dim_s, dim_z, dim_y)
¶
Base class for the different datatypes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
types |
VariableType
|
Array containing the data type information (type, class, ndim) |
required |
dim_s |
int
|
Dimension of s space |
required |
dim_z |
int
|
Dimension of z space |
required |
dim_y |
int
|
Dimension of y space |
required |
Source code in vambn/modelling/models/hivae/heads.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
dist(params)
abstractmethod
¶
Compute the distribution given the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ParameterType
|
The parameters of the distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
DistributionType |
DistributionType
|
The computed distribution. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the method is not implemented. |
Source code in vambn/modelling/models/hivae/heads.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
forward(samples_z, samples_s)
abstractmethod
¶
Forward pass of the module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples_z |
Tensor
|
Samples from the z space. |
required |
samples_s |
Tensor
|
Samples from the s space. |
required |
Returns:
Name | Type | Description |
---|---|---|
ParameterType |
ParameterType
|
The output of the forward pass. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the method is not implemented. |
Source code in vambn/modelling/models/hivae/heads.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
log_prob(data, params=None)
¶
Compute the log probability of the data given the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
The input data. |
required |
params |
Optional[ParameterType]
|
The parameters of the distribution. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The log probability of the data. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the distribution is not initialized. |
Source code in vambn/modelling/models/hivae/heads.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
rsample()
¶
Sample using the reparameterization trick.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The sampled data. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the distribution is not initialized. |
Source code in vambn/modelling/models/hivae/heads.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
sample()
¶
Sample from the distribution.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The sampled data. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the distribution is not initialized. |
Source code in vambn/modelling/models/hivae/heads.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
CatHead
¶
Bases: BaseModuleHead[CategoricalParameters, ReparameterizedCategorical]
Class representing the categorical head of a model.
Attributes:
Name | Type | Description |
---|---|---|
variable_type |
VariableType
|
Array containing the data type information (type, class, ndim) |
dim_s |
int
|
Dimension of s space |
dim_z |
int
|
Dimension of z space |
dim_y |
int
|
Dimension of y space |
logit_layer |
ModifiedLinear
|
Linear layer for computing logits |
_dist_class |
ReparameterizedCategorical
|
Class for representing reparameterized categorical distribution |
Source code in vambn/modelling/models/hivae/heads.py
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 |
|
__init__(variable_type, dim_s, dim_z, dim_y)
¶
Initialize the CatHead class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
Array containing the data type information (type, class, ndim) |
required |
dim_s |
int
|
Dimension of s space |
required |
dim_z |
int
|
Dimension of z space |
required |
dim_y |
int
|
Dimension of y space |
required |
Source code in vambn/modelling/models/hivae/heads.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
dist(params)
¶
Compute the reparameterized categorical distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
CategoricalParameters
|
Categorical parameters |
required |
Returns:
Name | Type | Description |
---|---|---|
ReparameterizedCategorical |
ReparameterizedCategorical
|
Reparameterized categorical distribution |
Source code in vambn/modelling/models/hivae/heads.py
554 555 556 557 558 559 560 561 562 563 564 |
|
forward(samples_z, samples_s)
¶
Forward pass of the CatHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples_z |
Tensor
|
Samples from the z space |
required |
samples_s |
Tensor
|
Samples from the s space |
required |
Returns:
Name | Type | Description |
---|---|---|
CategoricalParameters |
CategoricalParameters
|
Categorical parameters |
Source code in vambn/modelling/models/hivae/heads.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
|
CountHead
¶
Bases: BaseModuleHead[PoissonParameters, Poisson]
Head module for the Poisson distribution (Count data).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
Array containing the data type information (type, class, ndim) |
required |
dim_s |
int
|
Dimension of s space |
required |
dim_z |
int
|
Dimension of z space |
required |
dim_y |
int
|
Dimension of y space |
required |
Attributes:
Name | Type | Description |
---|---|---|
lambda_layer |
ModifiedLinear
|
Linear layer for computing the rate parameter |
_dist_class |
Poisson
|
Class for representing the Poisson distribution |
Source code in vambn/modelling/models/hivae/heads.py
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 |
|
__init__(variable_type, dim_s, dim_z, dim_y)
¶
Initializes the CountHead class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
Array containing the data type information (type, class, ndim) |
required |
dim_s |
int
|
Dimension of s space |
required |
dim_z |
int
|
Dimension of z space |
required |
dim_y |
int
|
Dimension of y space |
required |
Source code in vambn/modelling/models/hivae/heads.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
|
dist(params)
¶
Creates a Poisson distribution from the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
PoissonParameters
|
The Poisson parameters |
required |
Returns:
Type | Description |
---|---|
Poisson
|
dists.Poisson: The Poisson distribution |
Source code in vambn/modelling/models/hivae/heads.py
492 493 494 495 496 497 498 499 500 501 502 |
|
forward(samples_z, samples_s)
¶
Performs the forward pass of the CountHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples_z |
Tensor
|
Samples from the z space |
required |
samples_s |
Tensor
|
Samples from the s space |
required |
Returns:
Name | Type | Description |
---|---|---|
PoissonParameters |
PoissonParameters
|
The Poisson parameter |
Source code in vambn/modelling/models/hivae/heads.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
|
PosHead
¶
Bases: BaseModuleHead[LogNormalParameters, LogNormal]
Head module for the LogNormal (pos) distribution
Attributes:
Name | Type | Description |
---|---|---|
variable_type |
VariableType
|
The type of variable. |
dim_s |
int
|
The dimension of s. |
dim_z |
int
|
The dimension of z. |
dim_y |
int
|
The dimension of y. |
loc_layer |
ModifiedLinear
|
The linear layer for computing the location parameter. |
scale_layer |
ModifiedLinear
|
The linear layer for computing the scale parameter. |
_dist_class |
LogNormal
|
The class representing the LogNormal distribution. |
_n_pars |
int
|
The number of parameters in the distribution. |
Source code in vambn/modelling/models/hivae/heads.py
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 |
|
__init__(variable_type, dim_s, dim_z, dim_y)
¶
Initializes the PosHead class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
The type of variable. |
required |
dim_s |
int
|
The dimension of s. |
required |
dim_z |
int
|
The dimension of z. |
required |
dim_y |
int
|
The dimension of y. |
required |
Source code in vambn/modelling/models/hivae/heads.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
|
dist(params)
¶
Creates a LogNormal distribution based on the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
LogNormalParameters
|
The parameters of the distribution. |
required |
Returns:
Type | Description |
---|---|
LogNormal
|
dists.LogNormal: The LogNormal distribution. |
Source code in vambn/modelling/models/hivae/heads.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
forward(samples_z, samples_s)
¶
Performs the forward pass of the PosHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples_z |
Tensor
|
The z samples. |
required |
samples_s |
Tensor
|
The s samples. |
required |
Returns:
Name | Type | Description |
---|---|---|
LogNormalParameters |
LogNormalParameters
|
The output of the forward pass. |
Source code in vambn/modelling/models/hivae/heads.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
log_prob(data, params=None)
¶
Computes the log probability of the data given the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
The input data. |
required |
params |
LogNormalParameters | None
|
The parameters of the distribution. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The log probability of the data. |
Source code in vambn/modelling/models/hivae/heads.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
RealHead
¶
Bases: BaseModuleHead[NormalParameters, Normal]
Class representing the RealHead module.
This module is used for data of type real or pos.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
Array containing the data type information (type, class, ndim) |
required |
dim_s |
int
|
Dimension of s space |
required |
dim_z |
int
|
Dimension of z space |
required |
dim_y |
int
|
Dimension of y space |
required |
Attributes:
Name | Type | Description |
---|---|---|
loc_layer |
ModifiedLinear
|
Linear layer for computing the location parameter |
scale_layer |
ModifiedLinear
|
Linear layer for computing the scale parameter |
_dist_class |
type
|
Class representing the distribution |
_n_pars |
int
|
Number of parameters in the distribution |
Source code in vambn/modelling/models/hivae/heads.py
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 |
|
__init__(variable_type, dim_s, dim_z, dim_y)
¶
Initialize the RealHead module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
Array containing the data type information (type, class, ndim) |
required |
dim_s |
int
|
Dimension of s space |
required |
dim_z |
int
|
Dimension of z space |
required |
dim_y |
int
|
Dimension of y space |
required |
Source code in vambn/modelling/models/hivae/heads.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
dist(params)
¶
Create a Normal distribution based on the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
NormalParameters
|
Parameters of the Normal distribution |
required |
Returns:
Type | Description |
---|---|
Normal
|
dists.Normal: Normal distribution |
Source code in vambn/modelling/models/hivae/heads.py
255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
forward(samples_z, samples_s)
¶
Forward pass of the RealHead module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples_z |
Tensor
|
Samples from the z space |
required |
samples_s |
Tensor
|
Samples from the s space |
required |
Returns:
Name | Type | Description |
---|---|---|
NormalParameters |
NormalParameters
|
Parameters of the Normal distribution |
Source code in vambn/modelling/models/hivae/heads.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
TruncatedNormalHead
¶
Bases: BaseModuleHead[NormalParameters, TruncatedNormal]
Class representing the TruncatedNormalHead module.
This module is used for data of type real or pos.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
Array containing the data type information (type, class, ndim) |
required |
dim_s |
int
|
Dimension of s space |
required |
dim_z |
int
|
Dimension of z space |
required |
dim_y |
int
|
Dimension of y space |
required |
Attributes:
Name | Type | Description |
---|---|---|
loc_layer |
ModifiedLinear
|
Linear layer for computing the location parameter |
scale_layer |
ModifiedLinear
|
Linear layer for computing the scale parameter |
_dist_class |
type
|
Class representing the distribution |
_n_pars |
int
|
Number of parameters in the distribution |
Source code in vambn/modelling/models/hivae/heads.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 |
|
__init__(variable_type, dim_s, dim_z, dim_y)
¶
Initializes a TruncatedNormalHead object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_type |
VariableType
|
The type of variable. |
required |
dim_s |
int
|
The dimensionality of s. |
required |
dim_z |
int
|
The dimensionality of z. |
required |
dim_y |
int
|
The dimensionality of y. |
required |
Source code in vambn/modelling/models/hivae/heads.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
dist(params)
¶
Creates a TruncatedNormal distribution based on the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
NormalParameters
|
The parameters of the distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
TruncatedNormal |
TruncatedNormal
|
The created TruncatedNormal distribution. |
Source code in vambn/modelling/models/hivae/heads.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
forward(samples_z, samples_s)
¶
Performs a forward pass through the TruncatedNormalHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
samples_z |
Tensor
|
The z samples. |
required |
samples_s |
Tensor
|
The s samples. |
required |
Returns:
Name | Type | Description |
---|---|---|
NormalParameters |
NormalParameters
|
The output of the forward pass. |
Source code in vambn/modelling/models/hivae/heads.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
log_prob(data, params=None)
¶
Computes the log probability of the data given the parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
The input data. |
required |
params |
NormalParameters | None
|
The parameters of the distribution. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The log probability of the data. |
Source code in vambn/modelling/models/hivae/heads.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
hivae
¶
Hivae
¶
Bases: AbstractNormalModel[Tensor, Tensor, HivaeOutput, HivaeEncoding]
Entire HIVAE model containing Encoder and Decoder structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_types |
VarTypes
|
List of VariableType objects defining the types of the variables in the data. |
required |
input_dim |
int
|
Dimension of input data (number of columns in the dataframe). If the data contains categorical variables, the input dimension is larger than the number of features. |
required |
dim_s |
int
|
Dimension of s space. |
required |
dim_z |
int
|
Dimension of z space. |
required |
dim_y |
int
|
Dimension of y space. |
required |
module_name |
str
|
Name of the module this HIVAE is associated with. Defaults to 'HIVAE'. |
'HIVAE'
|
mtl_method |
Tuple[str]
|
List of methods to use for multi-task learning. Assessed possibilities are combinations of "identity", "gradnorm", "graddrop". Further implementations and details can be found in the mtl.py file. Defaults to ("identity",). |
('identity')
|
use_imputation_layer |
bool
|
Flag to indicate if imputation layer should be used. Defaults to False. |
False
|
individual_model |
bool
|
Flag to indicate if the current model is applied individually or as part of e.g. a modular HIVAE. Defaults to True. |
True
|
Source code in vambn/modelling/models/hivae/hivae.py
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 |
|
colnames: Tuple[str, ...]
cached
property
¶
Tuple of column names derived from variable types.
Returns:
Type | Description |
---|---|
Tuple[str, ...]
|
Tuple[str, ...]: A tuple containing column names. |
decoding: bool
property
writable
¶
Decoding flag indicating if the encoder and decoder are in decoding mode.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Decoding flag. |
normalization_parameters: NormalizationParameters
property
writable
¶
Gets the normalization parameters (mean and standard deviation).
Returns:
Name | Type | Description |
---|---|---|
NormalizationParameters |
NormalizationParameters
|
The normalization parameters. |
tau: float
property
writable
¶
Gets the temperature parameter for the model.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The temperature parameter. |
decode(encoding)
¶
Decode the given encoding to reconstruct the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding |
HivaeEncoding
|
The encoding to decode. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The reconstructed data tensor. |
Source code in vambn/modelling/models/hivae/hivae.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
decoder_part(data, mask, encoder_output)
¶
Pass through the decoder part of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data tensor. |
required |
mask |
Tensor
|
Mask tensor indicating missing values. |
required |
encoder_output |
EncoderOutput
|
Output from the encoder. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
The output of the decoder. |
Source code in vambn/modelling/models/hivae/hivae.py
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 |
|
encoder_part(data, mask)
¶
Pass through the encoder part of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data tensor. |
required |
mask |
Tensor
|
Mask tensor indicating missing values. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor, EncoderOutput]
|
Tuple[torch.Tensor, torch.Tensor, EncoderOutput]: Processed data, mask, and encoder output. |
Raises:
Type | Description |
---|---|
ValueError
|
If data tensor has invalid shape. |
Source code in vambn/modelling/models/hivae/hivae.py
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 |
|
forward(data, mask)
¶
Forward pass through the HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data tensor. |
required |
mask |
Tensor
|
Mask tensor indicating missing values. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
The output of the HIVAE model. |
Source code in vambn/modelling/models/hivae/hivae.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
LstmHivae
¶
Bases: Hivae
LSTM-based HIVAE model with Encoder and Decoder structure for temporal data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variable_types |
VarTypes
|
List of VariableType objects defining the types of the variables in the data. |
required |
input_dim |
int
|
Dimension of input data (number of columns in the dataframe). If the data contains categorical variables, the input dimension is larger than the number of features. |
required |
dim_s |
int
|
Dimension of s space. |
required |
dim_z |
int
|
Dimension of z space. |
required |
dim_y |
int
|
Dimension of y space. |
required |
n_layers |
int
|
Number of layers in the LSTM. |
required |
num_timepoints |
int
|
Number of time points in the temporal data. |
required |
module_name |
str
|
Name of the module this HIVAE is associated with. Defaults to 'HIVAE'. |
'HIVAE'
|
mtl_method |
Tuple[str]
|
List of methods to use for multi-task learning. Assessed possibilities are combinations of "identity", "gradnorm", "graddrop". Further implementations and details can be found in the mtl.py file. Defaults to ("identity",). |
('identity')
|
use_imputation_layer |
bool
|
Flag to indicate if imputation layer should be used. Defaults to False. |
False
|
individual_model |
bool
|
Flag to indicate if the current model is applied individually or as part of e.g. a modular HIVAE. Defaults to True. |
True
|
Source code in vambn/modelling/models/hivae/hivae.py
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 |
|
decode(encoding)
¶
Decode the given encoding to reconstruct the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding |
HivaeEncoding
|
The encoding to decode. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The reconstructed data tensor. |
Source code in vambn/modelling/models/hivae/hivae.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
decoder_part(data, mask, encoder_output)
¶
Pass through the decoder part of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data tensor. |
required |
mask |
Tensor
|
Mask tensor indicating missing values. |
required |
encoder_output |
EncoderOutput
|
Output from the encoder. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
The output of the decoder. |
Source code in vambn/modelling/models/hivae/hivae.py
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 |
|
encoder_part(data, mask)
¶
Pass through the encoder part of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data tensor. |
required |
mask |
Tensor
|
Mask tensor indicating missing values. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor, EncoderOutput]
|
Tuple[torch.Tensor, torch.Tensor, EncoderOutput]: Processed data, mask, and encoder output. |
Source code in vambn/modelling/models/hivae/hivae.py
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 |
|
forward(data, mask)
¶
Forward pass through the LSTM HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tensor
|
Input data tensor. |
required |
mask |
Tensor
|
Mask tensor indicating missing values. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
The output of the LSTM HIVAE model. |
Source code in vambn/modelling/models/hivae/hivae.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
|
modular
¶
ModularHivae
¶
Bases: AbstractModularModel[Tuple[Tensor, ...], Tuple[Tensor, ...], ModularHivaeOutput, ModularHivaeEncoding]
Modular HIVAE model containing multiple data modules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_config |
Tuple[DataModuleConfig]
|
Configuration for each data module. See DataModuleConfig for details. |
required |
dim_s |
int | Dict[str, int]
|
Number of mixture components for each module individually (dict) or a single value for all modules (int). |
required |
dim_z |
int
|
Dimension of the latent space. Equal for all modules. |
required |
dim_ys |
int
|
Dimension of the latent space ys. Equal for all modules. |
required |
dim_y |
int | Dict[str, int]
|
Dimension of the latent variable y for each module or a single value for all modules. |
required |
shared_element_type |
str
|
Type of shared element. Possible values are "none", "sharedLinear", "concatMtl", "concatIndiv", "avgMtl", "maxMtl", "encoder", "encoderMtl". Defaults to "none". |
'none'
|
mtl_method |
Tuple[str, ...]
|
Methods for multi-task learning. Tested possibilities are combinations of "identity", "gradnorm", "graddrop". Further implementations and details can be found in the mtl.py file. Defaults to ("identity",). |
('identity')
|
use_imputation_layer |
bool
|
Flag to indicate if imputation layer should be used. Defaults to False. |
False
|
Source code in vambn/modelling/models/hivae/modular.py
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 |
|
decoding: bool
property
writable
¶
Decoding flag indicating if the encoder and decoder are in decoding mode.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Decoding flag. |
tau
property
writable
¶
Get the temperature parameter for the model.
Returns:
Name | Type | Description |
---|---|---|
float |
The temperature parameter. |
__init__(module_config, dim_s, dim_z, dim_ys, dim_y, shared_element_type='none', mtl_method=('identity'), use_imputation_layer=False)
¶
Initialize the modular HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_config |
Tuple[DataModuleConfig]
|
Configuration for each data module. |
required |
dim_s |
int | Dict[str, int]
|
Number of the mixture components for each module or a single value for all modules. |
required |
dim_z |
int
|
Dimension of the latent space. Equal for all modules. |
required |
dim_ys |
int
|
Dimension of the latent space ys. Equal for all modules. |
required |
dim_y |
int | Dict[str, int]
|
Dimension of the latent variable y for each module or a single value for all modules. |
required |
shared_element_type |
str
|
Type of shared element. Defaults to "none". |
'none'
|
mtl_method |
Tuple[str, ...]
|
Methods for MTL. Defaults to ("identity",). |
('identity')
|
use_imputation_layer |
bool
|
Flag to indicate if imputation layer should be used. Defaults to False. |
False
|
Source code in vambn/modelling/models/hivae/modular.py
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 |
|
colnames(module_name)
¶
Get column names for a specific module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name |
str
|
Name of the module. |
required |
Returns:
Type | Description |
---|---|
Tuple[str, ...]
|
Tuple[str, ...]: Column names for the specified module. |
Source code in vambn/modelling/models/hivae/modular.py
168 169 170 171 172 173 174 175 176 177 178 |
|
decode(encoding)
¶
Decode the given encoding to reconstruct the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding |
ModularHivaeEncoding
|
The encoding to decode. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[Tensor, ...]: The reconstructed data tensors for each module. |
Source code in vambn/modelling/models/hivae/modular.py
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 |
|
forward(data, mask)
¶
Forward pass through the modular HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Tuple[Tensor, ...]
|
Input data tensors for each module. |
required |
mask |
Tuple[Tensor, ...]
|
Mask tensors indicating missing values for each module. |
required |
Returns:
Name | Type | Description |
---|---|---|
ModularHivaeOutput |
ModularHivaeOutput
|
The output of the modular HIVAE model. |
Source code in vambn/modelling/models/hivae/modular.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 |
|
is_longitudinal(module_name)
¶
Check if a specific module is longitudinal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name |
str
|
Name of the module. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the module is longitudinal, False otherwise. |
Source code in vambn/modelling/models/hivae/modular.py
181 182 183 184 185 186 187 188 189 190 191 |
|
normalization
¶
Normalization
¶
Class for normalization utilities, including broadcasting masks and normalizing/denormalizing data.
Source code in vambn/modelling/models/hivae/normalization.py
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 |
|
denormalize_params(params, variable_types, normalization_params)
staticmethod
¶
Denormalize parameters based on variable types and normalization parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
etas |
Tuple[Etas, ...]
|
The parameters to denormalize. |
required |
variable_types |
VarTypes
|
The variable types information. |
required |
normalization_params |
NormalizationParameters
|
The normalization parameters. |
required |
Returns:
Type | Description |
---|---|
Tuple[Parameters, ...]
|
Tuple[Parameters, ...]: The denormalized parameters. |
Source code in vambn/modelling/models/hivae/normalization.py
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 |
|
normalize_data(x, mask, variable_types, prior_parameters, eps=1e-06)
staticmethod
¶
Normalize the input data based on variable types and prior parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
The input data tensor. |
required |
mask |
Tensor
|
The mask tensor indicating missing values. |
required |
variable_types |
VarTypes
|
The variable types information. |
required |
prior_parameters |
NormalizationParameters
|
The prior normalization parameters. |
required |
eps |
float
|
A small value to prevent division by zero. Defaults to 1e-6. |
1e-06
|
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor, NormalizationParameters]
|
Tuple[torch.Tensor, torch.Tensor, NormalizationParameters]: The normalized data, updated mask, and new normalization parameters. |
Source code in vambn/modelling/models/hivae/normalization.py
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 |
|
NormalizationParameters
dataclass
¶
Data class for normalization parameters, including mean and standard deviation.
This class is only used for the parameters of real and pos typed variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mean |
Tensor
|
The mean values for normalization. |
required |
std |
Tensor
|
The standard deviation values for normalization. |
required |
Source code in vambn/modelling/models/hivae/normalization.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 |
|
__add__(other)
¶
Add two NormalizationParameters instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
NormalizationParameters
|
Another instance to add. |
required |
Returns:
Name | Type | Description |
---|---|---|
NormalizationParameters |
NormalizationParameters
|
A new instance with combined parameters. |
Source code in vambn/modelling/models/hivae/normalization.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
__getitem__(idx)
¶
Get normalization parameters by index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
The index to retrieve parameters for. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor] | NormalizationParameters
|
Tuple[torch.Tensor, torch.Tensor] | NormalizationParameters: The mean and std tensors or a new NormalizationParameters instance. |
Source code in vambn/modelling/models/hivae/normalization.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
__setitem__(idx, value)
¶
Set normalization parameters by index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
The index to set parameters for. |
required |
value |
Tuple[Tensor, Tensor]
|
The mean and std tensors to set. |
required |
Source code in vambn/modelling/models/hivae/normalization.py
67 68 69 70 71 72 73 74 75 76 77 |
|
from_tensors(mean, std)
classmethod
¶
Create NormalizationParameters from mean and std tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mean |
Tensor
|
The mean tensor. |
required |
std |
Tensor
|
The standard deviation tensor. |
required |
Returns:
Name | Type | Description |
---|---|---|
NormalizationParameters |
NormalizationParameters
|
An instance of NormalizationParameters. |
Source code in vambn/modelling/models/hivae/normalization.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
outputs
¶
DecoderOutput
dataclass
¶
Dataclass to hold the output from the decoder.
Attributes:
Name | Type | Description |
---|---|---|
log_p_x |
Tensor
|
Log-likelihood of the data. |
kl_z |
Tensor
|
KL divergence for the z variable. |
kl_s |
Tensor
|
KL divergence for the s variable. |
corr_loss |
Tensor
|
Correlation loss if applicable. |
recon |
Optional[Tensor]
|
Reconstruction, if any. |
samples |
Optional[Tensor]
|
Samples generated, if any. |
enc_s |
Optional[Tensor]
|
Encoded s values, if any. |
enc_z |
Optional[Tensor]
|
Encoded z values, if any. |
output_name |
Optional[str]
|
Name of the output, if any. |
detached |
bool
|
Whether the tensors have been detached. |
Source code in vambn/modelling/models/hivae/outputs.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 |
|
elbo: Tensor
property
¶
Calculate the negative Evidence Lower Bound (ELBO).
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The negative ELBO. |
loss: Tensor
property
¶
Calculate the loss based on the negative ELBO.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The loss tensor. |
Raises:
Type | Description |
---|---|
Exception
|
If tensors have been detached. |
__post_init__()
¶
Validate dimensions of the log-likelihood tensor.
Raises:
Type | Description |
---|---|
Exception
|
If log-likelihood tensor is not of dimension 1. |
Source code in vambn/modelling/models/hivae/outputs.py
95 96 97 98 99 100 101 102 103 104 105 |
|
__str__()
¶
String representation of the DecoderOutput object.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string describing the DecoderOutput object. |
Source code in vambn/modelling/models/hivae/outputs.py
107 108 109 110 111 112 113 114 115 116 117 118 |
|
detach_and_move()
¶
Detach all tensors and move them to CPU.
Returns:
Name | Type | Description |
---|---|---|
DecoderOutput |
DecoderOutput
|
The detached DecoderOutput object. |
Source code in vambn/modelling/models/hivae/outputs.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
EncoderOutput
dataclass
¶
Dataclass for encoder output.
Attributes:
Name | Type | Description |
---|---|---|
samples_s |
Tensor
|
Samples from the s distribution. |
logits_s |
Tensor
|
Logits for the s distribution. |
mean_z |
Tensor
|
Mean of the z distribution. |
scale_z |
Tensor
|
Scale of the z distribution. |
samples_z |
Optional[Tensor]
|
Samples from the z distribution. |
h_representation |
Optional[Tensor]
|
Hidden representation, if any. |
Source code in vambn/modelling/models/hivae/outputs.py
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 |
|
decoder_representation: Tensor
property
writable
¶
Get the decoder representation.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The hidden representation if available, otherwise the samples from the z distribution. |
HivaeEncoding
dataclass
¶
Dataclass for HIVAE encoding.
Attributes:
Name | Type | Description |
---|---|---|
s |
Tensor
|
Encoding for s. |
z |
Tensor
|
Encoding for z. |
module |
str
|
Module name. |
samples |
Optional[Tensor]
|
Samples generated, if any. |
subjid |
Optional[List[str | int]]
|
Subject IDs. |
h_representation |
Optional[Tensor]
|
Hidden representation, if any. |
Source code in vambn/modelling/models/hivae/outputs.py
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 |
|
decoder_representation: Tensor
property
writable
¶
Get the decoder representation.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The hidden representation if available, otherwise the z encoding. |
__post_init__()
¶
Initialize the encoding and ensure tensors are on CPU and have the correct dtype.
Source code in vambn/modelling/models/hivae/outputs.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
|
convert()
¶
Convert the encoding to a dictionary format.
Returns:
Type | Description |
---|---|
Dict[str, List[str | float]]
|
Dict[str, List[str | float]]: The converted encoding. |
Source code in vambn/modelling/models/hivae/outputs.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|
get_samples(module=None)
¶
Get the samples for the specified module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module |
Optional[str]
|
The module name. If None, return all samples. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The samples tensor. |
Source code in vambn/modelling/models/hivae/outputs.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
save_meta_enc(path)
¶
Save the metadata encoding to a CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The file path to save the metadata. |
required |
Source code in vambn/modelling/models/hivae/outputs.py
493 494 495 496 497 498 499 500 501 502 503 504 |
|
HivaeOutput
dataclass
¶
Dataclass for HIVAE output.
Attributes:
Name | Type | Description |
---|---|---|
loss |
Tensor
|
Loss tensor. |
enc_z |
Tensor
|
Encoded z values. |
enc_s |
Tensor
|
Encoded s values. |
samples |
Optional[Tensor]
|
Samples generated, if any. |
n |
Optional[int]
|
Number of samples. |
single |
bool
|
Whether this is a single output. |
Source code in vambn/modelling/models/hivae/outputs.py
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 |
|
avg_loss: float
property
¶
Calculate the average loss.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The average loss. |
Raises:
Type | Description |
---|---|
ValueError
|
If the loss tensor has an invalid dimension. |
n_loss: int
property
¶
Get the number of loss values.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of loss values. |
__add__(other)
¶
Add another HivaeOutput object to this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
HivaeOutput
|
The other HivaeOutput object to add. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
The resulting HivaeOutput object. |
Source code in vambn/modelling/models/hivae/outputs.py
282 283 284 285 286 287 288 289 290 291 292 293 |
|
__post_init__()
¶
Initialize the number of samples.
Source code in vambn/modelling/models/hivae/outputs.py
210 211 212 213 214 |
|
detach()
¶
Detach all tensors and move them to CPU.
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
The detached HivaeOutput object. |
Source code in vambn/modelling/models/hivae/outputs.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
stack(other)
¶
Stack another HivaeOutput object with this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
HivaeOutput
|
The other HivaeOutput object to stack. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutput |
HivaeOutput
|
The stacked HivaeOutput object. |
Source code in vambn/modelling/models/hivae/outputs.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
LogLikelihoodOutput
dataclass
¶
Dataclass to hold the output from log-likelihood functions.
Attributes:
Name | Type | Description |
---|---|---|
log_p_x |
Tensor
|
Log-likelihood for observed data. |
log_p_x_missing |
Tensor
|
Log-likelihood for missing data. |
samples |
Optional[Tensor]
|
Samples generated, if any. |
Source code in vambn/modelling/models/hivae/outputs.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
LstmHivaeOutput
dataclass
¶
Bases: HivaeOutput
Dataclass for LSTM HIVAE output.
Source code in vambn/modelling/models/hivae/outputs.py
296 297 298 299 300 |
|
ModularHivaeEncoding
dataclass
¶
Dataclass for modular HIVAE encoding.
Attributes:
Name | Type | Description |
---|---|---|
encodings |
Tuple[HivaeEncoding, ...]
|
Tuple of HIVAE encodings. See HivaeEncoding for details. |
modules |
List[str]
|
List of module names in the same order as encodings. |
Source code in vambn/modelling/models/hivae/outputs.py
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 |
|
__getitem__(idx)
¶
Get an encoding by index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
The index of the encoding to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeEncoding |
HivaeEncoding
|
The encoding at the specified index. |
Source code in vambn/modelling/models/hivae/outputs.py
590 591 592 593 594 595 596 597 598 599 600 |
|
__post_init__()
¶
Initialize the modular encoding and ensure tensors are on CPU and have the correct dtype.
Raises:
Type | Description |
---|---|
Exception
|
If modules in encodings do not match modules in ModularHivaeEncoding. |
Source code in vambn/modelling/models/hivae/outputs.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
convert()
¶
Convert the modular encoding to a dictionary format.
Returns:
Type | Description |
---|---|
Dict[str, List[float | str]]
|
Dict[str, List[float | str]]: The converted encoding. |
Source code in vambn/modelling/models/hivae/outputs.py
543 544 545 546 547 548 549 550 551 552 553 554 |
|
get(module)
¶
Get an encoding by module name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module |
str
|
The module name. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeEncoding |
HivaeEncoding
|
The encoding for the specified module. |
Raises:
Type | Description |
---|---|
Exception
|
If the module is not found in encodings. |
Source code in vambn/modelling/models/hivae/outputs.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
|
get_samples(module=None)
¶
Get the samples for the specified module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module |
Optional[str]
|
The module name. If None, return all samples. |
None
|
Returns:
Type | Description |
---|---|
Tensor | Dict[str, Tensor]
|
Tensor | Dict[str, Tensor]: The samples tensor or a dictionary of samples. |
Source code in vambn/modelling/models/hivae/outputs.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
|
save_meta_enc(path)
¶
Save the metadata encoding to a CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The file path to save the metadata. |
required |
Source code in vambn/modelling/models/hivae/outputs.py
556 557 558 559 560 561 562 563 564 565 566 567 |
|
ModularHivaeOutput
dataclass
¶
Dataclass for modular HIVAE output.
Attributes:
Name | Type | Description |
---|---|---|
outputs |
Tuple[HivaeOutputs, ...]
|
Tuple of HIVAE outputs. See HivaeOutputs for details. |
Source code in vambn/modelling/models/hivae/outputs.py
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 |
|
avg_loss: float
property
¶
Calculate the average loss across all outputs.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The average loss. |
loss: Tensor
property
¶
Calculate the total loss across all outputs.
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The total loss tensor. |
__add__(other)
¶
Add another ModularHivaeOutput object to this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
ModularHivaeOutput
|
The other ModularHivaeOutput object to add. |
required |
Returns:
Name | Type | Description |
---|---|---|
ModularHivaeOutput |
ModularHivaeOutput
|
The resulting ModularHivaeOutput object. |
Source code in vambn/modelling/models/hivae/outputs.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
__item__(idx)
¶
Get an output by index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
The index of the output to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
HivaeOutputs |
HivaeOutputs
|
The output at the specified index. |
Source code in vambn/modelling/models/hivae/outputs.py
380 381 382 383 384 385 386 387 388 389 390 |
|
__iter__()
¶
Iterate over the outputs.
Returns:
Name | Type | Description |
---|---|---|
Iterator |
An iterator over the outputs. |
Source code in vambn/modelling/models/hivae/outputs.py
362 363 364 365 366 367 368 369 |
|
__len__()
¶
Get the number of outputs.
Returns:
Name | Type | Description |
---|---|---|
int |
The number of outputs. |
Source code in vambn/modelling/models/hivae/outputs.py
371 372 373 374 375 376 377 378 |
|
detach()
¶
Detach all tensors in the outputs and move them to CPU.
Returns:
Name | Type | Description |
---|---|---|
ModularHivaeOutput |
ModularHivaeOutput
|
The detached ModularHivaeOutput object. |
Source code in vambn/modelling/models/hivae/outputs.py
331 332 333 334 335 336 337 338 339 340 |
|
shared
¶
AvgModuleMtl
¶
Bases: BaseModule
This module averages the z's and passes them through the MOO block. The output is then passed through individual layers to generate the final outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
The dimension of the input z. |
required |
ys_dim |
int
|
The dimension of the shared output ys. |
required |
y_dim |
int | Tuple[int, ...]
|
The dimension of the individual outputs y. |
required |
n_modules |
int
|
The number of modules. |
required |
module_names |
Tuple[str, ...]
|
The names of the modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
The method used for multi-task learning. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
_mtl_module |
MultiObjectiveOptimization
|
The multi-objective optimization module. |
moo_block |
MultiMOOForLoop
|
The multi-objective optimization block. |
scaling_layers |
ModuleList
|
The list of scaling layers. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(z)
¶
Performs the forward pass of the module. The input z's are averaged and passed through the MOO block. The output is then passed through the individual scaling layers to generate the final output tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tuple[Tensor, ...]
|
The input z. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[torch.Tensor, ...]: The output tensors. |
Source code in vambn/modelling/models/hivae/shared.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
order_layers(module_names)
¶
Orders the scaling layers based on the given module names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str]
|
The names of the modules. |
required |
Source code in vambn/modelling/models/hivae/shared.py
469 470 471 472 473 474 475 476 477 478 479 480 |
|
BaseElement
¶
Bases: Module
A base neural network element that consists of a single modified linear layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
int
|
Input dimension of the layer. |
required |
output_dim |
int
|
Output dimension of the layer. |
required |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(x)
¶
Perform the forward pass through the layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
Input tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Output tensor after passing through the layer. |
Source code in vambn/modelling/models/hivae/shared.py
27 28 29 30 31 32 33 34 35 36 37 |
|
BaseModule
¶
Bases: Module
, ABC
Base class for all modules in the HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
Input dimension of the latent samples z. |
required |
ys_dim |
int
|
Intermediate dimension of the latent samples ys. |
required |
y_dim |
int or Tuple[int, ...]
|
Output dimension of the latent samples y, which can be different for each module. |
required |
n_modules |
int
|
Number of modules. |
required |
module_names |
Tuple[str, ...]
|
Names of the modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
MTL methods used to avoid conflicting gradients. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the length of y_dim is not equal to the number of modules. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
__init__(z_dim, ys_dim, y_dim, n_modules, module_names, mtl_method=None)
¶
Base class for all modules in the HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
Input dimension of the latent samples z. |
required |
ys_dim |
int
|
Intermediate dimension of the latent samples ys. |
required |
y_dim |
int | Tuple[int, ...]
|
Output dimension of the latent samples y, which can be different for each module. |
required |
n_modules |
int
|
Number of modules. |
required |
module_names |
Tuple[str, ...]
|
Names of the modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
MTL methods used to avoid conflicting gradients. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the length of y_dim is not equal to the number of modules. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
order_layers(module_names)
abstractmethod
¶
Order the layers of the module according to the module names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str, ...]
|
Names of the modules |
required |
Source code in vambn/modelling/models/hivae/shared.py
97 98 99 100 101 102 103 104 105 |
|
ConcatModule
¶
Bases: BaseModule
A module that concatenates multiple input tensors and applies scaling layers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
The dimension of the input z tensors. |
required |
ys_dim |
int
|
The dimension of the output ys tensors. |
required |
y_dim |
int or Tuple[int, ...]
|
The dimension of the output y tensors. |
required |
n_modules |
int
|
The number of modules. |
required |
module_names |
Tuple[str, ...]
|
The names of the modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
The method used for multi-task learning (default: None). |
None
|
Attributes:
Name | Type | Description |
---|---|---|
shared_layer |
BaseElement
|
The shared layer that concatenates the input z tensors. |
scaling_layers |
ModuleList
|
The list of scaling layers for each module. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(z)
¶
Performs forward pass through the ConcatModule. The input tensors z are concatenated and passed through the shared layer to generate a single output tensor. The output tensor is then passed through the scaling layers to generate the final output tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tuple[Tensor, ...]
|
The input tensors z. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[torch.Tensor, ...]: The output tensors after applying scaling layers. |
Source code in vambn/modelling/models/hivae/shared.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|
order_layers(module_names)
¶
Reorders the scaling layers based on the given module names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str]
|
The new order of the module names. |
required |
Source code in vambn/modelling/models/hivae/shared.py
382 383 384 385 386 387 388 389 390 391 392 393 |
|
ConcatModuleMtl
¶
Bases: BaseModule
This module concatenates the z's and passes them through a shared layer before passing through the MOO block. The output is then passed through individual layers to generate the final outputs. This is the same as the ConcatModule, but with the addition of the MOO block.
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(z)
¶
Forward pass through the module. The z's are concatenated and passed through the shared layer to generate one output which is identical for all modules. The output is then passed through the MOO block and individual layers to generate the final outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tuple[Tensor, ...]
|
Input tensor. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[torch.Tensor, ...]: Output tensor with individual outputs for each module. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
order_layers(module_names)
¶
Order the layers based on the module names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str]
|
Names of the modules. |
required |
Source code in vambn/modelling/models/hivae/shared.py
298 299 300 301 302 303 304 305 306 307 308 |
|
EncoderModule
¶
Bases: BaseModule
EncoderModule class represents a module for encoding input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
The dimension of the latent space. |
required |
ys_dim |
int
|
The dimension of the output space. |
required |
y_dim |
int or Tuple[int, ...]
|
The dimension(s) of the input data. |
required |
n_modules |
int
|
The number of modules. |
required |
module_names |
Tuple[str, ...]
|
The names of the modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
The method(s) for multi-task learning. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
attention |
SelfAttention
|
The self-attention layer. |
feed_forward |
Sequential
|
The feed-forward neural network. |
dropout |
Dropout
|
The dropout layer. |
layer_norm_1 |
LayerNorm
|
The layer normalization layer. |
layer_norm_2 |
LayerNorm
|
The layer normalization layer. |
ys_layer |
Linear
|
The linear layer for output. |
scaling_layers |
ModuleList
|
The list of scaling layers. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(z)
¶
Performs forward pass through the encoder module. The input tensors z are concatenated and passed through the self-attention layer. The output is then passed through the feed-forward neural network and the output layer. The output is then passed through the scaling layers to generate the final output tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tuple[Tensor, ...]
|
The input tensors. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[torch.Tensor, ...]: The output tensors. |
Source code in vambn/modelling/models/hivae/shared.py
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
|
order_layers(module_names)
¶
Orders the scaling layers based on the given module names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str]
|
The names of the modules. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in vambn/modelling/models/hivae/shared.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
EncoderModuleMtl
¶
Bases: BaseModule
Encoder module for multi-task learning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
The dimension of the latent space. |
required |
ys_dim |
int
|
The dimension of the shared representation. |
required |
y_dim |
int | Tuple[int, ...]
|
The dimension(s) of the task-specific representations. |
required |
n_modules |
int
|
The number of task-specific modules. |
required |
module_names |
Tuple[str, ...]
|
The names of the task-specific modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
The multi-task learning method(s) to use. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
attention |
SelfAttention
|
The self-attention layer. |
feed_forward |
Sequential
|
The feed-forward neural network. |
dropout |
Dropout
|
The dropout layer. |
layer_norm_1 |
LayerNorm
|
The first layer normalization. |
layer_norm_2 |
LayerNorm
|
The second layer normalization. |
ys_layer |
Linear
|
The linear layer for shared representation. |
scaling_layers |
ModuleList
|
The list of scaling layers for task-specific representations. |
_mtl_module |
MultiObjectiveOptimization
|
The multi-objective optimization module. |
moo_block |
MultiMOOForLoop
|
The multi-objective optimization block. |
Raises:
Type | Description |
---|---|
Exception
|
This class should no longer be used. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(z)
¶
Forward pass of the module. The input tensors z are concatenated and passed through the self-attention layer. The output is then passed through the feed-forward neural network combined with the residual connection and layer normalization. The output is then passed through the MTL block and the scaling layers to generate the final output tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tuple[Tensor, ...]
|
The input tensors. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[torch.Tensor, ...]: The output tensors. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
order_layers(module_names)
¶
Order the scaling layers based on the given module names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str]
|
The names of the task-specific modules. |
required |
Source code in vambn/modelling/models/hivae/shared.py
804 805 806 807 808 809 810 811 812 813 814 |
|
ImposterModule
¶
Bases: BaseModule
This module is used as a placeholder when no modularity is desired. It simply returns the input z as the output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
Input dimension of the latent samples z. |
required |
ys_dim |
int
|
Intermediate dimension of the latent samples ys. |
required |
y_dim |
int or Tuple[int, ...]
|
Output dimension of the latent samples y, which can be different for each module. |
required |
n_modules |
int
|
Number of modules. |
required |
module_names |
Tuple[str, ...]
|
Names of the modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
MTL methods used to avoid conflicting gradients. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
has_params |
bool
|
Whether the module has parameters. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(z)
¶
Forward pass through the module. Since this module has no parameters, it simply returns the input z.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tuple[Tensor, ...]
|
Input tensor. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[torch.Tensor, ...]: Output tensor. |
Source code in vambn/modelling/models/hivae/shared.py
170 171 172 173 174 175 176 177 178 179 180 181 |
|
order_layers(module_names)
¶
Order the layers based on the module names. Since this module has no parameters, this method does nothing in the case of the ImposterModule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str]
|
Names of the modules. |
required |
Source code in vambn/modelling/models/hivae/shared.py
160 161 162 163 164 165 166 167 168 |
|
MaxModuleMtl
¶
Bases: BaseModule
This module takes the maximum of the z's and passes them through the MOO block. The output is then passed through individual layers to generate the final outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
The dimension of the input z. |
required |
ys_dim |
int
|
The dimension of the ys. |
required |
y_dim |
int | Tuple[int, ...]
|
The dimension of the output y. |
required |
n_modules |
int
|
The number of modules. |
required |
module_names |
Tuple[str, ...]
|
The names of the modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
The method for multi-task learning. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
_mtl_module |
MultiObjectiveOptimization
|
The multi-objective optimization module. |
moo_block |
MultiMOOForLoop
|
The multi-objective optimization block. |
scaling_layers |
ModuleList
|
The list of scaling layers. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(z)
¶
Performs forward pass through the module. The maximum of the z's is passed through the MOO block. The output is then passed through individual scaling layers to generate the final output tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tuple[Tensor, ...]
|
The input z. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[torch.Tensor, ...]: The output tensors. |
Source code in vambn/modelling/models/hivae/shared.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
|
order_layers(module_names)
¶
Orders the scaling layers based on the given module names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str]
|
The names of the modules. |
required |
Source code in vambn/modelling/models/hivae/shared.py
553 554 555 556 557 558 559 560 561 562 563 |
|
SelfAttention
¶
Bases: Module
Self-Attention module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hidden_dim |
int
|
The dimension of the input and output tensors. |
required |
Attributes:
Name | Type | Description |
---|---|---|
query |
Linear
|
Linear layer for computing the query tensor. |
key |
Linear
|
Linear layer for computing the key tensor. |
value |
Linear
|
Linear layer for computing the value tensor. |
softmax |
Softmax
|
Softmax function for computing attention weights. |
Source code in vambn/modelling/models/hivae/shared.py
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 |
|
forward(z)
¶
Forward pass of the SelfAttention module. Computes the query, key, and value tensors and uses them to compute the attention weights. The attention weights are then used to compute the attended values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tensor
|
Input tensor of shape (batch_size, seq_len, hidden_dim). |
required |
Returns:
Type | Description |
---|---|
torch.Tensor: Output tensor of shape (batch_size, seq_len, hidden_dim). |
Source code in vambn/modelling/models/hivae/shared.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
|
SharedLinearModule
¶
Bases: BaseModule
This module passes the z's through a single shared dense layer that generates the individual outputs for each module using the same weights. Outputs are generated one by one. The assumption is that z shares the same dimensional space across modules. This is the simplest form of modularity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_dim |
int
|
Input dimension of the latent samples z. |
required |
ys_dim |
int
|
Intermediate dimension of the latent samples ys. |
required |
y_dim |
int or Tuple[int, ...]
|
Output dimension of the latent samples y, which can be different for each module. |
required |
n_modules |
int
|
Number of modules. |
required |
module_names |
Tuple[str, ...]
|
Names of the modules. |
required |
mtl_method |
Optional[Tuple[str, ...]]
|
MTL methods used to avoid conflicting gradients. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
shared_layer |
BaseElement
|
Shared dense layer. |
scaling_layers |
ModuleList
|
List of individual dense layers for each module. |
Source code in vambn/modelling/models/hivae/shared.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 |
|
forward(z)
¶
Forward pass through the module. The z's are passed through the shared layer to generate one output which is identical for all modules. The output is then passed through individual layers to generate the final outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Tuple[Tensor, ...]
|
Input tensor. |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, ...]
|
Tuple[torch.Tensor, ...]: Output tensor with individual outputs for each module. |
Source code in vambn/modelling/models/hivae/shared.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
order_layers(module_names)
¶
Order the layers based on the module names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_names |
Tuple[str]
|
Names of the modules. |
required |
Source code in vambn/modelling/models/hivae/shared.py
229 230 231 232 233 234 235 236 237 238 239 |
|
trainer
¶
BaseTrainer
¶
Bases: Generic[TConfig, TModel, TPredict, TrainerType, TEncoding]
, ABC
Base class for trainers in the VAMBN2 framework.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
VambnDataset
|
The dataset to use for training. |
required |
config |
PipelineConfig
|
The configuration object for the pipeline. |
required |
workers |
int
|
The number of workers to use for data loading. |
required |
checkpoint_path |
Path
|
The path to save checkpoints during training. |
required |
module_name |
Optional[str]
|
The name of the module. Defaults to None. |
None
|
experiment_name |
Optional[str]
|
The name of the experiment. Defaults to None. |
None
|
force_cpu |
bool
|
Whether to force CPU usage. Defaults to False. |
False
|
Attributes:
Name | Type | Description |
---|---|---|
dataset |
VambnDataset
|
The dataset used for training. |
config |
PipelineConfig
|
The configuration object for the pipeline. |
workers |
int
|
The number of workers used for data loading. |
checkpoint_path |
Path
|
The path to save checkpoints during training. |
model |
Optional[TModel]
|
The model used for training. |
model_config |
Optional[TConfig]
|
The configuration object for the model. |
module_name |
Optional[str]
|
The name of the module. |
experiment_name |
Optional[str]
|
The name of the experiment. |
type |
str
|
The type of the trainer. |
device |
device
|
The device used for training. |
use_mtl |
bool
|
Whether to use multi-task learning. |
use_gan |
bool
|
Whether to use generative adversarial networks. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
run_base: str
cached
property
¶
Generates a base name for the training run. Used e.g. for MLflow run names.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The base name for the Training run. |
cleanup_checkpoints()
¶
Cleans up the checkpoints directory.
This method deletes the entire checkpoints directory specified by self.checkpoint_path
.
Returns:
Type | Description |
---|---|
None |
Source code in vambn/modelling/models/hivae/trainer.py
411 412 413 414 415 416 417 418 419 420 |
|
cv_generator(splits, seed=42)
¶
Generates train and validation datasets for cross-validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splits |
int
|
Number of splits. |
required |
seed |
int
|
Seed for split. Defaults to 42. |
42
|
Raises:
Type | Description |
---|---|
ValueError
|
Number of splits must be greater than 0. |
Yields:
Type | Description |
---|---|
VambnDataset
|
Generator[Tuple[VambnDataset, VambnDataset], None, None]: A generator that yields tuples of train and validation datasets. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
get_dataloader(dataset, batch_size, shuffle)
¶
Get a DataLoader object for the given dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
VambnDataset
|
The dataset to use. |
required |
batch_size |
int
|
The batch size. |
required |
shuffle |
bool
|
Whether to shuffle the data. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataLoader |
DataLoader
|
The DataLoader object. |
Raises:
Type | Description |
---|---|
ValueError
|
If the dataset is empty. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
hyperopt(study, num_trials)
¶
Perform hyperparameter optimization using Optuna.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
study |
Study
|
The Optuna study object. |
required |
num_trials |
int
|
The number of trials to run. |
required |
Returns:
Name | Type | Description |
---|---|---|
Hyperparameters |
Hyperparameters
|
The best hyperparameters found during optimization. |
Raises:
Type | Description |
---|---|
ValueError
|
If no trials are found in the study. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
load_model(path)
¶
Load the model and its configuration from the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to load the model from. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in vambn/modelling/models/hivae/trainer.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
|
multiple_objective_selection(study, corr_weight=0.8)
¶
Selects the best trial from a given Optuna study based on multiple objectives.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
study |
Study
|
The Optuna study object. |
required |
corr_weight |
float
|
The weight for the relative correlation error. Defaults to 0.8. |
0.8
|
Returns:
Type | Description |
---|---|
FrozenTrial
|
optuna.trial.FrozenTrial: The best trial. |
Raises:
Type | Description |
---|---|
ValueError
|
If no trials are found in the study. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
optimize_model(model=None)
¶
Optimizes the model using a specified optimization function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Optional[TModel]
|
The model to optimize. If None, the method optimizes self.model. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
TModel |
TModel
|
The optimized model. |
Notes
- The optimization function is specified by the opt_func variable.
- The opt_func function should take a model as input and return an optimized model.
- If model is None, the method optimizes self.model.
- If model is not None, the method optimizes the specified model.
Raises:
Type | Description |
---|---|
TypeError
|
If the model is not of type TModel. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
read_model_config(path)
abstractmethod
¶
Read the model configuration from the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to read the model configuration from. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in vambn/modelling/models/hivae/trainer.py
551 552 553 554 555 556 557 558 559 560 561 562 |
|
save_model(path)
¶
Save the model and its configuration to the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to save the model. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in vambn/modelling/models/hivae/trainer.py
504 505 506 507 508 509 510 511 512 513 514 515 |
|
save_model_config(path)
abstractmethod
¶
Save the model configuration to the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to save the model configuration. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in vambn/modelling/models/hivae/trainer.py
538 539 540 541 542 543 544 545 546 547 548 549 |
|
Hyperparameters
dataclass
¶
Class representing the hyperparameters for the model trainer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dim_s |
int | Dict[str, int] | Tuple[int, ...]
|
Dimension(s) of the input sequence(s). |
required |
dim_y |
int | Dict[str, int] | Tuple[int, ...]
|
Dimension(s) of the output sequence(s). |
required |
dim_z |
int
|
Dimension of the latent space. |
required |
dropout |
float
|
Dropout rate. |
required |
batch_size |
int
|
Batch size. |
required |
learning_rate |
float | Dict[str, float] | Tuple[float, ...]
|
Learning rate(s). |
required |
epochs |
int
|
Number of training epochs. |
required |
mtl_methods |
Tuple[str, ...]
|
Multi-task learning methods. Defaults to ("identity",). |
('identity')
|
lstm_layers |
int
|
Number of LSTM layers. Defaults to 1. |
1
|
dim_ys |
Optional[int]
|
Dimension of the output sequence. Defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
dim_s |
int | Dict[str, int] | Tuple[int, ...]
|
Dimension(s) of the input sequence(s). |
dim_y |
int | Dict[str, int] | Tuple[int, ...]
|
Dimension(s) of the output sequence(s). |
dim_z |
int
|
Dimension of the latent space. |
dropout |
float
|
Dropout rate. |
batch_size |
int
|
Batch size. |
learning_rate |
float | Dict[str, float] | Tuple[float, ...]
|
Learning rate(s). |
epochs |
int
|
Number of training epochs. |
mtl_methods |
Tuple[str, ...]
|
Multi-task learning methods. |
lstm_layers |
int
|
Number of LSTM layers. |
dim_ys |
Optional[int]
|
Dimension of the output sequence. |
Methods:
Name | Description |
---|---|
__post_init__ |
Post-initialization method. |
write_to_json |
Path): Write the hyperparameters to a JSON file. |
read_from_json |
Path): Read the hyperparameters from a JSON file. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
read_from_json(path)
classmethod
¶
Read the hyperparameters from a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Path to the JSON file. |
required |
Returns:
Name | Type | Description |
---|---|---|
Hyperparameters |
An instance of the Hyperparameters class. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
write_to_json(path)
¶
Write the hyperparameters to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Path to the JSON file. |
required |
Source code in vambn/modelling/models/hivae/trainer.py
144 145 146 147 148 149 150 151 152 153 154 |
|
ModularTrainer
¶
Bases: BaseTrainer[GenericMHivaeConfig, GenericMHivaeModel, ModularHivaeOutput, 'ModularTrainer', ModularHivaeEncoding]
Source code in vambn/modelling/models/hivae/trainer.py
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 |
|
__init__(dataset, config, workers, checkpoint_path, module_name=None, experiment_name=None, force_cpu=False, shared_element='none')
¶
Initialize the ModularTrainer class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
VambnDataset
|
The VambnDataset object. |
required |
config |
PipelineConfig
|
The PipelineConfig object. |
required |
workers |
int
|
The number of workers for data loading. |
required |
checkpoint_path |
Path
|
The path to save checkpoints. |
required |
module_name |
str | None
|
The name of the module. |
None
|
experiment_name |
str | None
|
The name of the experiment. |
None
|
force_cpu |
bool
|
Whether to force CPU usage. |
False
|
shared_element |
str
|
The type of shared element. |
'none'
|
Source code in vambn/modelling/models/hivae/trainer.py
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 |
|
decode(encoding, use_mode=True)
¶
Decode the given encoding to obtain the sampled data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoding |
Union[HivaeEncoding, ModularHivaeEncoding]
|
The encoding to decode. |
required |
use_mode |
bool
|
Whether to use the mode for decoding. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Dict[str, Tensor]
|
Dict[str, Tensor]: The decoded sampled data, with module names as keys. |
Source code in vambn/modelling/models/hivae/trainer.py
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 |
|
get_module_config(hyperparameters)
¶
Get the module configuration based on the hyperparameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hyperparameters |
Hyperparameters
|
The Hyperparameters object. |
required |
Returns:
Type | Description |
---|---|
Tuple[DataModuleConfig, ...]
|
A tuple of DataModuleConfig objects. |
Source code in vambn/modelling/models/hivae/trainer.py
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 |
|
hyperparameters(trial)
¶
Generate hyperparameters for the trial.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trial |
Trial
|
The optuna.Trial object. |
required |
Returns:
Type | Description |
---|---|
Hyperparameters
|
The generated Hyperparameters object. |
Source code in vambn/modelling/models/hivae/trainer.py
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 |
|
init_model(config)
¶
Initialize the ModularHivae model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
ModularHivaeConfig
|
The ModularHivaeConfig object. |
required |
Returns:
Type | Description |
---|---|
ModularHivae
|
The initialized ModularHivae model. |
Source code in vambn/modelling/models/hivae/trainer.py
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 |
|
predict(dl)
¶
Predict the output of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dl |
DataLoader
|
The DataLoader object. |
required |
Returns:
Name | Type | Description |
---|---|---|
ModularHivaeOutput |
ModularHivaeOutput
|
The output of the model. |
Source code in vambn/modelling/models/hivae/trainer.py
1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 |
|
process_encodings(predictions)
¶
Process the model predictions and return the encodings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predictions |
ModularHivaeOutput
|
The model predictions. |
required |
Returns:
Type | Description |
---|---|
ModularHivaeEncoding
|
The ModularHivaeEncoding object. |
Source code in vambn/modelling/models/hivae/trainer.py
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 |
|
read_model_config(path)
¶
Read the model configuration from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to read the model configuration from. |
required |
Source code in vambn/modelling/models/hivae/trainer.py
1857 1858 1859 1860 1861 1862 1863 1864 1865 |
|
save_model_config(path)
¶
Save the model configuration to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to save the model configuration. |
required |
Raises:
Type | Description |
---|---|
Exception
|
If the model is None. |
Exception
|
If the model config is None. |
Source code in vambn/modelling/models/hivae/trainer.py
1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 |
|
TraditionalGanTrainer
¶
Bases: TraditionalTrainer[HivaeConfig, GanHivae]
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
init_model(config)
¶
Initializes the GAN-HIVAE model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
HivaeConfig
|
The configuration for the GAN-HIVAE model. |
required |
Returns:
Name | Type | Description |
---|---|---|
GanHivae |
GanHivae
|
The initialized GAN-HIVAE model. |
Source code in vambn/modelling/models/hivae/trainer.py
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 |
|
TraditionalTrainer
¶
Bases: BaseTrainer[GenericHivaeConfig, GenericHivaeModel, HivaeOutput, 'TraditionalTrainer', HivaeEncoding]
Source code in vambn/modelling/models/hivae/trainer.py
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 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 |
|
hyperparameters(trial)
¶
Function to suggest hyperparameters for the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trial |
Trial
|
Trial instance |
required |
Returns:
Type | Description |
---|---|
Hyperparameters
|
Dict[str, Any]: Suggested hyperparameters |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
read_model_config(path)
¶
Reads the model configuration from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to read the model configuration from. |
required |
Source code in vambn/modelling/models/hivae/trainer.py
1332 1333 1334 1335 1336 1337 1338 1339 1340 |
|
save_model_config(path)
¶
Saves the model configuration to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to save the model configuration. |
required |
Source code in vambn/modelling/models/hivae/trainer.py
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 |
|
train(best_parameters)
¶
Trains the model using the best hyperparameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
best_parameters |
Hyperparameters
|
The best hyperparameters obtained from optimization. |
required |
Returns:
Name | Type | Description |
---|---|---|
GenericHivaeModel |
GenericHivaeModel
|
The trained model. |
Source code in vambn/modelling/models/hivae/trainer.py
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 |
|
timed(fn)
¶
Decorator to time a function for benchmarking purposes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
Callable
|
Function to be timed. |
required |
Returns:
Type | Description |
---|---|
Tuple[Any, float]
|
Tuple[Any, float]: Result of the function and the time taken to execute it. |
Source code in vambn/modelling/models/hivae/trainer.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|