MODULE REFERENCE

generic

anomx.models.generic

Adapters for user supplied estimators, functions, and PyTorch modules.

GenericModel

GenericModel(model: Any, *, family: str = 'predictive', fit_fn: Callable | None = None, predict_fn: Callable | None = None, epochs: int = 20, batch_size: int = 32, learning_rate: float = 0.001, loss_fn: Callable | None = None, optimizer_factory: Callable | None = None, device: str = 'cpu', random_state: int = 42)

Bases: NormalityModel

Adapt an estimator, callable, or torch.nn.Module to Anomx.

fit_fn(model, x, y) and predict_fn(model, x) explicitly override the underlying implementation. Estimators otherwise use their fit and predict methods; callable models support inference without fitting. The observation axis is always first. Prediction must preserve its length, while the remaining axes may change (for example for embeddings).

PyTorch modules receive float32 inputs and train with Adam/MSE unless an optimizer factory or loss function is provided. Classification uses integer class targets and cross-entropy; prediction returns class logits. Reconstruction models may omit targets; other families require them. No scaling, window creation, or forecast alignment is implicit. Use TorchForecastingModel for sliding-window forecasting. Torch remains an optional dependency.

Parameters

model

Estimator, callable, or torch module owned by this adapter.

family

predictive, forecasting, reconstruction, representation, or classification. Describes purpose without restricting tensor axes.

epochs, batch_size, learning_rate

Positive PyTorch training settings; ignored by estimator backends.

Signature parameters
ParameterTypeDefault
modelAnyrequired
familykeyword onlystr'predictive'
fit_fnkeyword onlyCallable | NoneNone
predict_fnkeyword onlyCallable | NoneNone
epochskeyword onlyint20
batch_sizekeyword onlyint32
learning_ratekeyword onlyfloat0.001
loss_fnkeyword onlyCallable | NoneNone
optimizer_factorykeyword onlyCallable | NoneNone
devicekeyword onlystr'cpu'
random_statekeyword onlyint42

Members

component_typeattribute
component_keyattribute
component_key = 'generic_model'
component_nameattribute
component_name = 'Generic Model'
component_discoverableattribute
is_torchproperty
is_torch: bool

Whether the wrapped object inherits from torch.nn.Module.

Returns bool

fitmethod
fit(data: Any, target: Any = None, *, verbose: bool = False) -> GenericModel

Fit only the supplied observations; record PyTorch epoch losses.

Signature parameters
ParameterTypeDefault
dataAnyrequired
targetAnyNone
verbosekeyword onlyboolFalse

Returns GenericModel

predictmethod
predict(data: Any) -> Any

Predict while retaining a DataFrame index or TimeSeries coordinates.

Signature parameters
ParameterTypeDefault
dataAnyrequired

Returns Any

savemethod
save(path: str) -> None

Serialize this adapter; only load trusted pickle files.

Signature parameters
ParameterTypeDefault
pathstrrequired

Returns None

loadmethod
load(path: str) -> GenericModel

Replace adapter state from a trusted file written by save.

Signature parameters
ParameterTypeDefault
pathstrrequired

Returns GenericModel