torch_frame.nn.encoder.TimestampEncoder

class TimestampEncoder(out_channels: Optional[int] = None, stats_list: Optional[list[dict[torch_frame.data.stats.StatType, Any]]] = None, stype: Optional[stype] = None, post_module: Optional[Module] = None, na_strategy: torch_frame.typing.NAStrategy | None = NAStrategy.MEDIAN_TIMESTAMP, out_size: int = 8)[source]

Bases: StypeEncoder

TimestampEncoder for timestamp stype. Year is encoded with torch_frame.nn.encoding.PositionalEncoding. The other features, including month, day, dayofweek, hour, minute and second, are encoded using torch_frame.nn.encoding.CyclicEncoding. It applies linear layer for each column in a batched manner. The TimestampEncoder does not support NaN timestamps, because torch_frame.nn.encoding.PositionalEncoding does not support negative tensor values. So torch_frame.NAStrategy.MEDIAN_TIMESTAMP is applied as the default NAStrategy.

Parameters:

out_size (int) – Output dimension of the positional and cyclic encodings.

reset_parameters() None[source]

Initialize the parameters of post_module.

encode_forward(feat: Tensor, col_names: Optional[list[str]] = None) Tensor[source]

The main forward function. Maps input feat from TensorFrame (shape [batch_size, num_cols]) into output x of shape [batch_size, num_cols, out_channels].