online_wrappers
Composable wrappers for online algorithms.
- class pysatl_cpd.core.online.wrappers.online_wrappers.SkippingCondition(*, name, condition)[source]
Bases:
GenericNamed condition deciding whether an observation should be skipped.
- Variables:
name – Human-readable identifier for this condition.
condition – Callable that returns True when an observation should be skipped (not passed to the underlying algorithm).
- Parameters:
- __post_init__()[source]
Validate that the condition name is non-empty.
- Raises:
ValueError – If name is an empty string.
- Return type:
- class pysatl_cpd.core.online.wrappers.online_wrappers.BatchReducer(*, name, reducer)[source]
Bases:
GenericNamed reducer converting a block of observations into one observation.
- Variables:
name – Human-readable identifier for this reducer.
reducer – Callable that converts a sequence of raw observations into a single value for the wrapped algorithm.
- Parameters:
- __post_init__()[source]
Validate that the reducer name is non-empty.
- Raises:
ValueError – If name is an empty string.
- Return type:
- class pysatl_cpd.core.online.wrappers.online_wrappers.SkippingOnlineAlgorithmWrapper(algorithm, *, skipping_condition)[source]
Bases:
OnlineAlgorithm,GenericWrap an online algorithm and optionally skip observations.
When the configured
skipping_conditionis met for an observation, the wrapper returns the last computed detection statistic without passing the observation to the wrapped algorithm.- Parameters:
algorithm (
OnlineAlgorithm[TypeVar(DataT),TypeVar(ConfigurationT, bound=OnlineAlgorithmConfiguration),TypeVar(StateT, bound=OnlineAlgorithmState)]) – Algorithm to wrap.skipping_condition (
SkippingCondition[TypeVar(DataT)]) – Condition that decides which observations to skip.
- __init__(algorithm, *, skipping_condition)[source]
- Parameters:
algorithm (OnlineAlgorithm[DataT, ConfigurationT, StateT])
skipping_condition (SkippingCondition[DataT])
- Return type:
None
- property name: str
Return a composite name reflecting the wrapped algorithm and condition.
- Returns:
Composite name in the form
AlgorithmName{skip[on=condition]}.- Return type:
- property configuration: ConfigurationT
Return the wrapped algorithm’s configuration.
- Returns:
Configuration of the underlying algorithm.
- Return type:
ConfigurationT
- property state: StateT
Return the wrapped algorithm’s current state.
- Returns:
Current state of the underlying algorithm.
- Return type:
StateT
- reset()[source]
Reset the wrapper and the underlying algorithm to initial state.
Clears the cached last detection function value and delegates reset to the wrapped algorithm.
- Return type:
- recreate()[source]
Return a fresh instance with the same skipping condition.
- Returns:
A new wrapper instance sharing the same skipping condition but a freshly recreated underlying algorithm.
- Return type:
SkippingOnlineAlgorithmWrapper[TypeVar(DataT),TypeVar(ConfigurationT, bound=OnlineAlgorithmConfiguration),TypeVar(StateT, bound=OnlineAlgorithmState)]
- class pysatl_cpd.core.online.wrappers.online_wrappers.BatchingOnlineAlgorithmWrapper(algorithm, *, batch_size, reducer)[source]
Bases:
OnlineAlgorithm,GenericWrap an online algorithm and feed it reduced observation batches.
Raw observations are buffered until the batch is full, then reduced to a single value via
BatchReducerand passed to the wrapped algorithm. Partial batches return the last computed statistic.- Parameters:
algorithm (
OnlineAlgorithm[TypeVar(BatchT),TypeVar(ConfigurationT, bound=OnlineAlgorithmConfiguration),TypeVar(StateT, bound=OnlineAlgorithmState)]) – Algorithm to wrap (operates on the reduced batch type).batch_size (
int) – Number of raw observations to accumulate before feeding a reduced value to the wrapped algorithm. Must be positive.reducer (
BatchReducer[TypeVar(DataT),TypeVar(BatchT)]) – Function that converts a sequence of raw observations into a single value for the wrapped algorithm.
- Raises:
ValueError – If
batch_sizeis not positive.
- __init__(algorithm, *, batch_size, reducer)[source]
- Parameters:
algorithm (OnlineAlgorithm[BatchT, ConfigurationT, StateT])
batch_size (int)
reducer (BatchReducer[DataT, BatchT])
- Return type:
None
- property name: str
Return a composite name reflecting the wrapped algorithm and batch config.
- Returns:
Composite name in the form
AlgorithmName{batch[size=N, reduce=name]}.- Return type:
- property configuration: ConfigurationT
Return the wrapped algorithm’s configuration.
- Returns:
Configuration of the underlying algorithm.
- Return type:
ConfigurationT
- property state: StateT
Return the wrapped algorithm’s current state.
- Returns:
Current state of the underlying algorithm.
- Return type:
StateT
- reset()[source]
Reset the buffer, cached statistic, and underlying algorithm.
Clears the observation buffer and cached detection function, then delegates reset to the wrapped algorithm.
- Return type:
- recreate()[source]
Return a fresh instance with the same batch size and reducer.
- Returns:
A new wrapper instance sharing the same batch configuration but a freshly recreated underlying algorithm.
- Return type:
BatchingOnlineAlgorithmWrapper[TypeVar(DataT),TypeVar(BatchT),TypeVar(ConfigurationT, bound=OnlineAlgorithmConfiguration),TypeVar(StateT, bound=OnlineAlgorithmState)]