protocol

# `anomaly_detector_protocol`

Protocol for machine learning anomaly detectors.

Availability:
`logtalk_load(anomaly_detection_protocols(loader))`
Author: Paulo Moura
Version: 1:0:0
Date: 2026-05-06
Compilation flags:
`static`
Dependencies:
(none)
Remarks:
(none)
Inherited public predicates:
(none)

## Public predicates

### `learn/2`

Learns an anomaly detector from the given dataset object.

Compilation flags:
`static`
Template:
`learn(Dataset,AnomalyDetector)`
Mode and number of proofs:
`learn(+object_identifier,-compound)` - `one`

### `learn/3`

Learns an anomaly detector from the given dataset object using the specified options.

Compilation flags:
`static`
Template:
`learn(Dataset,AnomalyDetector,Options)`
Mode and number of proofs:
`learn(+object_identifier,-compound,+list(compound))` - `one`

### `check_anomaly_detector/1`

Checks that a learned anomaly detector term is structurally valid for the receiving implementation. Throws an exception when the term is not a valid anomaly detector representation.

Compilation flags:
`static`
Template:
`check_anomaly_detector(AnomalyDetector)`
Mode and number of proofs:
`check_anomaly_detector(@compound)` - `one_or_error`
Exceptions:
`AnomalyDetector` is a variable:
`instantiation_error`
`AnomalyDetector` is neither a variable nor a valid anomaly detector:
`domain_error(anomaly_detector,AnomalyDetector)`

### `valid_anomaly_detector/1`

True when a learned anomaly detector term is structurally valid for the receiving implementation. Succeeds iff `check_anomaly_detector/1` succeeds without throwing an exception.

Compilation flags:
`static`
Template:
`valid_anomaly_detector(AnomalyDetector)`
Mode and number of proofs:
`valid_anomaly_detector(@compound)` - `zero_or_one`

### `diagnostics/2`

Returns diagnostics and metadata associated with a learned anomaly detector in a representation-independent way.

Compilation flags:
`static`
Template:
`diagnostics(AnomalyDetector,Diagnostics)`
Mode and number of proofs:
`diagnostics(+compound,-list(compound))` - `one`

### `diagnostic/2`

Tests or enumerates individual diagnostics metadata terms for a learned anomaly detector.

Compilation flags:
`static`
Template:
`diagnostic(AnomalyDetector,Diagnostic)`
Mode and number of proofs:
`diagnostic(+compound,?compound)` - `zero_or_more`

### `anomaly_detector_options/2`

Returns the effective training options recorded in a learned anomaly detector.

Compilation flags:
`static`
Template:
`anomaly_detector_options(AnomalyDetector,Options)`
Mode and number of proofs:
`anomaly_detector_options(+compound,-list(compound))` - `one`

### `predict/3`

Predicts whether a new instance is `normal` or `anomaly` using the learned detector. The instance is a list of `Attribute-Value` pairs.

Compilation flags:
`static`
Template:
`predict(AnomalyDetector,Instance,Prediction)`
Mode and number of proofs:
`predict(+compound,+list,-atom)` - `one`

### `predict/4`

Predicts whether a new instance is `normal` or `anomaly` using the learned detector and the specified options. The instance is a list of `Attribute-Value` pairs.

Compilation flags:
`static`
Template:
`predict(AnomalyDetector,Instance,Prediction,Options)`
Mode and number of proofs:
`predict(+compound,+list,-atom,+list(compound))` - `one`

### `score/3`

Computes an anomaly score in the interval `[0.0, 1.0]` for a new instance. Larger scores indicate more anomalous instances.

Compilation flags:
`static`
Template:
`score(AnomalyDetector,Instance,Score)`
Mode and number of proofs:
`score(+compound,+list,-float)` - `one`

### `score_all/3`

Computes anomaly scores for all examples in a dataset and returns a list of `Id-Class-Score` triples sorted by descending score.

Compilation flags:
`static`
Template:
`score_all(Dataset,AnomalyDetector,Scores)`
Mode and number of proofs:
`score_all(+object_identifier,+compound,-list)` - `one`

### `export_to_clauses/4`

Converts an anomaly detector into a list of predicate clauses. `Functor` is the functor for the generated predicate clauses. When exporting a serialized detector term, a noun such as `detector` or `model` is usually clearer than a verb such as `detect`.

Compilation flags:
`static`
Template:
`export_to_clauses(Dataset,AnomalyDetector,Functor,Clauses)`
Mode and number of proofs:
`export_to_clauses(+object_identifier,+compound,+callable,-list(clause))` - `one`

### `export_to_file/4`

Exports an anomaly detector to a file. `Functor` is the functor for the generated predicate clauses. When exporting a serialized detector term, a noun such as `detector` or `model` is usually clearer than a verb such as `detect`.

Compilation flags:
`static`
Template:
`export_to_file(Dataset,AnomalyDetector,Functor,File)`
Mode and number of proofs:
`export_to_file(+object_identifier,+compound,+callable,+atom)` - `one`

### `print_anomaly_detector/1`

Prints an anomaly detector to the current output stream in a human-readable format.

Compilation flags:
`static`
Template:
`print_anomaly_detector(AnomalyDetector)`
Mode and number of proofs:
`print_anomaly_detector(+compound)` - `one`

## Protected predicates

(none)

## Private predicates

(none)

## Operators

(none)

See also

anomaly_dataset_protocol, anomaly_detector_common, isolation_forest_anomaly_detector, knn_distance_anomaly_detector, lof_anomaly_detector