# guifagundes01/transformer-locindoor architecture

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

- Interactive diagram: https://gitdiagram.com/guifagundes01/transformer-locindoor
- Repository: https://github.com/guifagundes01/transformer-locindoor

## Overview

##### Project type and purpose
- Transformer-Localization is a machine-learning research pipeline focused on indoor localization.
- It provides baseline KNN experiments and a Transformer-based localization model (tLoc) with data augmentation, filtering, training, and inference stages.

##### File structure
- Top level:
- data/ — raw and preprocessed CSV/NumPy geometry files
- experiments/ — shell scripts and result logs for KNN experiments
- figures/ — (presumably output visualization)
- localization/ — core Python package with submodules:
– augmentation/ — augmentation routines and tests
– dataset/ — dataset definitions/loaders for RSS, language masks, building geometry
– models/ — model building blocks (_feedforward, _rnn, positional encoding, RBF model)
– scripts/ — CLI entry points for running KNN, training tLoc, filtering data, etc.
– transformations/ — ranking-based dataset transformations and tests
– utils/ — constants, determinism helpers
- experimentation.ipynb, tests.ipynb — notebooks for exploratory analysis
- Makefile, .gitignore, requirements.txt

##### README
- Provides CLI usage for KNN and tLoc
- Describes a 4-step workflow for training, filtering, retraining, and inference
- Indicates that two main “systems” coexist: a KNN baseline and the Transformer-based tLoc pipeline

