pyhealth.processors.StageNetTensorProcessor#
Processor for StageNet numeric inputs with coupled value/time data and forward-fill imputation.
- class pyhealth.processors.StageNetTensorProcessor[source]#
Bases:
TemporalFeatureProcessorFeature processor for StageNet NUMERIC inputs with coupled value/time data.
This processor handles numeric feature sequences (flat or nested) and applies forward-fill imputation to handle missing values (NaN/None). For categorical codes, use StageNetProcessor instead.
Format: {
“value”: [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], # nested numerics “time”: [0.0, 1.5] or None
}
The processor automatically detects: - List of numbers -> flat numeric sequences - List of lists of numbers -> nested numeric sequences (feature vectors)
Imputation Strategy: - Forward-fill: Missing values (NaN/None) are filled with the last observed
value for that feature dimension. If no prior value exists, 0.0 is used.
Applied per feature dimension independently
- Returns:
Tuple of (time_tensor, value_tensor) where time_tensor can be None
Examples
>>> # Case 1: Feature vectors with missing values >>> processor = StageNetTensorProcessor() >>> data = { ... "value": [[1.0, None, 3.0], [None, 5.0, 6.0], [7.0, 8.0, None]], ... "time": [0.0, 1.5, 3.0] ... } >>> time, values = processor.process(data) >>> values # [[1.0, 0.0, 3.0], [1.0, 5.0, 6.0], [7.0, 8.0, 6.0]] >>> values.dtype # torch.float32 >>> time.shape # (3,)
- process(value)[source]#
Process tuple format numeric data into tensors.
Applies forward-fill imputation to handle NaN/None values. For each feature dimension, missing values are filled with the last observed value (or 0.0 if no prior value exists).
- dim()[source]#
Number of dimensions for each output tensor.
Time tensor is 1D. Value tensor is 1D (flat) or 2D (nested). Must be called after fit().
- value_dim()[source]#
Number of numeric features per time-step (used with nn.Linear). Must be called after fit().
- Return type:
- process_temporal(value)[source]#
Return dict output for UnifiedMultimodalEmbeddingModel.
- Returns:
FloatTensor (T, F), “time”: FloatTensor (T,) or None}
- Return type:
{“value”
- load(path)#
Optional: Load processor state from disk.