MLPs

class spherical_inr.mlp.MLP(input_features: int, output_features: int, hidden_sizes: List[int], bias: bool = True, activation: str = 'relu', activation_kwargs: dict = {})[source]

Bases: Module

Multi-Layer Perceptron (MLP).

Defines a feedforward neural network that computes a mapping \(f: \mathbb{R}^{\text{input\_features}} \to \mathbb{R}^{\text{output\_features}}\) via a series of fully connected layers interleaved with an activation function. If \(x\) is the input, then the network computes

\[f(x) = W_L\,\phi\Bigl(W_{L-1}\,\phi\bigl(\cdots\,\phi(W_1\,x+b_1)\bigr)+b_{L-1}\Bigr)+b_L,\]

where \(\phi\) denotes the activation function and \(W_i\) and \(b_i\) are the weight matrices and bias vectors of each layer, respectively.

Parameters:
  • input_features (int) – Dimensionality of the input.

  • output_features (int) – Dimensionality of the output.

  • hidden_sizes (List[int]) – List of integers specifying the sizes of hidden layers.

  • bias (bool, optional) – If True, each linear layer includes a bias term (default: True).

  • activation (str, optional) – Identifier for the activation function to use (default: “relu”).

  • activation_kwargs (dict, optional) – Additional keyword arguments for configuring the activation function.

forward(x: Tensor) Tensor[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.

class spherical_inr.mlp.SineMLP(input_features: int, output_features: int, hidden_sizes: List[int], bias: bool = True, omega0: float = 1.0)[source]

Bases: MLP

Sine-Activated Multi-Layer Perceptron (SineMLP).

A variant of the MLP where the activation function is sine with a frequency scaling factor \(\omega_0\). For an input \(x\), the network computes

\[f(x) = W_L\,\sin\Bigl(\omega_0\Bigl(W_{L-1}\,\sin\bigl(\omega_0(\cdots\,\sin(W_1\,x+b_1)\bigr)+b_{L-1}\Bigr)\Bigr)+b_L.\]

In addition, the weights are initialized uniformly in the range

\[\left[-\frac{\sqrt{6/n}}{\omega_0},\,\frac{\sqrt{6/n}}{\omega_0}\right],\]

where \(n\) is the number of input features to the corresponding layer.

Parameters:
  • input_features (int) – Dimensionality of the input.

  • output_features (int) – Dimensionality of the output.

  • hidden_sizes (List[int]) – List of integers specifying the sizes of hidden layers.

  • bias (bool, optional) – If True, each linear layer includes a bias term (default: True).

  • omega0 (float, optional) – Frequency factor for the sine activation and weight initialization (default: 1.0).

init() None[source]