rolling_ae
¶
Classes:
Name | Description |
---|---|
RollingAutoencoder |
Rolling window autoencoder for streaming anomaly detection. |
RollingAutoencoder
¶
RollingAutoencoder(
module: Module,
loss_fn: Union[str, Callable] = "mse",
optimizer_fn: Union[str, Callable] = "sgd",
lr: float = 0.001,
device: str = "cpu",
seed: int = 42,
window_size: int = 10,
append_predict: bool = False,
**kwargs
)
Bases: RollingDeepEstimator
, AnomalyDetector
Rolling window autoencoder for streaming anomaly detection.
Maintains a fixed-size deque of the latest window_size
observations and
feeds them as a sequence tensor to the wrapped autoencoder module. The
anomaly score is the reconstruction error for the current (or most recent)
window. This design allows sequence context without retaining the full
historical stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
Module
|
Autoencoder (or encoder-only) style module operating on a rolling tensor. |
required |
loss_fn
|
str | Callable
|
Loss for reconstruction error measurement. |
'mse'
|
optimizer_fn
|
str | Callable
|
Optimizer specification. |
'sgd'
|
lr
|
float
|
Learning rate. |
1e-3
|
device
|
str
|
Torch device. |
'cpu'
|
seed
|
int
|
Random seed. |
42
|
window_size
|
int
|
Number of past samples retained. |
10
|
append_predict
|
bool
|
If True, the scored sample (during prediction) is appended to the window. |
False
|
**kwargs
|
Forwarded to :class: |
{}
|
Notes
The provided module should expect input shape roughly (seq_len, batch=1, n_features)
which is what :func:deque2rolling_tensor
produces.
Methods:
Name | Description |
---|---|
clone |
Return a fresh estimator instance with (optionally) copied state. |
draw |
Render a (partial) computational graph of the wrapped model. |
learn_many |
Batch update; extends window with rows from X and learns if full. |
learn_one |
Update model using a single sample appended to the rolling window. |
load |
Load a previously saved estimator. |
save |
Persist the estimator (architecture, weights, optimiser & runtime state). |
score_many |
Return list of reconstruction errors for each row in X. |
score_one |
Return reconstruction error for current window + candidate sample. |
Source code in deep_river/anomaly/rolling_ae.py
clone
¶
Return a fresh estimator instance with (optionally) copied state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_params
|
dict | None
|
Parameter overrides for the cloned instance. |
None
|
include_attributes
|
bool
|
If True, runtime state (observed features, buffers) is also copied. |
False
|
copy_weights
|
bool
|
If True, model weights are copied (otherwise the module is re‑initialised). |
False
|
Source code in deep_river/base.py
draw
¶
Render a (partial) computational graph of the wrapped model.
Imports graphviz
and torchviz
lazily. Raises an informative
ImportError if the optional dependencies are not installed.
Source code in deep_river/base.py
learn_many
¶
Batch update; extends window with rows from X and learns if full.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
DataFrame containing the input features for each sample. |
required |
y
|
None
|
Ignored, present for compatibility. |
None
|
Source code in deep_river/anomaly/rolling_ae.py
learn_one
¶
Update model using a single sample appended to the rolling window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Dictionary containing feature name-value pairs for the sample. |
required |
y
|
Any
|
Target value (not used in autoencoder training). |
None
|
**kwargs
|
Additional keyword arguments. |
{}
|
Source code in deep_river/anomaly/rolling_ae.py
load
classmethod
¶
Load a previously saved estimator.
The method reconstructs the estimator class, its wrapped module, optimiser state and runtime information (feature names, buffers, etc.).
Source code in deep_river/base.py
save
¶
Persist the estimator (architecture, weights, optimiser & runtime state).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str | Path
|
Destination file. Parent directories are created automatically. |
required |
Source code in deep_river/base.py
score_many
¶
Return list of reconstruction errors for each row in X.
If the window is not yet full, zeros are returned for alignment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
DataFrame containing the input features for each sample. |
required |
Returns:
Type | Description |
---|---|
List[float]
|
List of computed anomaly scores (reconstruction errors) for each sample in X. |
Source code in deep_river/anomaly/rolling_ae.py
score_one
¶
Return reconstruction error for current window + candidate sample.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Dictionary containing feature name-value pairs for the candidate sample. |
required |
Returns:
Type | Description |
---|---|
float
|
Computed anomaly score (reconstruction error). |