##### Main components
a. Data Layer
- Raw Data: data/*.csv, data/geometry_building_*.npy
- Augmented Data: data/augmented* and data/filtered folders
b. Preprocessing & Augmentation
- localization.augmentation (augmentation.py, augmentation_rbf_model.py)
- localization.transformations (ranking_based.py)
c. Dataset & Loader
- localization.dataset (RSSDataset, LangDataset, UjiIndoorLoc)
- langmaskdataset for language-masked input
d. Model Training & Architecture
- tLoc model: feedforward + positional encoding + lock-in encoder + RNN layers (in localization.models)
- RBF model variant (RBF-based augmentor)
e. Baseline Experiments
- KNN: run_knn script, experiments/knn.sh
f. Filtering & Retraining
- Scripts: filter_tloc, train_tloc_filtered
g. Inference
- run_tloc (with building/floor arguments)

##### Relationships and interactions
- Data flows from Raw Data → Augmentation/Filtering → Dataset loaders → Model training → Trained model
- Experiments branch off for KNN (no model training) versus full tLoc pipeline
- Utilities (constants, determinism) are shared across augmentation, dataset, and model components

##### Architectural patterns and technologies
- Modular Python package (`localization/`) following separation of concerns
- Test-driven for augmentation and transformations
- Scripts as thin orchestration layers (Unix CLI + `-m localization.scripts.*`)
- Data-centric, batch pipeline (no microservices; single process)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RawTrain["trainingData.csv"]:::data
        RawVal["validationData.csv"]:::data
        RawGeom["Geometry Files (.npy)"]:::data
    end

    %% Preprocessing & Augmentation
    subgraph "Preprocessing & Augmentation"
        direction TB
        StandardAug["augmentation.py"]:::preproc
        RBFaug["augmentation_rbf_model.py"]:::preproc
        RankingTrans["ranking_based.py"]:::preproc
    end

    %% Dataset Loaders
    subgraph "Dataset Loaders"
        direction TB
        RSSDS["rssdataset.py"]:::dataset
        LangDS["langdataset.py"]:::dataset
        MaskDS["langmaskdataset.py"]:::dataset
        UjiDS["ujiindoorloc.py"]:::dataset
    end

    %% Model Components
    subgraph "Model Components"
        direction TB
        FF["_feedforward.py"]:::model
        PE["_positionalencoding.py"]:::model
        LI["_lockinencoder.py"]:::model
        RNN["_rnn.py"]:::model
        Norm["_normalizer.py"]:::model
        Flat["_flatten.py"]:::model
        RBFModel["rbf_model.py"]:::model
    end

    %% Scripts & Controllers
    subgraph "CLI Scripts"
        direction TB
        RunAug["run_augmentation.py"]:::scripts
        GenRank["gen_ranking_based_dataset.py"]:::scripts
        RunKNN["run_knn.py"]:::scripts
        KNNsh["knn.sh"]:::scripts
        TrainTLoc["train_tloc.py"]:::scripts
        TrainTLocF["train_tloc_filtered.py"]:::scripts
        TrainRNN["train_rnn.py"]:::scripts
        TrainLangRNN["train_lang_rnn.py"]:::scripts
        TrainLangMask["train_lang_rnn_mask.py"]:::scripts
        FilterT["filter_tloc.py"]:::scripts
        RunTLocF["run_tloc_filtered.py"]:::scripts
        RunTLoc["run_tloc.py"]:::scripts
        BuildMasks["build_prob_masks.py"]:::scripts
    end

    %% Outputs
    subgraph "Outputs"
        direction TB
        AugData["Augmented Data"]:::output
        AugBayes["Augmented Bayes Data"]:::output
        FilteredData["Filtered Data"]:::output
        KNNResults["knn.txt"]:::output
        TrainedModel["Trained tLoc Model"]:::output
        Figures["Figures"]:::output
    end

    %% Connections: Data to Preprocessing
    RawTrain --> StandardAug
    RawVal --> StandardAug
    RawGeom --> RBFaug

    %% Preprocessing to Data Stores
    StandardAug --> AugData
    RBFaug --> AugBayes

    %% Augmented Data to Ranking
    AugData --> RankingTrans
    RankingTrans --> FilteredData

    %% Data Stores to Dataset Loaders
    AugData --> RSSDS
    AugData --> LangDS
    AugData --> UjiDS
    FilteredData --> MaskDS

    %% Dataset to Model Components
    RSSDS --> FF
    LangDS --> PE
    MaskDS --> LI
    UjiDS --> RNN

    %% Model flow
    FF --> PE --> LI --> RNN --> Norm --> Flat
    RBFModel --> FF

    %% Scripts orchestrate stages
    RunAug --> StandardAug
    GenRank --> RankingTrans
    RunKNN --> KNNResults
    KNNsh --> RunKNN
    TrainTLoc --> FF
    TrainTLocF --> FF
    TrainRNN --> RNN
    TrainLangRNN --> LangDS
    TrainLangMask --> MaskDS
    FilterT --> FilteredData
    RunTLocF --> RunTLoc
    RunTLoc --> TrainedModel
    BuildMasks --> MaskDS

    %% Outputs
    TrainedModel --> Figures

    %% Click Events
    click RawTrain "https://github.com/guifagundes01/transformer-locindoor/blob/main/data/trainingData.csv"
    click RawVal "https://github.com/guifagundes01/transformer-locindoor/blob/main/data/validationData.csv"
    click RawGeom "https://github.com/guifagundes01/transformer-locindoor/tree/main/data/"
    click StandardAug "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/augmentation/augmentation.py"
    click RBFaug "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/augmentation/augmentation_rbf_model.py"
    click RankingTrans "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/transformations/ranking_based.py"
    click RSSDS "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/dataset/rssdataset.py"
    click LangDS "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/dataset/langdataset.py"
    click MaskDS "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/dataset/langmaskdataset.py"
    click UjiDS "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/dataset/ujiindoorloc.py"
    click FF "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/models/_feedforward.py"
    click PE "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/models/_positionalencoding.py"
    click LI "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/models/_lockinencoder.py"
    click RNN "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/models/_rnn.py"
    click Norm "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/models/_normalizer.py"
    click Flat "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/models/_flatten.py"
    click RBFModel "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/models/rbf_model.py"
    click RunAug "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/run_augmentation.py"
    click GenRank "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/gen_ranking_based_dataset.py"
    click RunKNN "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/run_knn.py"
    click KNNsh "https://github.com/guifagundes01/transformer-locindoor/blob/main/experiments/knn.sh"
    click KNNResults "https://github.com/guifagundes01/transformer-locindoor/blob/main/experiments/results/knn.txt"
    click TrainTLoc "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/train_tloc.py"
    click TrainTLocF "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/train_tloc_filtered.py"
    click TrainRNN "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/train_rnn.py"
    click TrainLangRNN "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/train_lang_rnn.py"
    click TrainLangMask "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/train_lang_rnn_mask.py"
    click FilterT "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/filter_tloc.py"
    click RunTLocF "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/run_tloc_filtered.py"
    click RunTLoc "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/run_tloc.py"
    click BuildMasks "https://github.com/guifagundes01/transformer-locindoor/blob/main/localization/scripts/build_prob_masks.py"
    click AugData "https://github.com/guifagundes01/transformer-locindoor/tree/main/data/augmented/*"
    click AugBayes "https://github.com/guifagundes01/transformer-locindoor/tree/main/data/augmented_bayes/*"
    click FilteredData "https://github.com/guifagundes01/transformer-locindoor/tree/main/data/filtered/*"

    %% Styles
    classDef data fill:#bbdefb,stroke:#0d47a1,color:#0d47a1;
    classDef preproc fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20;
    classDef dataset fill:#fff9c4,stroke:#f57f17,color:#f57f17;
    classDef model fill:#ffcdd2,stroke:#b71c1c,color:#b71c1c;
    classDef scripts fill:#e0e0e0,stroke:#424242,color:#424242;
    classDef output fill:#d1c4e9,stroke:#4a148c,color:#4a148c;
```
