# si-cim/prototorch_models architecture

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

- Interactive diagram: https://gitdiagram.com/si-cim/prototorch_models
- Repository: https://github.com/si-cim/prototorch_models

## Overview

##### Main Components

a. Core Components:
- Model Implementation Layer (src/prototorch/models/)
- Abstract Base Classes (abstract.py)
- Model Categories:
- LVQ Family Models
- Unsupervised Learning Models
- Probabilistic Models
- Distance-based Models (KNN)
- Visualization Components (vis.py)
- Callback System (callbacks.py)

b. External Dependencies:
- PyTorch
- PyTorch-Lightning
- ProtoTorch Core

**[External Dependencies Layer]**
- ↓
**[Abstract Base Layer]**
- ↓
**[Core Implementation Layer]**
- ↓
**[Model Categories Layer]**
- ↓
**[Utility Layer (Callbacks, Visualization)]**

##### Component Relationships

- Inheritance relationships from abstract base classes
- Dependencies between components
- Data flow during model training and inference

##### Specific Implementation Details

a. Model Categories Section:
**LVQ Family:**
**[GLVQ] ← [GRLVQ] ← [GMLVQ]**
**[Siamese GLVQ]**
**[RSLVQ]**
**[PLVQ]**
**etc.**

**Unsupervised:**
**[Neural Gas]**
**[Growing Neural Gas]**
**[KSOM]**

b. Integration Points:
- How models interact with PyTorch-Lightning
- Demonstrate callback integration

##### Technical Details

- Model initialization flow
- Training pipeline integration
- Callback hooks
- Visualization pipeline

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Dependencies Layer
    subgraph Dependencies
        PyTorch["PyTorch"]
        PyTorchLightning["PyTorch Lightning"]
        ProtoTorchCore["ProtoTorch Core"]
    end

    %% Abstract Base Layer
    subgraph AbstractLayer["Abstract Base Layer"]
        AbstractBase["Abstract Base Classes"]:::abstract
    end

    %% Core Implementation Layer
    subgraph CoreLayer["Core Implementation Layer"]
        ModelImpl["Model Implementation"]:::core
        Callbacks["Callback System"]:::utility
        Visualization["Visualization Component"]:::utility
    end

    %% Model Categories Layer
    subgraph ModelCategories["Model Categories"]
        subgraph LVQFamily["LVQ Family"]
            GLVQ["GLVQ"]:::implemented
            GRLVQ["GRLVQ"]:::implemented
            GMLVQ["GMLVQ"]:::implemented
            SiameseGLVQ["Siamese GLVQ"]:::implemented
            RSLVQ["RSLVQ"]:::implemented
            PLVQ["PLVQ"]:::implemented
        end

        subgraph Unsupervised["Unsupervised Learning"]
            NeuralGas["Neural Gas"]:::implemented
            GrowingNeuralGas["Growing Neural Gas"]:::implemented
            KSOM["KSOM"]:::implemented
        end

        subgraph OtherModels["Other Models"]
            KNN["Distance-based (KNN)"]:::implemented
            CBC["CBC"]:::wip
        end
    end

    %% Relationships
    PyTorch --> PyTorchLightning
    PyTorchLightning --> ProtoTorchCore
    ProtoTorchCore --> AbstractBase
    AbstractBase --> ModelImpl
    ModelImpl --> LVQFamily
    ModelImpl --> Unsupervised
    ModelImpl --> OtherModels
    ModelImpl --> Callbacks
    ModelImpl --> Visualization

    %% Component Mappings
    click AbstractBase "https://github.com/si-cim/prototorch_models/blob/main/src/prototorch/models/abstract.py"
    click Visualization "https://github.com/si-cim/prototorch_models/blob/main/src/prototorch/models/vis.py"
    click Callbacks "https://github.com/si-cim/prototorch_models/blob/main/src/prototorch/models/callbacks.py"
    click GLVQ "https://github.com/si-cim/prototorch_models/blob/main/examples/glvq_iris.py"
    click GMLVQ "https://github.com/si-cim/prototorch_models/blob/main/examples/gmlvq_iris.py"
    click GrowingNeuralGas "https://github.com/si-cim/prototorch_models/blob/main/examples/gng_iris.py"
    click KSOM "https://github.com/si-cim/prototorch_models/blob/main/examples/ksom_colors.py"
    click RSLVQ "https://github.com/si-cim/prototorch_models/blob/main/examples/rslvq_iris.py"
    click SiameseGLVQ "https://github.com/si-cim/prototorch_models/blob/main/examples/siamese_glvq_iris.py"
    click ModelImpl "https://github.com/si-cim/prototorch_models/tree/main/src/prototorch/models/"
    click KNN "https://github.com/si-cim/prototorch_models/blob/main/src/prototorch/models/knn.py"
    click CBC "https://github.com/si-cim/prototorch_models/blob/main/src/prototorch/models/cbc.py"

    %% Styles
    classDef abstract fill:#a8d1f0
    classDef implemented fill:#90EE90
    classDef utility fill:#FFE5B4
    classDef core fill:#D3D3D3
    classDef wip fill:#DDA0DD

    %% Legend
    subgraph Legend
        L1["Abstract Base Classes"]:::abstract
        L2["Implemented Models"]:::implemented
        L3["Utility Components"]:::utility
        L4["Core Components"]:::core
        L5["Work in Progress"]:::wip
    end
```
