Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Sktime Pytorch forecasting FullyConnectedModule

From Leeroopedia


Knowledge Sources
Domains Time_Series, Forecasting, Deep_Learning
Last Updated 2026-02-08 08:00 GMT

Overview

FullyConnectedModule is a configurable multi-layer perceptron (MLP) implemented as a PyTorch nn.Module, supporting optional dropout and layer normalization between hidden layers.

Description

FullyConnectedModule constructs a sequential feedforward neural network with a configurable number of hidden layers, each followed by an activation function and optional dropout and layer normalization. The architecture consists of an input projection layer, zero or more hidden layers of uniform width, and a final linear output layer. This module serves as the core submodule within the MLP forecasting model in pytorch-forecasting.

Usage

Use FullyConnectedModule when you need a standalone, reusable MLP block within a larger forecasting architecture. It is the primary submodule used by the DecoderMLP and related MLP-based models in pytorch-forecasting for mapping encoded time series features to prediction outputs.

Code Reference

Source Location

Signature

class FullyConnectedModule(nn.Module):
    def __init__(
        self,
        input_size: int,
        output_size: int,
        hidden_size: int,
        n_hidden_layers: int,
        activation_class: nn.ReLU,
        dropout: float = None,
        norm: bool = True,
    ):

Import

from pytorch_forecasting.models.mlp.submodules import FullyConnectedModule

I/O Contract

Inputs

Name Type Required Description
input_size int Yes Dimensionality of the input features
output_size int Yes Dimensionality of the output features
hidden_size int Yes Number of neurons in each hidden layer
n_hidden_layers int Yes Number of hidden layers between the input and output layers
activation_class nn.Module class Yes Activation function class to apply after each linear layer (e.g., nn.ReLU)
dropout float No Dropout probability applied after each activation; None disables dropout
norm bool No Whether to apply LayerNorm after each hidden layer; defaults to True

Outputs

Name Type Description
forward(x) torch.Tensor Output tensor of shape (batch_size, output_size) produced by the sequential MLP

Usage Examples

import torch
from torch import nn
from pytorch_forecasting.models.mlp.submodules import FullyConnectedModule

# Create a 3-hidden-layer MLP with dropout and layer normalization
mlp = FullyConnectedModule(
    input_size=30,
    output_size=10,
    hidden_size=64,
    n_hidden_layers=3,
    activation_class=nn.ReLU,
    dropout=0.1,
    norm=True,
)

# Forward pass: batch of 16 samples, 30 input features
x = torch.randn(16, 30)
output = mlp(x)  # shape: (16, 10)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment