Skip to contents

Flags rows whose squared reconstruction error exceeds threshold; with no threshold the empirical quantile of the errors is used, which calibrates the detector on the data being scored.

Usage

morie_geron_anomaly_autoencoder(model, X, threshold = NULL, quantile = 0.99)

Arguments

model

Function(X) -> reconstruction, or a list with reconstruct, predict, or encode + decode.

X

Data to score.

threshold

Optional squared-error cut.

quantile

Quantile in (0, 1] used when threshold is NULL.

Value

List with errors, is_anomaly, threshold, threshold_calibrated, n_anomalies, reconstruction.

Examples

zero <- function(A) matrix(0, nrow(as.matrix(A)), ncol(as.matrix(A)))
morie_geron_anomaly_autoencoder(zero, matrix(c(0, 3, 1, 5), ncol = 1),
    quantile = 0.6)
#> $errors
#> [1]  0  9  1 25
#> 
#> $is_anomaly
#> [1] FALSE  TRUE FALSE  TRUE
#> 
#> $threshold
#> [1] 7.4
#> 
#> $threshold_calibrated
#> [1] TRUE
#> 
#> $n_anomalies
#> [1] 2
#> 
#> $reconstruction
#>      [,1]
#> [1,]    0
#> [2,]    0
#> [3,]    0
#> [4,]    0
#> 
#> $estimate
#> [1] 8.75
#> 
#> $n
#> [1] 4
#> 
#> $method
#> [1] "Autoencoder anomaly detection by squared reconstruction error"
#>