How amitroy7781/gad-nr works
Project Type and Purpose
• This is a research‐oriented Python implementation (via Jupyter notebooks) of the GAD-NR algorithm for graph anomaly detection. It is not a full‐stack web service but an experimental ML pipeline: data ingestion, model definition (encoder + decoder), training (loss computation), and evaluation benchmarks.
File Structure Analysis
• Top‐level files only:
• Benchmarking.ipynb – notebook to run experimental comparisons.
• GAD-NR.ipynb – notebook implementing the GAD-NR model end to end (data loading, training, evaluation).
• requirements.txt – Python dependencies.
• README.md – project description, architecture, usage, experimental results.
Key Insights from README
• Core model architecture:
• Encoder = Feature‐wise MLP → GNN message passing → node embeddings
• Decoder splits into three branches:
a. MLP for self‐feature reconstruction (MSE loss)
b. MLP for degree reconstruction (MSE loss)
c. MLP estimating Gaussian neighbor‐feature distribution (KL divergence)
• Data handling: sampling fixed-size neighbor sets per node.
• Evaluation: ROC AUC over structural, contextual, and joint anomaly types.
a. Main Components
• Data Ingestion Module
– Input: graph dataset (nodes + features + adjacency)
– Outliers generator (contextual & structural)
• Preprocessing & Sampling
– Neighbor sampler (sample_size parameter)
– Data loader constructs mini‐batches of (node, neighbors)
• Model (GAD-NR)
– Encoder block
· Feature MLP
· GNN layer (e.g., GCN)
– Decoder block (three parallel heads)
· Self‐feature MLP → ŷ_feature
· Degree MLP → ŷ_degree
· Gaussian MLP → μ, σ for neighbor features
• Loss & Optimization
– MSE(self‐feature) + MSE(degree) + KL(neighbor) weighted by λ’s
– Optimizer (e.g., Adam)
– Learning‐rate scheduler (if any)
• Evaluation & Benchmarking
– Compute anomaly scores
– ROC AUC, comparison plots (in Benchmarking.ipynb)
b. Relationships & Data Flow
1. Raw graph → Preprocessing
2. Preprocessed batches → Encoder → Latent embeddings
3. Embeddings → Decoder heads → Reconstructions / Distributions
4. Reconstructions + Ground truth → Loss computation
5. Gradients → Optimizer → Model update
6. Trained model → Evaluation module → Metrics/Plots
c. Architectural Patterns & Design Principles
• Modular separation: Data pipeline, model definition, training loop, evaluation
• Multi‐task learning: three reconstruction objectives combined
• Graph Neural Network pattern: encoder–decoder architecture
• Notebook orchestration: experiments as sequential cells rather than a packaged service
d. Key Technologies & Libraries
• PyTorch (+ torch‐geometric) for GNN layers
• Numpy/pandas for data handling
• Matplotlib/seaborn for result plots
• Jupyter notebooks as the entrypoint for experiments