pysatl_tsp.core.processor.lag_handler

Module Contents

Classes

LagHandler

A handler that applies a lag-based transformation to time series data.

API

class pysatl_tsp.core.processor.lag_handler.LagHandler(lag: int)[source]

Bases: pysatl_tsp.core.Handler[float | None, float | None]

A handler that applies a lag-based transformation to time series data.

This handler applies a formula (2 * current_value - lagged_value) that compares the current value with a value from ‘lag’ time steps in the past. For the first ‘lag’ values where no lagged value is available, it outputs None.

The transformation can be useful for detecting changes or trends in time series by comparing current values with historical ones.

Parameters:

lag – Number of time steps to look back for the lagged value

Example:
# Create a data source with numeric values
data_source = SimpleDataProvider([1.0, 2.0, 3.0, 4.0, 5.0])

# Create a lag handler with lag of 2
lag_handler = LagHandler(lag=2)
lag_handler.set_source(data_source)

# Process the data
results = list(lag_handler)
print(results)

# Output:
# [None, None, 5.0, 6.0, 7.0]
#
# Explanation:
# - First two values: None (not enough history)
# - Third value: 2*3.0-1.0 = 5.0 (current=3.0, lagged=1.0)
# - Fourth value: 2*4.0-2.0 = 6.0 (current=4.0, lagged=2.0)
# - Fifth value: 2*5.0-3.0 = 7.0 (current=5.0, lagged=3.0)

Initialization

Initialize a lag handler.

Parameters:

lag – Number of time steps to look back for the lagged value

__iter__() collections.abc.Iterator[float | None][source]

Create an iterator that yields transformed values based on lag comparison.

This method outputs None for the first ‘lag’ values, then applies the formula 2 * current_value - lagged_value for subsequent values. If either the current value or the lagged value is None, the result will be None.

Returns:

Iterator yielding transformed values or None

Raises:

ValueError – If no source has been set