apache_beam.ml.anomaly.univariate.median module
Trackers for calculating median in windowed fashion.
- class apache_beam.ml.anomaly.univariate.median.MedianTracker(*args, **kwargs)[source]
 Bases:
BaseTrackerTracks the median of a stream of values using a quantile tracker.
This wrapper class encapsulates a QuantileTracker configured specifically for the 0.5 quantile (median).
- Parameters:
 quantile_tracker – An optional QuantileTracker instance. If not provided, a BufferedSlidingQuantileTracker with a default window size 1000 and q=0.5 is created.
- Raises:
 AssertionError – If the provided quantile_tracker is not initialized with q=0.5.
- push(x)[source]
 Pushes a new value and updates the internal quantile tracker.
- Parameters:
 x – The new value to be pushed.
- get()[source]
 Calculates and returns the median (q = 0.5).
- Returns:
 - The median of the values in the window setting specified in the
 internal quantile tracker. Returns NaN if the window is empty.
- Return type:
 
- MedianTracker__spec_type = 'MedianTracker'
 
- classmethod from_spec(spec: Spec, _run_init: bool = True) Self | type[Self]
 Generate a Specifiable subclass object based on a spec.
- Parameters:
 spec – the specification of a Specifiable subclass object
_run_init – whether to call __init__ or not for the initial instantiation
- Returns:
 the Specifiable subclass object
- Return type:
 Self
- run_original_init() None
 Execute the original __init__ method with its saved arguments.
For instances of the Specifiable class, initialization is deferred (lazy initialization). This function forces the execution of the original __init__ method using the arguments captured during the object’s initial instantiation.
- classmethod spec_type()
 
- to_spec() Spec
 Generate a spec from a Specifiable subclass object.
- Returns:
 The specification of the instance.
- Return type:
 
- classmethod unspecifiable()