RADAR.time_series.algorithms

Subpackages

Submodules

RADAR.time_series.algorithms.transformers module

class RADAR.time_series.algorithms.transformers.TransformersAnomalyDetection(**kwargs)[source]

Bases: BaseAnomalyDetection

decision_function(X)[source]

Calculates anomaly scores as reconstruction MSE per sample.

evaluate(X, y=None, threshold=None)[source]

Evaluates the model on data X (and optionally y). If no threshold is provided, it is calculated as mean + 3 * std.

fit(X, y=None)[source]

Train Transformer model. X is the input sequence. If y is provided, it is used as target

get_default_params(**params)[source]

Get DEFAULT parameters for this estimator, params is used to configure positional parameters in order to obtain default parameters of the object.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

get_params(**kwargs)[source]

Get parameters for this estimator.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

predict(X)[source]

Predicts outputs for input data X

classmethod register_algorithm(name, model_class)[source]

Register a new algorithm in the class. :param - name: The name of the new algorithm. :type - name: str :param - model_class: The class implementing the anomaly detection model. :type - model_class: class

The class should have:
  • An __init__ method that accepts model-specific parameters.

  • A fit(X, y) method to train the model.

  • A predict(X) method to make predictions.

  • Optionally, a decision_function(X) for scoring anomalies.

score_to_label_fn(scores)[source]
set_params(**params)[source]

Set the parameters of this estimator. :returns: self :rtype: object

RADAR.time_series.algorithms.tsfedl module

class RADAR.time_series.algorithms.tsfedl.TsfedlAnomalyDetection(batch_size=16, **kwargs)[source]

Bases: BaseAnomalyDetection

Base module for any pyTorch Lightning based algorithm in TSFEDL library

Parameters:
decision_function(X)[source]

Compute the reconstruction error of X using the trained model. This can be interpreted as a performance score of the prediction.

Parameters:

X (numpy array of shape (n_samples, seq_len, n_features)) – Input data.

Returns:

scores – Reconstruction error per sample.

Return type:

numpy array of shape (n_samples,)

evaluate(X, y=None, threshold=None)[source]

Evaluate the model using decision_function (scores) and predict (outputs).

Parameters:
  • X (numpy array or pandas DataFrame) – Input sequences.

  • y (numpy array or pandas DataFrame, optional) – Ground-truth values (for metrics).

  • threshold (float, optional) – Threshold to convert scores into binary labels. If None, it is computed as mean + 3 * std.

Returns:

results

Dictionary containing:
  • ”scores”: anomaly/forecasting scores.

  • ”labels_preds”: predicted labels (if thresholding is applied).

  • ”preds”: model predictions.

  • ”labels_true”: ground-truth labels (if provided).

Return type:

dict

fit(X, y=None)[source]

Fit detector. y is ignored in unsupervised methods.

Parameters:
  • X (numpy array of shape (n_samples, n_features)) – The input samples.

  • y (Ignored) – Not used, present for API consistency by convention.

Returns:

self – Fitted estimator.

Return type:

object

get_default_params(**params)[source]

Get DEFAULT parameters for this estimator, params is used to configure positional parameters in order to obtain default parameters of the object.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

get_params()[source]

Get parameters for this estimator.

Returns:

params – Parameter names mapped to their values.

Return type:

mapping of string to any

predict(X, threshold=None)[source]

Predict anomaly labels (0 = normal, 1 = anomaly).

Parameters:
  • X (array-like) – Input sequences.

  • threshold (float, optional) – Threshold for classification. If None, uses mean + 3*std.

Returns:

y_pred – Binary anomaly labels.

Return type:

numpy array of shape (n_samples,)

set_params(**params)[source]

Set the parameters of this estimator. :returns: self :rtype: object

Module contents