Modeling Module
Classifier
Bases: Module
Multi-class classifier for adversarial training in n-modal latent space alignment.
Attributes:
| Name | Type | Description |
|---|---|---|
input_dim |
Dimension of the input features. |
|
n_modalities |
Number of modalities (classes) to classify. |
|
n_hidden |
Number of hidden units in the classifier network. |
Source code in src/autoencodix/modeling/_classifier.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
forward(x)
Forward pass through the classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor of shape (batch_size, input_dim). |
required |
Returns: Output tensor of shape (batch_size, n_modalities) representing class scores.
Source code in src/autoencodix/modeling/_classifier.py
31 32 33 34 35 36 37 38 39 | |
ImageVAEArchitecture
Bases: BaseAutoencoder
This class defines a VAE, based on a CNN for images
It takes as input an image and of shape (C,W,H) and reconstructs it.
We ensure to have a latent space of shape
So we need to calculate how the image dimension changes after each Convolution (we assume W=H) Applying the formular: W_out = (((W - kernel_size + 2padding)/stride) + 1) We get: W_out = (((W-4+2*1)/2)+1) = = (W-2/2)+1 = = (2(0.5W-1)/2) +1 # factor 2 out = 0.5W - 1 + 1 W_out = 0.5W So in this configuration the output shape halfs after every convolutional step (assuming W=H)
Attributes:
| Name | Type | Description |
|---|---|---|
input_dim |
int
|
(C,W,H) the input image shape |
config |
Configuration object containing model architecture parameters |
|
_encoder |
Optional[Module]
|
Encoder network of the autoencoder |
_decoder |
Optional[Module]
|
Decoder network of the autoencoder |
latent_dim |
int
|
Dimension of the latent space |
nc |
int
|
number of channels in the input image |
h |
int
|
height of the input image |
w |
int
|
width of the input image |
img_shape |
Tuple[int, int, int]
|
(C,W,H) the input image shape |
hidden_dim |
int
|
number of filters in the first convolutional layer |
Source code in src/autoencodix/modeling/_imagevae_architecture.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 | |
__init__(input_dim, config, ontologies=None, feature_order=None)
Initialize the ImageVAEArchitecture with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim
|
Tuple[int, int, int]
|
(C,W,H) the input image shape |
required |
config
|
Optional[DefaultConfig]
|
Configuration object containing model parameters. |
required |
hidden_dim
|
number of filters in the first convolutional layer |
required |
Source code in src/autoencodix/modeling/_imagevae_architecture.py
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 | |
decode(x)
Decode the latent tensor x Args: x: Latent tensor Returns: Decoded tensor, reconstructed from the latent space
Source code in src/autoencodix/modeling/_imagevae_architecture.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
encode(x)
Encodes the input tensor x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns: The encoded latent space representation, or mu and logvar for VAEs.
Source code in src/autoencodix/modeling/_imagevae_architecture.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
forward(x)
Forward pass of the model. Args: x: Input tensor Returns: ModelOutput object containing the reconstructed tensor and latent tensor
Source code in src/autoencodix/modeling/_imagevae_architecture.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
get_latent_space(x)
Returns the latent space representation of the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns: Latent space representation
Source code in src/autoencodix/modeling/_imagevae_architecture.py
243 244 245 246 247 248 249 250 251 252 253 | |
reparameterize(mu, logvar)
Reparameterization trick for VAE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
Tensor
|
mean of the latent distribution |
required |
logvar
|
Tensor
|
log-variance of the latent distribution |
required |
Returns: z: sampled latent vector
Source code in src/autoencodix/modeling/_imagevae_architecture.py
230 231 232 233 234 235 236 237 238 239 240 241 | |
translate(z)
Reshapes the output to get actual images
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Latent tensor |
required |
Returns: Reconstructed image of shape (C,W,H)
Source code in src/autoencodix/modeling/_imagevae_architecture.py
270 271 272 273 274 275 276 277 278 279 | |
LayerFactory
Factory for creating configurable neural network layers.
Source code in src/autoencodix/modeling/_layer_factory.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 | |
create_layer(in_features, out_features, dropout_p=0.1, last_layer=False)
staticmethod
Create a configurable layer with optional components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Input feature dimension |
required |
out_features
|
int
|
Output feature dimension |
required |
dropout_p
|
float
|
Dropout probability, by default 0.1 |
0.1
|
last_layer
|
bool
|
Flag to skip activation/dropout for final layer, by default False |
False
|
Returns:
| Type | Description |
|---|---|
List[Module]
|
List of layer components |
Source code in src/autoencodix/modeling/_layer_factory.py
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 | |
get_layer_dimensions(feature_dim, latent_dim, n_layers, enc_factor)
staticmethod
Calculate progressive layer dimensions.
Args: feature_dim: Input feature dimension latent_dim: Target latent dimension n_layers: Number of layers enc_factor: Reduction factor for layer sizes
Returns:
| Type | Description |
|---|---|
List[int]
|
Calculated layer dimensions |
Source code in src/autoencodix/modeling/_layer_factory.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
MaskixArchitectureVanilla
Bases: BaseAutoencoder
Masked Autoencoder Architecture that follows https://doi.org/10.1093/bioinformatics/btae020
To closely mimic the publication, the network is not build with our LayerFactory as in other architectures.
Attributes:
| Name | Type | Description |
|---|---|---|
input_dim |
Union[int, Tuple[int, ...]]
|
number of input features |
config |
Configuration object containing model architecture parameters |
|
encoder |
Encoder network of the autoencoder |
|
decoder |
Decoder network of the autoencoder |
Source code in src/autoencodix/modeling/_maskix_architecture.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
decode(x)
Decodes the latent representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input Tensor |
required |
Returns: torch.Tensor
Source code in src/autoencodix/modeling/_maskix_architecture.py
85 86 87 88 89 90 91 92 93 94 | |
encode(x)
Encodes the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input Tensor |
required |
Returns: torch.Tensor
Source code in src/autoencodix/modeling/_maskix_architecture.py
63 64 65 66 67 68 69 70 71 72 | |
get_latent_space(x)
Returns the latent space representation of the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input Tensor |
required |
Returns: torch.Tensor
Source code in src/autoencodix/modeling/_maskix_architecture.py
74 75 76 77 78 79 80 81 82 83 | |
OntixArchitecture
Bases: BaseAutoencoder
Ontology Autoencoder implementation with separate encoder and decoder construction.
Attributes: input_dim: number of input features config: Configuration object containing model architecture parameters _encoder: Encoder network of the autoencoder _decoder: Decoder network of the autoencoder mu: Linear layer to compute the mean of the latent distribution logvar: Linear layer to compute the log-variance of the latent distribution masks: Tuple of weight masks for the decoder layers based on ontology latent_dim: Dimension of the latent space, inferred from the first mask ontologies: Ontology information. feature_order: Order of features for input data.
Source code in src/autoencodix/modeling/_ontix_architecture.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
__init__(config, input_dim, ontologies, feature_order)
Initialize the Vanilla Autoencoder with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[Union[None, DefaultConfig]]
|
Configuration object containing model parameters. |
required |
input_dim
|
int
|
Number of input features. |
required |
ontologies
|
tuple
|
Ontology information. |
required |
feature_order
|
list
|
Order of features for input data. |
required |
Source code in src/autoencodix/modeling/_ontix_architecture.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 | |
decode(x)
Decode the latent tensor x
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Latent tensor |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor |
Tensor
|
Decoded tensor |
Source code in src/autoencodix/modeling/_ontix_architecture.py
259 260 261 262 263 264 265 266 267 268 269 270 | |
encode(x)
Encode the input tensor x
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Encoded tensor |
Source code in src/autoencodix/modeling/_ontix_architecture.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
forward(x)
Forward pass of the model, fill
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns:
| Type | Description |
|---|---|
ModelOutput
|
ModelOutput object containing the reconstructed tensor and latent tensor |
Source code in src/autoencodix/modeling/_ontix_architecture.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
get_latent_space(x)
Returns the latent space representation of the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Latent space representation |
Source code in src/autoencodix/modeling/_ontix_architecture.py
293 294 295 296 297 298 299 300 301 302 303 304 305 | |
reparameterize(mu, logvar)
Reparameterization trick for VAE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
Tensor
|
Mean tensor |
required |
logvar
|
Tensor
|
Log variance tensor |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Reparameterized latent tensor |
Source code in src/autoencodix/modeling/_ontix_architecture.py
245 246 247 248 249 250 251 252 253 254 255 256 257 | |
VanillixArchitecture
Bases: BaseAutoencoder
Vanilla Autoencoder implementation with separate encoder and decoder construction.
Attributes:
| Name | Type | Description |
|---|---|---|
input_dim |
number of input features |
|
config |
Configuration object containing model architecture parameters |
|
encoder |
Encoder network of the autoencoder |
|
decoder |
Decoder network of the autoencoder |
Source code in src/autoencodix/modeling/_vanillix_architecture.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__init__(config, input_dim, ontologies=None, feature_order=None)
Initialize the Vanilla Autoencoder with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[Union[None, DefaultConfig]]
|
Configuration object containing model parameters. |
required |
input_dim
|
int
|
Number of input features. |
required |
Source code in src/autoencodix/modeling/_vanillix_architecture.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
decode(x)
Decodes the latent representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input Tensor |
required |
Returns: torch.Tensor
Source code in src/autoencodix/modeling/_vanillix_architecture.py
109 110 111 112 113 114 115 116 117 118 | |
encode(x)
Encodes the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input Tensor |
required |
Returns: torch.Tensor
Source code in src/autoencodix/modeling/_vanillix_architecture.py
87 88 89 90 91 92 93 94 95 96 | |
forward(x)
Forward pass of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input Tensor |
required |
Returns: ModelOutput
Source code in src/autoencodix/modeling/_vanillix_architecture.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
get_latent_space(x)
Returns the latent space representation of the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
input Tensor |
required |
Returns: torch.Tensor
Source code in src/autoencodix/modeling/_vanillix_architecture.py
98 99 100 101 102 103 104 105 106 107 | |
VarixArchitecture
Bases: BaseAutoencoder
Variational Autoencoder implementation with separate encoder and decoder construction.
Attributes:
| Name | Type | Description |
|---|---|---|
input_dim |
int
|
number of input features |
config |
Configuration object containing model architecture parameters |
|
encoder |
Encoder network of the autoencoder |
|
decoder |
Decoder network of the autoencoder |
|
mu |
Linear layer to compute the mean of the latent distribution |
logvar: Linear layer to compute the log-variance of the latent distribution
Source code in src/autoencodix/modeling/_varix_architecture.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
__init__(config, input_dim, ontologies=None, feature_order=None)
Initialize the Vanilla Autoencoder with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[Union[None, DefaultConfig]]
|
Configuration object containing model parameters. |
required |
input_dim
|
int
|
Number of input features. |
required |
Source code in src/autoencodix/modeling/_varix_architecture.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
decode(x)
Decode the latent tensor x
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Latent tensor |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Decoded tensor |
Source code in src/autoencodix/modeling/_varix_architecture.py
159 160 161 162 163 164 165 166 167 168 169 | |
encode(x)
Encode the input tensor x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Encoded tensor |
Source code in src/autoencodix/modeling/_varix_architecture.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
forward(x)
Forward pass of the model, fill
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns:
| Type | Description |
|---|---|
ModelOutput
|
ModelOutput object containing the reconstructed tensor and latent tensor |
Source code in src/autoencodix/modeling/_varix_architecture.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
get_latent_space(x)
Returns the latent space representation of the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Latent space representation |
Source code in src/autoencodix/modeling/_varix_architecture.py
145 146 147 148 149 150 151 152 153 154 155 156 157 | |
reparameterize(mu, logvar)
Reparameterization trick for VAE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
Tensor
|
torch.Tensor |
required |
logvar
|
Tensor
|
torch.Tensor |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor |
Source code in src/autoencodix/modeling/_varix_architecture.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |