# rock-feller/hcnns_and_chaos architecture

> Architecture diagram of the GitHub repository rock-feller/hcnns_and_chaos, 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/rock-feller/hcnns_and_chaos
- Repository: https://github.com/rock-feller/hcnns_and_chaos

## Overview

##### Project Type and Purpose
- This is a research-oriented deep learning project focusing on modeling chaotic and climate (partially observable) systems.
- It implements custom HCNN and RNN modules from scratch in PyTorch, including specialized data handling, preprocessing, training strategies, and result management.
- The purpose is to provide a systematic experimental setup for advanced neural network architectures, with support for long-memory improvements and hardware acceleration (CUDA and Apple MPS).

##### Analyzing the File Structure
- Top-level directories include base implementations (HCNN, LSTM, RNN), distinct modeling frameworks (HCNNs_Chaos, RNNs_Chaos, HCNNs_Climate, RNNs_Climate), and utility/data folders (chaotic_data, data).
- Each modeling framework (for both chaos and climate) follows a similar structure featuring:
- A data section (or data_prep) that handles preparation, transformation, and normalization.
- A modules section (hcnn_modules / models) where the core network cells and architectures are defined.
- A modeling_strategy folder that encapsulates custom training functions and experimental strategies.
- The repo also includes test modules (under test/) and supplementary notebooks for simulations and visualizations.
- Configuration files and a clear separation of functionality indicate a modular, layered approach.

##### Key Components to Capture
a. Data Layer:
- Raw data sources and datasets (organized under the “data” folder, e.g., “climate_data” and “sunhours_data”).
- Specialized data processing modules (e.g., data_prep directories within HCNNs_Chaos, RNNs_Chaos, HCNNs_Climate, and RNNs_Climate; also “climate_wizard” for additional processing).
b. Model Definition Layer:
- Core network architecture modules found in HCNN, LSTM, RNN folders.
- Specialized implementations in the “hcnn_modules” and (for RNNs) in “models” directories.
c. Training/Modeling Strategy Layer:
- Custom training functions and strategies for chaotic systems (in the modeling_strategy folders under HCNNs_Chaos and RNNs_Chaos) and climate systems (in the corresponding HCNNs_Climate and RNNs_Climate directories).
d. Execution and Evaluation:
- Simulation scripts (simulation_instance_HCNNs.py, simulation_instance_RNNs.py, and notebooks in RNNs_Chaos) that drive experiments.
- Output handling components (described in the README’s “Training and Results Management” section, where outputs are organized into JSON metrics, CSV forecast files, and serialized state_dicts).
e. Testing and Visualization:
- Testing components (located in the “test” directory) to validate architectural properties.
- Visualization modules (found in HCNN/visualization.py, LSTM/visualization.py, RNN/visualization.py, and notebooks) to analyze results.

##### Relationships and Data Flows
- Raw data from the “data” folder flows into the data preprocessing modules (data_prep folders).
- Preprocessed data feeds into the network modules (HCNN_Cells, rnn_based_models, etc.).
- The forward pass and backward propagation (implemented in custom model files within HCNN, LSTM, and RNN directories) interact with the training strategy modules to optimize the models.
- During training, outputs (performance metrics, forecasts, trained models) are generated and stored in designated output folders.
- External simulation scripts and notebooks oversee the overall experiment flow, invoking both preprocessing and training components.

##### Architectural Patterns and Design Principles
- Modularization: Each major function (data handling, modeling, training, output management) is separated into distinct folders/modules, reflecting a layered architecture.
- Reusability & Extensibility: Parallel folders for chaos and climate ensure that similar functionalities (data preprocessing, modeling, training) can be extended or modified independently.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        DA["Raw Data (climate & sunhours)"]:::data
        DC1["Chaos Data HCNN"]:::data
        DC2["Chaos Data RNN"]:::data
        DP1["Chaos Data Prep HCNN"]:::data
        DP2["Chaos Data Prep RNN"]:::data
        DP3["Climate Data Prep HCNN"]:::data
        DP4["Climate Data Prep RNN"]:::data
        CW["Climate Wizard"]:::data
    end

    %% Model Definition Layer
    subgraph "Model Definition Layer"
        MH1["HCNN models.py"]:::model
        MH2["HCNN modules.py"]:::model
        MR["RNN models.py"]:::model
        ML["LSTM models.py"]:::model
        HC_CM["HCNN Chaos Modules"]:::model
        HC_CM_cl["HCNN Climate Modules"]:::model
        RC_CM["RNN Chaos Modules"]:::model
        RC_CM_cl["RNN Climate Modules"]:::model
    end

    %% Training Strategy Layer
    subgraph "Training Strategy Layer"
        TS1["Training Strategy Chaos HCNN"]:::training
        TS2["Training Strategy Chaos RNN"]:::training
        TS3["Training Strategy Climate HCNN"]:::training
        TS4["Training Strategy Climate RNN"]:::training
    end

    %% Execution & Output Management
    subgraph "Execution & Output"
        EX1["HCNN Simulation"]:::training
        EX2["RNN Simulation"]:::training
        EX3["RNN Chaos Simulation"]:::training
        LG1["HCNN Logger"]:::output
        LG2["LSTM Logger"]:::output
        LG3["RNN Logger"]:::output
        NB1["Notebooks RNN Chaos"]:::training
        NB2["Notebooks Sunhours"]:::training
    end

    %% Testing and Visualization
    subgraph "Testing & Visualization"
        T["Testing Suite"]:::test
        V1["Visualization HCNN"]:::test
        V2["Visualization LSTM"]:::test
        V3["Visualization RNN"]:::test
        V4["Visualization Climate"]:::test
    end

    %% Data Flow: Raw Data to Preprocessing
    DA -->|"data_preprocessing"| DP1
    DA -->|"data_preprocessing"| DP2
    DA -->|"data_preprocessing"| DP3
    DA -->|"data_preprocessing"| DP4
    CW -->|"enhances"| DP3
    CW -->|"enhances"| DP4
    DC1 -->|"supplies"| DP1
    DC2 -->|"supplies"| DP2

    %% Data Preprocessing to Model Definition (Specialized Modules)
    DP1 -->|"preprocessed"| HC_CM
    DP2 -->|"preprocessed"| RC_CM
    DP3 -->|"preprocessed"| HC_CM_cl
    DP4 -->|"preprocessed"| RC_CM_cl

    %% Base Model Definitions feeding into Specialized Modules
    MH1 -->|"provides"| HC_CM
    MH2 -->|"provides"| HC_CM
    MH1 -->|"provides"| HC_CM_cl
    MH2 -->|"provides"| HC_CM_cl
    MR -->|"provides"| RC_CM
    MR -->|"provides"| RC_CM_cl
    ML -->|"provides"| LG2

    %% Model Modules to Training Strategies
    HC_CM -->|"model_training"| TS1
    RC_CM -->|"model_training"| TS2
    HC_CM_cl -->|"model_training"| TS3
    RC_CM_cl -->|"model_training"| TS4

    %% Training Strategies to Execution/Output
    TS1 -->|"executes"| EX1
    TS2 -->|"executes"| EX3
    TS3 -->|"executes"| EX1
    TS4 -->|"executes"| EX2

    %% Simulation outputs to Loggers and Notebooks
    EX1 -->|"logs_output"| LG1
    EX2 -->|"logs_output"| LG3
    EX3 -->|"logs_output"| LG3
    EX1 -->|"feeds"| NB1
    EX2 -->|"feeds"| NB1
    EX3 -->|"feeds"| NB1
    DA -->|"supports"| NB2

    %% Execution outputs to Testing & Visualization
    EX1 -->|"evaluated_by"| V1
    EX1 -->|"evaluated_by"| V4
    EX2 -->|"evaluated_by"| V3
    EX2 -->|"evaluated_by"| V4
    EX3 -->|"evaluated_by"| V3
    T -->|"monitors"| V1
    T -->|"monitors"| V2
    T -->|"monitors"| V3
    T -->|"monitors"| V4

    %% Click Events for Data Layer
    click DA "https://github.com/rock-feller/hcnns_and_chaos/tree/master/data/"
    click DC1 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/HCNNs_Chaos/data"
    click DC2 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/RNNs_Chaos/data"
    click DP1 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/HCNNs_Chaos/data_prep"
    click DP2 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/RNNs_Chaos/data_prep"
    click DP3 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/HCNNs_Climate/data_prep"
    click DP4 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/RNNs_Climate/data_prep"
    click CW "https://github.com/rock-feller/hcnns_and_chaos/tree/master/data/climate_wizard"

    %% Click Events for Model Definition Layer
    click MH1 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/HCNN/models.py"
    click MH2 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/HCNN/modules.py"
    click MR "https://github.com/rock-feller/hcnns_and_chaos/blob/master/RNN/models.py"
    click ML "https://github.com/rock-feller/hcnns_and_chaos/blob/master/LSTM/models.py"
    click HC_CM "https://github.com/rock-feller/hcnns_and_chaos/tree/master/HCNNs_Chaos/hcnn_modules"
    click HC_CM_cl "https://github.com/rock-feller/hcnns_and_chaos/tree/master/HCNNs_Climate/hcnn_modules"
    click RC_CM "https://github.com/rock-feller/hcnns_and_chaos/tree/master/RNNs_Chaos/models"
    click RC_CM_cl "https://github.com/rock-feller/hcnns_and_chaos/tree/master/RNNs_Climate/models"

    %% Click Events for Training Strategy Layer
    click TS1 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/HCNNs_Chaos/modeling_strategy"
    click TS2 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/RNNs_Chaos/modeling_strategy"
    click TS3 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/HCNNs_Climate/modeling_strategy"
    click TS4 "https://github.com/rock-feller/hcnns_and_chaos/tree/master/RNNs_Climate/modeling_strategy"

    %% Click Events for Execution & Output
    click EX1 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/simulation_instance_HCNNs.py"
    click EX2 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/simulation_instance_RNNs.py"
    click EX3 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/RNNs_Chaos/simulation_instance.py"
    click LG1 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/HCNN/logger.py"
    click LG2 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/LSTM/logger.py"
    click LG3 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/RNN/logger.py"
    click NB1 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/RNNs_Chaos/example_test.ipynb"
    click NB2 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/data/sunhours_data/sunhours_generation_workflow.ipynb"

    %% Click Events for Testing and Visualization
    click T "https://github.com/rock-feller/hcnns_and_chaos/tree/master/test/"
    click V1 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/HCNN/visualization.py"
    click V2 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/LSTM/visualization.py"
    click V3 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/RNN/visualization.py"
    click V4 "https://github.com/rock-feller/hcnns_and_chaos/blob/master/data/climate_wizard/visual.py"

    %% Styles
    classDef data fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef model fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef training fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef output fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef test fill:#E0E0E0,stroke:#000,stroke-width:2px,stroke-dasharray: 5 5;
```
