Intrusion Detection Systems (titli.ids)
The titli.ids module provides various intrusion detection system (IDS) models for anomaly detection in network traffic.
Public API Overview
All IDS models expose the following 5 public methods:
def train_model(self, train_loader: DataLoader) -> None
"""Train the model on training data."""
def save(self, model_path: Optional[str] = None) -> None
"""Save trained model to disk.
Args:
model_path: Path to save model. If None, uses default path:
./artifacts/{dataset_name}/models/{model_name}.pth
"""
def load(self, model_path: Optional[str] = None) -> dict
"""Load trained model from disk.
Args:
model_path: Path to load model from. If None, uses default path.
Returns:
Checkpoint dictionary with model state
"""
def infer(self, test_loader: DataLoader) -> Tuple[np.ndarray, np.ndarray, np.ndarray]
"""Lightweight inference without metrics computation.
Args:
test_loader: PyTorch DataLoader with test data
Returns:
Tuple of (y_true, y_pred, reconstruction_errors):
- y_true: Ground truth labels
- y_pred: Binary predictions (0=benign, 1=anomaly)
- reconstruction_errors: Anomaly scores for each sample
"""
def evaluate(self, test_loader: DataLoader) -> None
"""Full evaluation with metrics and visualization.
Computes F1, Precision, Recall, Accuracy, AUC-ROC and generates:
- Confusion matrix plot
- ROC curve plot
- Anomaly score plot
- Metrics text file
All artifacts saved to ./artifacts/{dataset_name}/
Args:
test_loader: PyTorch DataLoader with test data
"""
Available Models
Traditional ML Models
LOF (Local Outlier Factor)
OCSVM (One-Class SVM)
Deep Learning Models
Autoencoder
VAE (Variational Autoencoder)
ICL (Instance Contrastive Learning)
Ensemble Models
KitNET
Notes
All models inherit from either
BaseSKLearnModelorPyTorchModel(internal base classes)Methods prefixed with
_are internal and not part of the public APIDefault save paths:
./artifacts/{dataset_name}/models/{model_name}.pthinfer()returns:(y_true, y_pred, reconstruction_errors)as numpy arraysevaluate()generates plots and metrics files in./artifacts/