immuneML.ml_methods.pytorch_implementations package

Submodules

immuneML.ml_methods.pytorch_implementations.PyTorchLogisticRegression module

class immuneML.ml_methods.pytorch_implementations.PyTorchLogisticRegression.PyTorchLogisticRegression(in_features: int, zero_abundance_weight_init: bool)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

immuneML.ml_methods.pytorch_implementations.PyTorchReceptorCNN module

class immuneML.ml_methods.pytorch_implementations.PyTorchReceptorCNN.PyTorchReceptorCNN(kernel_count: int, kernel_size, positional_channels: int, sequence_type: immuneML.environment.SequenceType.SequenceType, background_probabilities, chain_names)[source]

Bases: torch.nn.modules.module.Module

This class implements the ReceptorCNN using PyTorch. This is one specific implementation of the architecture proposed in ReceptorCNN.

forward(x)[source]

Implements the forward pass through the network by applying kernels to the one-hot encoded receptors, followed by ReLU activation and max pooling. The obtained output is then concatenated to get the receptor representation. A fully-connected layer is then applied to the representation to predict the class assignment.

Parameters

x – input data consisting of one-hot encoded immune receptors with optional positional information

Returns

predictions of class assignment

get_max_information_gain()[source]

Information gain corresponds to Kullback-Leibler divergence between the observed probability p of an option (e.g. amino acid) ond null (or background) probability q of the option:

\[ \begin{align}\begin{aligned}KL(p||q) = \sum_n p_n \, log_2 \, \frac{p_n}{q_n} = \sum_n p_n \, log_2 \, p_n - \sum_n p_n \, log_2 \, q_n = \sum_n p_n \, log_2 \, p_n - log_2 \, q_n\\log_2 \, q_n < 0 \, \, \, (1)\\\sum_n p_n \, log_2 \, p_n < 0 \, \, \, (2)\\(1) \wedge (2) \Rightarrow max(KL(p||q)) = - log_2 \, q_n\end{aligned}\end{align} \]
Returns

max information gain given background probabilities

rescale_weights_for_IGM()[source]

Rescales the weights in the kernels to represent information gain matrices.

Module contents