Skip to content

rolling_ae

RollingAutoencoder(module, loss_fn='mse', optimizer_fn='sgd', lr=0.001, device='cpu', seed=42, window_size=10, append_predict=False, **kwargs)

Bases: RollingDeepEstimator, AnomalyDetector

Wrapper for PyTorch autoencoder models that uses the networks reconstruction error for scoring the anomalousness of a given example. The class also features a rolling window to allow the model to make predictions based on the reconstructability of multiple previous examples.

PARAMETER DESCRIPTION
module

Torch module that builds the autoencoder to be wrapped. The module should accept inputs with shape (window_size, batch_size, n_features). It should also feature a parameter n_features used to adapt the network to the number of features in the initial training example.

TYPE: Type[Module]

loss_fn

Loss function to be used for training the wrapped model. Can be a loss function provided by torch.nn.functional or one of the following: 'mse', 'l1', 'cross_entropy', 'binary_crossentropy', 'smooth_l1', 'kl_div'.

TYPE: Union[str, Callable] DEFAULT: 'mse'

optimizer_fn

Optimizer to be used for training the wrapped model. Can be an optimizer class provided by torch.optim or one of the following: "adam", "adam_w", "sgd", "rmsprop", "lbfgs".

TYPE: Union[str, Callable] DEFAULT: 'sgd'

lr

Learning rate of the optimizer.

TYPE: float DEFAULT: 0.001

device

Device to run the wrapped model on. Can be "cpu" or "cuda".

TYPE: str DEFAULT: 'cpu'

seed

Random seed to be used for training the wrapped model.

TYPE: int DEFAULT: 42

window_size

Size of the rolling window used for storing previous examples.

TYPE: int DEFAULT: 10

append_predict

Whether to append inputs passed for prediction to the rolling window.

TYPE: bool DEFAULT: False

**kwargs

Parameters to be passed to the Module or the optimizer.

DEFAULT: {}

learn_many(X, y=None)

Performs one step of training with a batch of examples.

PARAMETER DESCRIPTION
X

Input batch of examples.

TYPE: DataFrame

y Should be None

RETURNS DESCRIPTION
RollingAutoencoder

The estimator itself.

learn_one(x, y=None, **kwargs)

Performs one step of training with a single example.

PARAMETER DESCRIPTION
x

Input example.

TYPE: dict

RETURNS DESCRIPTION
RollingAutoencoder

The estimator itself.