fusionlab.nn.components.aggregate_time_window_output

fusionlab.nn.components.aggregate_time_window_output(time_window_output, mode=None)[source]

Aggregates time window output features based on the specified aggregation method.

This function performs the final aggregation on a 3D tensor representing temporal features. The aggregation can be done by selecting the last time step, computing the average across time, or flattening the temporal and feature dimensions into a single vector per sample.

The aggregation methods are defined as follows:

\[ext{last: } F = T[:, -1, :]\]
\[ext{average: } F =\]
rac{1}{T_{dim}} sum_{i=1}^{T_{dim}}

T[:, i, :]

\[ext{flatten: } F = ext{reshape}(T, (batch\_size, time\_dim imes feat\_dim))\]

where \(T\) is the input tensor with shape \((batch\_size, time\_dim, feat\_dim)\) and \(F\) is the aggregated output.

time_window_outputtf.Tensor

A 3D tensor of shape \((batch\_size, time\_dim, feat\_dim)\) representing the output features over time.

modestr, optional

Aggregation method to apply. Supported values are:

  • "last": Selects the features from the last time step.

  • "average": Computes the mean of features across the time dimension.

  • "flatten": Flattens the time and feature dimensions into a single vector per sample.

If mode is None, the function falls back to the flatten aggregation method.

tf.Tensor

The aggregated features tensor after applying the specified aggregation method.

ValueError

If an unsupported aggregation method is provided in the mode argument.

>>> from fusionlab.nn.components import aggregate_time_window_output
>>> import tensorflow as tf
>>> # Create a dummy tensor with shape (2, 3, 4)
>>> dummy = tf.random.uniform((2, 3, 4))
>>> # Apply average aggregation
>>> result = aggregate_time_window_output(dummy,
...                                      mode="average")
  • The function uses TensorFlow operations to ensure compatibility with TensorFlow’s computation graph.

  • It is recommended to use this function as part of a larger neural network pipeline [1].

tf.reduce_mean

TensorFlow operation to compute mean along axes.

Parameters:
  • time_window_output (Tensor)

  • mode (str | None)