fusionlab.nn.utils.split_static_dynamic¶
- fusionlab.nn.utils.split_static_dynamic(sequences, static_indices, dynamic_indices, static_time_step=0, reshape_static=True, reshape_dynamic=True, static_reshape_shape=None, dynamic_reshape_shape=None)[source]¶
Split sequences into static and dynamic inputs for the model.
The split_static_dynamic function divides input sequences into static and dynamic components based on specified feature indices. Static features are typically location-specific and do not change over time, while dynamic features vary across different time steps.
\[\begin{split}\text{Static Inputs} = \mathbf{S} = \mathbf{X}_{t, static\_indices} \\ \text{Dynamic Inputs} = \mathbf{D} = \mathbf{X}_{:, dynamic\_indices}\end{split}\]- Parameters:
sequences (numpy.ndarray) – Array of input sequences with shape (batch_size, sequence_length, num_features).
static_indices (List[int]) – Indices of static features within the feature dimension.
dynamic_indices (List[int]) – Indices of dynamic features within the feature dimension.
static_time_step (int, default 0) – Time step from which to extract static features (default is the first time step).
reshape_static (bool, default True) – Whether to reshape static inputs. If False, returns without reshaping.
reshape_dynamic (bool, default True) – Whether to reshape dynamic inputs. If False, returns without reshaping.
static_reshape_shape (:class:
Optional[Tuple[int`, :class:`...]], default None) – Desired shape for static inputs after reshaping. If None, defaults to (batch_size, num_static_vars, 1).dynamic_reshape_shape (:class:
Optional[Tuple[int`, :class:`...]], default None) – Desired shape for dynamic inputs after reshaping. If None, defaults to (batch_size, sequence_length, num_dynamic_vars, 1).
- Returns:
A tuple containing: - Static inputs with shape as specified. - Dynamic inputs with shape as specified.
- Return type:
Tuple[`numpy.ndarray`, numpy.ndarray]- Raises:
ValueError – If static_time_step is out of range for the given sequence length.
Examples
>>> import numpy as np >>> from fusionlab.nn.utils import split_static_dynamic >>> >>> # Create a dummy sequence array >>> sequences = np.random.rand(100, 10, 5) # ( ... batch_size=100, sequence_length=10, num_features=5) >>> >>> # Define static and dynamic feature indices >>> static_indices = [0, 1] # e.g., longitude and latitude >>> dynamic_indices = [2, 3, 4] # e.g., year, GWL, density >>> >>> # Split the sequences >>> static_inputs, dynamic_inputs = split_static_dynamic( ... sequences, ... static_indices=static_indices, ... dynamic_indices=dynamic_indices, ... static_time_step=0 ... ) >>> >>> print(static_inputs.shape) (100, 2, 1) >>> print(dynamic_inputs.shape) (100, 10, 3, 1)
Notes
Static Features: These are typically location-specific features such as geographical coordinates or categorical attributes that remain constant over time.
Dynamic Features: These features vary over different time steps and are essential for capturing temporal dependencies in the data.
Reshaping: The function provides flexibility in reshaping the static and dynamic inputs to match the input requirements of various models, including Temporal Fusion Transformers.
See also
NoneFunction to create input sequences and targets for
timeReferences