# asherwoods39/capa-fi architecture

> Architecture diagram of the GitHub repository asherwoods39/capa-fi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/asherwoods39/capa-fi
- Repository: https://github.com/asherwoods39/capa-fi

## Overview

CAPA-Fi is a PyTorch framework for multi-user Wi-Fi CSI activity recognition and source-free adaptation when target environments contain only a subset of source activity classes. Its principal workflow loads CSI and slot labels, trains a permutation-invariant source model, then adapts the encoder on unlabeled target CSI while freezing the classifier; evaluation reports slot, occupancy, and category metrics. The graph preserves the documented rotation self-supervision, category filtering, and partial-shift evaluation capabilities. Some listed modules were not sampled, so only documented or indexed relationships are connected; unsampled internals are not inferred.

Main entry points: [`src/models/train_source.py`](https://github.com/asherwoods39/capa-fi/blob/main/src/models/train_source.py) (Source training), [`src/models/har_model.py`](https://github.com/asherwoods39/capa-fi/blob/main/src/models/har_model.py) (HAR model wrapper), [`src/adaptation/run_adaptation.py`](https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/run_adaptation.py) (Adaptation runner), [`src/adaptation/trainer.py`](https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/trainer.py) (Adaptation trainer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["CSI data"]
  node_downloader["WiMANS downloader<br/>[download_data.py]"]
  node_dataset["CSI dataset<br/>[dataset.py]"]
  node_augmentation["CSI augmentation<br/>[augmentation.py]"]
end

subgraph group_model["Recognition model"]
  node_source_train["Source training<br/>[train_source.py]"]
  node_backbone["Spatial-temporal backbone<br/>[backbone.py]"]
  node_classifier["Multi-slot classifier<br/>[classifier.py]"]
  node_har_model["HAR model wrapper<br/>[har_model.py]"]
  node_matcher["Hungarian matcher<br/>[matcher.py]"]
  node_source_losses["Source losses<br/>[losses.py]"]
  node_rotation_head["Rotation head<br/>[rotation_head.py]"]
end

subgraph group_adapt["Source-free adaptation"]
  node_adapt_runner["Adaptation runner<br/>[run_adaptation.py]"]
  node_mock_inputs["Synthetic inputs<br/>[mock_inputs.py]"]
  node_trainer["Adaptation trainer<br/>[trainer.py]"]
  node_confidence["Confidence filtering"]
  node_loss_engine["CAPA-Fi loss engine<br/>[loss_engine.py]"]
end

subgraph group_eval["Evaluation"]
  node_eval_runner["Benchmark runner<br/>[benchmark.py]"]
  node_metrics["Evaluation metrics<br/>[metrics.py]"]
end

node_researcher(("Researcher"))
node_wimans[("WiMANS data")]

node_researcher -->|"trains source"| node_source_train
node_researcher -->|"runs adaptation"| node_adapt_runner
node_wimans -->|"downloads"| node_downloader
node_downloader -->|"provides CSI files"| node_dataset
node_dataset -->|"loads source batches"| node_source_train
node_augmentation -->|"augments CSI"| node_source_train
node_source_train -->|"trains model"| node_har_model
node_source_train -->|"uses training losses"| node_source_losses
node_source_train -->|"matches slots"| node_matcher
node_har_model -->|"encodes CSI"| node_backbone
node_har_model -->|"classifies latents"| node_classifier
node_har_model -->|"predicts rotation"| node_rotation_head
node_adapt_runner -->|"runs adaptation"| node_trainer
node_adapt_runner -->|"loads target CSI"| node_dataset
node_adapt_runner -->|"uses fallback"| node_mock_inputs
node_trainer -->|"computes filtering"| node_confidence
node_trainer -->|"computes objective"| node_loss_engine
node_loss_engine -->|"computes probabilities"| node_confidence
node_trainer -->|"adapts model"| node_har_model
node_eval_runner -->|"reports metrics"| node_metrics
node_eval_runner -.->|"evaluates predictions"| node_har_model

click node_downloader "https://github.com/asherwoods39/capa-fi/blob/main/src/utils/download_data.py"
click node_dataset "https://github.com/asherwoods39/capa-fi/blob/main/src/dataset.py"
click node_augmentation "https://github.com/asherwoods39/capa-fi/blob/main/src/utils/augmentation.py"
click node_source_train "https://github.com/asherwoods39/capa-fi/blob/main/src/models/train_source.py"
click node_backbone "https://github.com/asherwoods39/capa-fi/blob/main/src/models/backbone.py"
click node_classifier "https://github.com/asherwoods39/capa-fi/blob/main/src/models/classifier.py"
click node_har_model "https://github.com/asherwoods39/capa-fi/blob/main/src/models/har_model.py"
click node_matcher "https://github.com/asherwoods39/capa-fi/blob/main/src/models/matcher.py"
click node_source_losses "https://github.com/asherwoods39/capa-fi/blob/main/src/models/losses.py"
click node_rotation_head "https://github.com/asherwoods39/capa-fi/blob/main/src/models/rotation_head.py"
click node_adapt_runner "https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/run_adaptation.py"
click node_mock_inputs "https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/mock_inputs.py"
click node_trainer "https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/trainer.py"
click node_confidence "https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/confidence_masking.py"
click node_loss_engine "https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/loss_engine.py"
click node_eval_runner "https://github.com/asherwoods39/capa-fi/blob/main/src/evaluation/benchmark.py"
click node_metrics "https://github.com/asherwoods39/capa-fi/blob/main/src/evaluation/metrics.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_downloader,node_dataset,node_augmentation toneBlue
class node_source_train,node_backbone,node_classifier,node_har_model,node_matcher,node_source_losses,node_rotation_head,node_wimans toneAmber
class node_adapt_runner,node_mock_inputs,node_trainer,node_confidence,node_loss_engine toneMint
class node_eval_runner,node_metrics toneRose
class node_researcher toneIndigo
```

## Components

### CSI data

- [WiMANS downloader](https://github.com/asherwoods39/capa-fi/blob/main/src/utils/download_data.py): `src/utils/download_data.py`
- [CSI dataset](https://github.com/asherwoods39/capa-fi/blob/main/src/dataset.py): `src/dataset.py`
- [CSI augmentation](https://github.com/asherwoods39/capa-fi/blob/main/src/utils/augmentation.py): `src/utils/augmentation.py`

### Recognition model

- [Source training](https://github.com/asherwoods39/capa-fi/blob/main/src/models/train_source.py): `src/models/train_source.py`
- [Spatial-temporal backbone](https://github.com/asherwoods39/capa-fi/blob/main/src/models/backbone.py): `src/models/backbone.py`
- [Multi-slot classifier](https://github.com/asherwoods39/capa-fi/blob/main/src/models/classifier.py): `src/models/classifier.py`
- [HAR model wrapper](https://github.com/asherwoods39/capa-fi/blob/main/src/models/har_model.py): `src/models/har_model.py`
- [Hungarian matcher](https://github.com/asherwoods39/capa-fi/blob/main/src/models/matcher.py): `src/models/matcher.py`
- [Source losses](https://github.com/asherwoods39/capa-fi/blob/main/src/models/losses.py): `src/models/losses.py`
- [Rotation head](https://github.com/asherwoods39/capa-fi/blob/main/src/models/rotation_head.py): `src/models/rotation_head.py`

### Source-free adaptation

- [Adaptation runner](https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/run_adaptation.py): `src/adaptation/run_adaptation.py`
- [Synthetic inputs](https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/mock_inputs.py): `src/adaptation/mock_inputs.py`
- [Adaptation trainer](https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/trainer.py): `src/adaptation/trainer.py`
- [Confidence filtering](https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/confidence_masking.py): `src/adaptation/confidence_masking.py`
- [CAPA-Fi loss engine](https://github.com/asherwoods39/capa-fi/blob/main/src/adaptation/loss_engine.py): `src/adaptation/loss_engine.py`

### Evaluation

- [Benchmark runner](https://github.com/asherwoods39/capa-fi/blob/main/src/evaluation/benchmark.py): `src/evaluation/benchmark.py`
- [Evaluation metrics](https://github.com/asherwoods39/capa-fi/blob/main/src/evaluation/metrics.py): `src/evaluation/metrics.py`

### Other components

- **Researcher**
- **WiMANS data**

## Connections

- Researcher → Source training: trains source (evidence: `README.md`)
- Researcher → Adaptation runner: runs adaptation (evidence: `README.md`)
- WiMANS data → WiMANS downloader: downloads (evidence: `src/utils/download_data.py`)
- WiMANS downloader → CSI dataset: provides CSI files (evidence: `src/dataset.py`)
- CSI dataset → Source training: loads source batches (evidence: `src/models/train_source.py`)
- CSI augmentation → Source training: augments CSI (evidence: `src/models/train_source.py`)
- Source training → HAR model wrapper: trains model (evidence: `src/models/train_source.py`)
- Source training → Source losses: uses training losses (evidence: `src/models/train_source.py`)
- Source training → Hungarian matcher: matches slots (evidence: `README.md`)
- HAR model wrapper → Spatial-temporal backbone: encodes CSI (evidence: `src/models/har_model.py`)
- HAR model wrapper → Multi-slot classifier: classifies latents (evidence: `src/models/har_model.py`)
- HAR model wrapper → Rotation head: predicts rotation (evidence: `src/models/har_model.py`)
- Adaptation runner → Adaptation trainer: runs adaptation (evidence: `src/adaptation/run_adaptation.py`)
- Adaptation runner → CSI dataset: loads target CSI (evidence: `src/adaptation/run_adaptation.py`)
- Adaptation runner → Synthetic inputs: uses fallback (evidence: `src/adaptation/run_adaptation.py`)
- Adaptation trainer → Confidence filtering: computes filtering (evidence: `src/adaptation/trainer.py`)
- Adaptation trainer → CAPA-Fi loss engine: computes objective (evidence: `src/adaptation/trainer.py`)
- CAPA-Fi loss engine → Confidence filtering: computes probabilities (evidence: `src/adaptation/loss_engine.py`)
- Adaptation trainer → HAR model wrapper: adapts model (evidence: `README.md`)
- Benchmark runner → Evaluation metrics: reports metrics (evidence: `README.md`)
- Benchmark runner → HAR model wrapper: evaluates predictions
