# is0383kk/symbolemergence-vae-gmm architecture

> Architecture diagram of the GitHub repository is0383kk/symbolemergence-vae-gmm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/is0383kk/symbolemergence-vae-gmm
- Repository: https://github.com/is0383kk/symbolemergence-vae-gmm

## Overview

##### Project type and purpose
- This is a Python-based deep learning research project (not a web or microservice app). It implements an emergent-communication “naming game” between two agents, each represented by a VAE (Variational Autoencoder) and a GMM (Gaussian Mixture Model), using the Metropolis-Hastings algorithm. The goal is to train the agents on MNIST images so that they converge on shared symbolic representations.

##### File structure
- Top-level files:
- main.py   → Orchestrates data loading, VAE training for both agents, the MH naming game loop, and metrics logging.
- cnn_vae_module_mnist.py → Defines the PyTorch VAE modules (encoder/decoder) tailored for MNIST (convolutional layers).
- recall_image.py → After training, loads stored GMM means and uses each agent’s VAE decoder to reconstruct (“recall”) images.
- tool.py   → Utility functions (data loaders, metric calculators, model save/load routines).
- No external microservices or frontend/backend layers—this is a self-contained ML pipeline.

##### Key insights from the README
- Two agents (A and B), each with VAE → Estimates latent z^A and z^B.
- Each agent clusters z via GMM to obtain discrete variables w^A/w^B.
- Agents alternately “speak” proposals of w and “listen” via Metropolis-Hastings accept/reject.
- Iterative loop: VAE training → proposal → MH decision → GMM/VAE-prior update → back to training.
- Outputs: ARI and Kappa scores, reconstructed images for qualitative analysis.

##### Detail
- Two parallel branches for Agent A and Agent B

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Stages
    subgraph "Training Stage"
        direction TB
        DataLoader["Data Loader (MNIST)"]:::data
        VAEA["VAE Module A"]:::vae
        VAEB["VAE Module B"]:::vae
        DataLoader -->|input images| VAEA
        DataLoader -->|input images| VAEB
    end

    subgraph "Communication Stage"
        direction TB
        GMM_A["GMM Module A"]:::prob
        GMM_B["GMM Module B"]:::prob
        MH["Metropolis-Hastings Engine"]:::prob
        Metrics["Metrics Logger"]:::util

        VAEA -->|latent z^A| GMM_A
        VAEB -->|latent z^B| GMM_B

        GMM_A -->|w^A proposal| MH
        GMM_B -->|w^B proposal| MH

        MH -->|accept/reject| GMM_A
        MH -->|accept/reject| GMM_B

        MH -->|log ARI/Kappa| Metrics
    end

    subgraph "Recall Stage"
        direction TB
        Recall["Recall Module"]:::util
        MH -->|after N iterations| Recall
        Recall -->|reconstructed images| StaticAssets
    end

    subgraph "Utilities"
        direction TB
        Utils["tool.py (Utilities)"]:::util
        StaticAssets["Static Assets (diagrams)"]:::util
        Utils --> DataLoader
        Utils --> GMM_A
        Utils --> GMM_B
        Utils --> Metrics
    end

    %% Loop annotation
    classDef loopAnn fill:none,stroke-dasharray: 5 5
    loop["Repeat N times"]:::loopAnn
    MH --> loop
    loop --> VAEA
    loop --> VAEB

    %% Click events
    click DataLoader "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/tool.py"
    click VAEA "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/cnn_vae_module_mnist.py"
    click VAEB "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/cnn_vae_module_mnist.py"
    click GMM_A "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/tool.py"
    click GMM_B "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/tool.py"
    click MH "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/main.py"
    click Metrics "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/main.py"
    click Recall "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/recall_image.py"
    click Utils "https://github.com/is0383kk/symbolemergence-vae-gmm/blob/master/tool.py"
    click StaticAssets "https://github.com/is0383kk/symbolemergence-vae-gmm/tree/master/image/"

    %% Styles
    classDef vae fill:#ADD8E6,stroke:#000
    classDef prob fill:#90EE90,stroke:#000
    classDef util fill:#FFA500,stroke:#000
    classDef data fill:#FFD700,stroke:#000
    classDef loopAnn fill:none,stroke-dasharray:5 5,stroke:#888
```
