Env
polars_ts.anomaly_agents.env
Anomaly detection environment for RL-based adaptive thresholding.
AnomalyEnv
Gymnasium-like environment for anomaly detection.
At each step, the agent observes a window of recent values and decides whether the current point is anomalous. If ground-truth labels are provided, rewards reflect detection accuracy.
Parameters
data 1D array of time series values. window_size Number of recent observations in each observation. labels Optional ground-truth boolean array (True = anomaly). When provided, correct detections get positive reward and false alarms negative. Without labels, reward is based on statistical deviation.
reset()
Reset and return initial observation.
step(action)
Take one step.
Parameters
action True to flag the current point as anomalous.
Returns
tuple
(observation, reward, done, info)
_get_obs()
Build observation: window of recent values.