model_torch module

class model_torch.BoundedActivation(M=100.0)[source]

Bases: Module

Bounded Activation Layer that applies a bounded activation function using tanh.

bounded_activation(x)

Apply the bounded activation to the input tensor.

forward(input)[source]

Forward pass to apply bounded activation.

forward(input)[source]

Forward pass through the bounded activation layer.

Parameters:

input (torch.Tensor) – Input tensor.

Returns:

Output after applying bounded activation.

Return type:

torch.Tensor

class model_torch.Discriminator(input_dim, batch_size, spec_norm, bounded, layers_list, device='cpu')[source]

Bases: Module

Discriminator Class that initializes and processes the discriminator network.

Parameters:
  • input_dim (int) – Dimension of the input features.

  • batch_size (int) – Batch size for processing.

  • spec_norm (bool) – Whether to apply spectral normalization to the layers.

  • bounded (bool) – Whether to apply bounded activation on the final output.

  • layers_list (list) – List of integers specifying the number of units for each hidden layer.

  • device (str) – Device to run the model on (‘cpu’ or ‘cuda’).

forward(inputs)[source]

Forward pass through the network.

Returns:

Output after processing through the discriminator network.

Return type:

torch.Tensor

forward(inputs)[source]

Forward pass through the discriminator.

Parameters:

inputs (torch.Tensor) – Input data to the network.

Returns:

Discriminator’s prediction after processing the inputs.

Return type:

torch.Tensor

class model_torch.Discriminator_MNIST[source]

Bases: Module

Discriminator Class for MNIST that processes the input and classifies real vs fake images.

forward(x)[source]

Forward pass through the network.

Returns:

Output after processing the input image through the discriminator network.

Return type:

torch.Tensor

forward(x)[source]

Forward pass through the MNIST discriminator.

Parameters:

x (torch.Tensor) – Input image data reshaped to (batch_size, 784).

Returns:

Output after processing through dense and normalization layers.

Return type:

torch.Tensor

class model_torch.Generator(X_dim, Z_dim, batch_size, spec_norm, layers_list, device='cpu')[source]

Bases: Module

Generator Class that initializes and processes the generator network.

Parameters:
  • X_dim (int) – Dimension of the output generated by the generator.

  • Z_dim (int) – Dimension of the input latent space.

  • batch_size (int) – Batch size for processing.

  • spec_norm (bool) – Whether to apply spectral normalization to the layers.

  • layers_list (list) – List of integers specifying the number of units for each hidden layer.

  • device (str) – Device to run the model on (‘cpu’ or ‘cuda’).

forward(inputs)[source]

Forward pass through the network.

Returns:

Generated output after processing the latent input.

Return type:

torch.Tensor

forward(inputs)[source]

Forward pass through the generator.

Parameters:

inputs (torch.Tensor) – Input latent vector.

Returns:

Generated output.

Return type:

torch.Tensor