# nautel/rcled architecture

> Architecture diagram of the GitHub repository nautel/rcled, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nautel/rcled
- Repository: https://github.com/nautel/rcled

## Overview

##### Main Components
- Data Sources and Storage:
– Input data resides in the “data” directory with subfolders for time series data, signature matrices, and labeled anomalies.
– The use of CSV and NumPy (.npy) files indicates that raw and preprocessed data are stored locally.
- Preprocessing and Data Generation:
– Scripts such as dataset.py, generating_signature_matrix.py, and generating_syn_dataset.py indicate a stage for preparing and augmenting the time series data.
– This component reads the raw data, applies any necessary transformations (e.g., generating signature matrices from the time series), and possibly simulates synthetic data for controlled experiments.
- Model Definition and Training:
– The RCLED model is implemented in model.py, while train.py, anomaly_detection.py, and main.py serve as different entry points to training and anomaly detection.
– The loss functions (loss.py) and evaluation metrics (metrics.py) detail how model performance is measured.
- Checkpoint and Storage Management:
– The “checkpoints” directory, with its nested structure (e.g., SMAP and synthetic related folders), shows storage of trained model snapshots (*.pt files). This facilitates monitoring training progress and rollback.
- Configuration and Hyperparameters:
– The config.yaml file will contain parameters for training, such as learning rates, batch sizes, and window sizes. This centralizes tweaks to the model and training process.
- Visualization and Analysis:
– visualization.py is dedicated to plotting model performance or results, which aids in the evaluation and debugging of anomalies.

##### Relationships and Interactions
– Data Flow: Data starts in the “data” directory (raw time series, labeled anomalies) and moves into the preprocessing stage where signature matrices are generated.
– Model Pipeline: The processed data is then fed into the RCLED model (model.py) for training and detection. The main training loop (train.py) orchestrates this process.
– Evaluation and Checkpointing: During or post training, loss functions and metrics come into play, with checkpoints saved periodically. These components are interdependent.
– Control Flow: Configuration from config.yaml influences multiple stages (data loading, preprocessing, model training). The main.py file often acts as the orchestrator integrating these components.
– Post-Processing: After training, visualization.py assists in depicting results, and anomaly_detection.py might be used for inference or additional analysis.

##### Architectural Patterns and Design Principles
– Modular Design: Each major step (data preparation, model building, training, evaluation, visualization) is split into clearly defined scripts.
– Pipeline/Flow-Based Architecture: The system can be seen as a sequential data pipeline where data is ingested, transformed, modeled, evaluated, and visualized.
– Separation of Concerns: By distinguishing between data generation (including synthetic dataset generation), model training, and evaluation, the code is easier to maintain and extend.
– Robustness and Reusability: The integration of checkpoints in separate directories and modular loss/metrics functions reflect an emphasis on robust training and clear evaluation of the anomaly detection task.

##### Suggested Elements
- Clearly Labeled Components:
– Data Input (data/time_series, data/signature_matrix, data/labeled_anomalies)
– Data Preprocessing & Generation (dataset.py, generating_signature_matrix.py, generating_syn_dataset.py)
– Model Architecture (model.py implementing RCLED)
– Training & Anomaly Detection Logic (train.py, anomaly_detection.py, main.py)
– Evaluation Methods (loss.py, metrics.py)
– Checkpoint Management (checkpoints directory structure)
– Configuration Management (config.yaml)
– Results Visualization (visualization.py)
– Illustrate the flow from data acquisition through preprocessing to model training, evaluation, checkpointing, and finally result visualization.
- Visual Distinctions:

– Finally, connect the output side to Visualization (visualization.py) to show how final results are exported.
– Optionally, include an external dependency node for any acknowledgements or base code (RobustAutoencoder) indicating that your work builds upon prior foundational architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    config["Configuration (config.yaml)"]:::config
    DS["Data Sources (data/)"]:::data

    %% Data Preprocessing & Generation
    subgraph "Data Preprocessing & Generation"
        d1["dataset.py"]:::preprocess
        d2["generating_signature_matrix.py"]:::preprocess
        d3["generating_syn_dataset.py"]:::preprocess
        PD["Preprocessed Data"]:::preprocess
    end

    %% Model Pipeline (RCLED)
    subgraph "Model Pipeline (RCLED)"
        m1["model.py"]:::model
        m2["train.py"]:::model
        m3["main.py"]:::model
        m4["anomaly_detection.py"]:::model
        MC["Model Complete"]:::model
    end

    %% Evaluation Methods
    subgraph "Evaluation Methods"
        e1["loss.py"]:::eval
        e2["metrics.py"]:::eval
        EC["Evaluation Outcome"]:::eval
    end

    %% Checkpoint and Visualization
    subgraph "Checkpoint & Visualization"
        CP["Checkpoint Storage (checkpoints/)"]:::checkpoint
        viz["Visualization (visualization.py)"]:::visualization
    end

    %% Connections
    config -->|"config_dependency"| d1
    config -->|"config_dependency"| m1
    DS -->|"data_flow"| PD
    d1 -->|"preprocess"| PD
    d2 -->|"preprocess"| PD
    d3 -->|"preprocess"| PD
    PD -->|"processed_data"| m1
    m1 -->|"forward"| m2
    m2 -->|"forward"| m3
    m3 -->|"forward"| m4
    m4 -->|"complete"| MC
    MC -->|"evaluated_by"| e1
    e1 -->|"metrics"| e2
    e2 -->|"outcome"| EC
    MC -->|"checkpoint_saved"| CP
    CP -->|"visualized"| viz
    EC -->|"visualized"| viz

    %% Click Events
    click config "https://github.com/nautel/rcled/blob/master/config.yaml"
    click DS "https://github.com/nautel/rcled/tree/master/data/"
    click d1 "https://github.com/nautel/rcled/blob/master/dataset.py"
    click d2 "https://github.com/nautel/rcled/blob/master/generating_signature_matrix.py"
    click d3 "https://github.com/nautel/rcled/blob/master/generating_syn_dataset.py"
    click m1 "https://github.com/nautel/rcled/blob/master/model.py"
    click m2 "https://github.com/nautel/rcled/blob/master/train.py"
    click m3 "https://github.com/nautel/rcled/blob/master/main.py"
    click m4 "https://github.com/nautel/rcled/blob/master/anomaly_detection.py"
    click e1 "https://github.com/nautel/rcled/blob/master/loss.py"
    click e2 "https://github.com/nautel/rcled/blob/master/metrics.py"
    click CP "https://github.com/nautel/rcled/tree/master/checkpoints/"
    click viz "https://github.com/nautel/rcled/blob/master/visualization.py"

    %% Styles
    classDef config fill:#D1C4E9,stroke:#4A148C,stroke-width:2px;
    classDef data fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef preprocess fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef model fill:#FFCCBC,stroke:#E64A19,stroke-width:2px;
    classDef eval fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef checkpoint fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef visualization fill:#F8BBD0,stroke:#AD1457,stroke-width:2px;
```
