How netmanaiops/donut works
Project Type and Purpose
• Donut is a Python library for anomaly detection in seasonal KPIs using a variational autoencoder (VAE) based approach.
• It provides modules for data preprocessing, model construction, training, prediction, and missing data reconstruction.
• The README shows example API usage, citation details, and guidance on installation and integration with TensorFlow, TFSnippet, and ZhuSuan.
File Structure
• Top-level files like .travis.yml, .gitignore, requirements*, and setup.py suggest standard package management, CI/CD integration, and testing.
• The “donut” directory holds the core modules:
– __init__.py: Package initialization.
– preprocessing.py & augmentation.py: Likely handle raw data transformations, timestamp completion, and augmentation.
– model.py: Defines the core VAE model structure.
– training.py: Contains logic to train the model (wrapped by DonutTrainer).
– prediction.py: Implements inference using DonutPredictor.
– reconstruction.py: Manages enhanced reconstruction (e.g., MCMC-based missing data imputation).
– utils.py: Utility functions used across the package.
• The “tests” directory mirrors the core modules to validate functionality.
• “sample_data” provides example CSV datasets to illustrate file format and usage.
Key Architecture Components/Blocks
a. Data Preparation Layer:
– Components: Preprocessing (donut/preprocessing.py) and Augmentation (donut/augmentation.py)
– Role: Completing timestamps, standardizing KPIs, and handling missing data
b. Model Core:
– Component: Model definition (donut/model.py)
– Role: Building the VAE architecture using TensorFlow and Keras layers (as seen in the API usage in the README)
c. Training Module:
– Component: Training logic in donut/training.py wrapped by a DonutTrainer class
– Role: Handling model training workflows, loss computations, and optimization
d. Prediction / Inference Module:
– Component: Prediction logic in donut/prediction.py, organized as DonutPredictor
– Role: Generating anomaly scores on new data
e. Reconstruction and Missing Data Imputation:
– Component: Reconstruction in donut/reconstruction.py
– Role: Incorporating MCMC iterative reconstruction approaches for missing data correction
f. Utility Functions:
– Component: donut/utils.py
– Role: Supporting common tasks across modules such as variable management and session handling
Relationships and Interactions
• Data flows from raw input through preprocessing/augmention to the model core.
• The model is constructed in a modular way where the encoder (built with Keras Dense layers) and the decoder are set up for VAE processes.
• Training and prediction modules directly wrap around the model core, managing sessions and TensorFlow variable scopes.
• The reconstruction module interfaces with both the model and utilities to provide advanced outputs (like MCMC-based reconstruction).
• External services include TensorFlow, TFSnippet, and ZhuSuan, which are critical dependencies influencing how the model is structured and executed.
Architectural Design Patterns and Principles
• A modular design: Separates concerns between data preparation, model definition, training, prediction, and post-processing.
• Dependency injection: The design makes it possible to plug in different neural network architectures (as seen in the API where h_for_p_x and h_for_q_z are defined).
• Clear separation of training vs. inference logic, which is reflected in both file and function organization.