Base API¶
The abstract base classes support inheritance; the runtime-checkable protocols support structural pipeline components without inheritance.
BaseModel ¶
Bases: ABC
Abstract base class for online anomaly detection models.
Online models process one observation at a time. score_one evaluates an
observation against the model's current reference state; learn_one
incorporates an observation into that state.
Subclasses must implement learn_one and score_one. Score ranges,
warm-up behavior, and score orientation are model-specific.
learn_one
abstractmethod
¶
Update the model with a single data point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
dict[str, float]
|
A dictionary representing a single data point. The keys are feature names, and the values are the corresponding feature values. |
required |
score_one
abstractmethod
¶
Compute the anomaly score for a single data point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
dict[str, float]
|
A dictionary representing a single data point. The keys are feature names, and the values are the corresponding feature values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The model-specific anomaly score for the data point. Consult the |
float
|
concrete model for its range and orientation. |
BaseTransformer ¶
Bases: ABC
Abstract base class for online transformers.
Transformers learn and transform one feature mapping at a time. A standalone
transformer does not prescribe whether learning happens before or after
transformation; :class:~aberrant.base.pipeline.Pipeline deliberately uses
post-update transformations during learn_one.
Subclasses must implement the learn_one and transform_one methods.
learn_one
abstractmethod
¶
Update the transformer with a single data point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
dict[str, float]
|
A dictionary representing a single data point. The keys are feature names, and the values are the corresponding feature values. |
required |
transform_one
abstractmethod
¶
Transform a single data point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
dict[str, float]
|
A dictionary representing a single data point to transform. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A dictionary with transformed feature values. |
BaseSimilaritySearchEngine ¶
Bases: ABC
Abstract base class for similarity search engines.
This class defines the interface for engines that store observations and reduce a nearest-neighbor query to one scalar. The interface does not impose whether that scalar is a distance, dissimilarity, or similarity; callers must follow the concrete engine's contract.
Subclasses must implement the append and search methods.
append
abstractmethod
¶
Add a data point to the search engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
dict[str, float]
|
A dictionary representing a single data point. The keys are feature names, and the values are the corresponding feature values. |
required |
search
abstractmethod
¶
Search for the n nearest neighbors of a data point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
dict[str, float]
|
A dictionary representing the query data point. |
required |
n_neighbors
|
int
|
The number of nearest neighbors to find. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The engine-specific scalar summary of the nearest-neighbor query. |
Pipeline ¶
Chain transformers with a transformer or model terminal.
Construction returns a :class:TransformerPipeline or :class:ModelPipeline
exposing only the terminal's capability. Learning uses post-update
transformations; transformation and scoring never invoke learning methods.
Nested pipelines are flattened into one prefix and terminal.
first
property
¶
first: TransformerProtocol
Return the transformer prefix as a composable component.
ends_in_transformer
property
¶
Whether this pipeline can transform output and accept another stage.
learn_one ¶
learn_one(x: FeatureMap) -> None
Learn from one sample using each prefix transformer's updated state.
TransformerPipeline ¶
Bases: Pipeline
A composable pipeline exposing transformed features.
stages
property
¶
stages: tuple[TransformerProtocol, ...]
All transformer stages in execution order.
transform_one ¶
transform_one(x: FeatureMap) -> FeatureMap
Apply the learned transformer stages without calling learn_one.
ModelPipeline ¶
Bases: Pipeline
A terminal pipeline exposing anomaly scores.
score_one ¶
score_one(x: FeatureMap) -> float
Transform and score an event without calling any stage's learn_one.
LearnerProtocol ¶
Bases: Protocol
A component that updates itself from one feature mapping.
TransformerProtocol ¶
Bases: LearnerProtocol, Protocol
Structural interface accepted for transformer pipeline stages.
transform_one ¶
transform_one(x: FeatureMap) -> FeatureMap
Transform one sample without updating learned state.
TransactionalLearnerProtocol ¶
Bases: LearnerProtocol, Protocol
A learner that can restore its state when a learning pass fails.
The context remains open through downstream learning. Implementations must restore their own state when the context raises; the pipeline cannot make nontransactional components atomic.
learning_transaction ¶
learning_transaction(x: FeatureMap) -> AbstractContextManager[None]
Keep updates on success and restore prior state when the context raises.
TransactionalTransformerProtocol ¶
Bases: TransformerProtocol, TransactionalLearnerProtocol, Protocol
A transformer with the transactional learner capability.
ModelProtocol ¶
Bases: LearnerProtocol, Protocol
Structural interface accepted for a terminal anomaly model.
score_one ¶
score_one(x: FeatureMap) -> float
Score one sample without updating learned state.
Readiness
dataclass
¶
Whether a component has a usable learned reference, not score validity.
observed and required describe the same history unit. Readiness does
not guarantee that every possible candidate satisfies the input domain.
ReadinessProtocol ¶
Exceptions¶
AberrantError ¶
Bases: Exception
Base exception class for all aberrant-specific errors.
ModelNotFittedError ¶
TransformationError ¶
Bases: AberrantError
Raised when a transformation operation fails.
PipelineError ¶
Bases: AberrantError
Raised when a pipeline operation fails.
ValidationError ¶
Bases: AberrantError
Raised when input validation fails.
ConfigurationError ¶
ConfigurationError(message: str = '', *, issues: Sequence[ConfigurationIssue] = ())
Bases: AberrantError
Raised when declarative component configuration is invalid.
issues
property
¶
issues: tuple[ConfigurationIssue, ...]
Immutable diagnostics, independent of the human-readable message.
ConfigurationIssue
dataclass
¶
One configuration failure at a path relative to the submitted value.
Codes are missing_parameter, unexpected_parameter, invalid_type,
invalid_value, unknown_component, missing_dependency and
invalid_configuration. Locations contain object keys and array indexes.
UnknownComponentError ¶
MissingOptionalDependencyError ¶
UnsupportedFeatureError ¶
IncompatibleComponentError ¶
Optional PyTorch architecture base¶
The following object requires aberrant[dl] at runtime and is intentionally
absent from from aberrant.base import *.
Architecture ¶
Bases: ABC, Module
Abstract base class for defining neural network architectures.
This class ensures that any neural network architecture can be plugged into online anomaly detection models. It provides a consistent interface and device handling capabilities.
Subclasses must implement the forward and input_size methods.
Initialize the architecture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device | None
|
The device to run the model on. If None, uses CPU. |
None
|
input_size
abstractmethod
property
¶
The expected input size for the network.
Returns:
| Type | Description |
|---|---|
int
|
Number of input features. |
forward
abstractmethod
¶
Forward pass through the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Output tensor. |
make_torch_generator
staticmethod
¶
Create an independently seeded, model-owned generator.