posthoc.models

Base classes and configuration

class posthoc.models.base.GenotypeDataset(genotypes, phenotype, covariates=None)[source]

Bases: Dataset

Parameters:
  • genotypes (np.ndarray)

  • phenotype (np.ndarray)

  • covariates (np.ndarray | None)

MISSING_CODE = -9
class posthoc.models.base.TrainConfig(task: "Literal['logistic', 'linear']" = 'logistic', val_fraction: 'float' = 0.2, batch_size: 'int' = 64, max_epochs: 'int' = 200, patience: 'int' = 15, lr: 'float' = 0.0001, weight_decay: 'float' = 0.0001, device: 'str' = 'cpu', seed: 'int' = 0)[source]

Bases: object

Parameters:
task: Literal['logistic', 'linear'] = 'logistic'
val_fraction: float = 0.2
batch_size: int = 64
max_epochs: int = 200
patience: int = 15
lr: float = 0.0001
weight_decay: float = 0.0001
device: str = 'cpu'
seed: int = 0
class posthoc.models.base.TrainResult(model: 'nn.Module', best_val_loss: 'float', train_losses: 'list[float]', val_losses: 'list[float]', stopped_epoch: 'int', train_idx: 'np.ndarray', val_idx: 'np.ndarray')[source]

Bases: object

Parameters:
model: Module
best_val_loss: float
train_losses: list[float]
val_losses: list[float]
stopped_epoch: int
train_idx: ndarray
val_idx: ndarray
class posthoc.models.base.MLPConfig(hidden_dims: 'list[int]' = <factory>, dropout: 'float' = 0.2, data_dropout: 'bool' = False, batch_norm: 'bool' = True, activation: 'str' = 'relu')[source]

Bases: object

Parameters:
hidden_dims: list[int]
dropout: float = 0.2
data_dropout: bool = False
batch_norm: bool = True
activation: str = 'relu'

MLP

class posthoc.models.mlp.MLP(input_dim, config=None)[source]

Bases: Module

Parameters:
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

posthoc.models.mlp.build_mlp(n_snps, n_covariates=0, config=None)[source]
Parameters:
Return type:

MLP

Training utilities

posthoc.models.utils.make_split(n_samples, phenotype, val_fraction, task, seed)[source]
Parameters:
Return type:

tuple[ndarray, ndarray]

posthoc.models.utils.get_loss_fn(task)[source]
Parameters:

task (str)

Return type:

Module

posthoc.models.utils.train_model(model, genotypes, phenotype, covariates, config)[source]
Parameters:
Return type:

TrainResult