Skip to contents

Fits a rank-k linear bottleneck by gradient descent with re-orthonormalisation, and scores each row by its squared reconstruction error.

Usage

morie_autoencoder_anomaly(
  X,
  k = 2,
  n_iter = 300,
  lr = 0.05,
  seed = 0,
  contamination = 0.05
)

Arguments

X

data matrix.

k

bottleneck rank.

n_iter, lr

gradient-descent controls.

seed

integer seed.

contamination

expected anomaly fraction, used for the threshold.

Value

list with score, rank (0-based), anomaly, reconstruction, threshold, explained_fraction.

Details

In the linear case this IS PCA reconstruction error – the optimum spans the leading k principal directions – which is worth knowing before reaching for a deep autoencoder that may be doing the same thing more slowly.

The anomalies are in the TRAINING data, so more bottleneck capacity makes detection worse rather than better: at k = d the reconstruction is exact and every error is zero. Keep k well below the intrinsic dimension.

References

Hawkins, S. et al. (2002). Outlier detection using replicator neural networks. DaWaK, 170-180.

Examples

set.seed(1)
X <- matrix(rnorm(300), ncol = 3); X[7, ] <- c(9, -9, 9)
which.max(morie_autoencoder_anomaly(X, k = 1)$score)
#> [1] 6