pytagi.nn.linear#

Classes#

Linear

Implements a Fully-connected layer, also known as a dense layer.

Module Contents#

class pytagi.nn.linear.Linear(input_size: int, output_size: int, bias: bool = True, gain_weight: float = 1.0, gain_bias: float = 1.0, init_method: str = 'He')[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Implements a Fully-connected layer, also known as a dense layer. This layer performs a linear transformation on the input data: \(y = xW^T + b\), where \(x\) is the input, \(W\) is the weight matrix, and \(b\) is the optional bias vector. It inherits from BaseLayer.

Initializes the Linear layer.

Parameters:
  • input_size – The number of features in the input tensor (the size of the last dimension).

  • output_size – The number of features in the output tensor. This determines the number of neurons in the layer.

  • bias – If True, an additive bias vector ‘b’ is included in the linear transformation. Defaults to True.

  • gain_weight – Scaling factor applied to the initialized weights (\(W\)). Defaults to 1.0.

  • gain_bias – Scaling factor applied to the initialized biases (\(b\)). Defaults to 1.0.

  • init_method – The method used for initializing the weights and biases (e.g., “He”, “Xavier”, “Normal”). Defaults to “He”.

get_layer_info() str[source]#

Retrieves a descriptive string containing information about the layer’s configuration (e.g., input/output size, whether bias is used) from the C++ backend.

get_layer_name() str[source]#

Retrieves the name of the layer (e.g., ‘Linear’) from the C++ backend.

init_weight_bias()[source]#

Initializes the layer’s parameters—the weight matrix (\(W\)) and the optional bias vector (\(b\))—using the specified initialization method and gain factors. This task is delegated to the C++ backend.