# pranoy-panda/causal-feature-subset-selection architecture

> Architecture diagram of the GitHub repository pranoy-panda/causal-feature-subset-selection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pranoy-panda/causal-feature-subset-selection
- Repository: https://github.com/pranoy-panda/causal-feature-subset-selection

## Overview

##### Project type and purpose
- It runs as a command-line pipeline (via main.py), processes vision datasets (MNIST, CIFAR, FMNIST), loads a pretrained model, computes causal feature subsets, evaluates them, and exports visualization results.

##### File structure
- Top-level orchestrator: main.py
- Configuration manager: config.py (datasets, hyperparameters, paths)
- Dataset loader and preprocessor: dataset_file.py
- Core algorithms and utilities: utils.py (causal metric computation, mask generation, plotting, evaluation)
- Results output directory: results/ (images saved from experiments)
- Dependency manifest: requirements.txt

##### README for additional insights
- External dependencies: PyTorch, NumPy, Matplotlib, skimage, captum.

a. Main components to represent
– Configuration Manager (config.py)
– Data Ingestion & Preprocessing (dataset_file.py)
– Causal Feature Selector (core routines in utils.py)
– Evaluation Module (post-hoc accuracy, Average Causal Effect in utils.py)
– Visualization & Results Generator (plotting routines in utils.py → results/)
– External Libraries & Frameworks (PyTorch, NumPy, skimage, captum, Matplotlib)

b. Relationships and data flow
– Configuration Manager feeds hyperparameters and dataset/model choices into Data Ingestion and Model Loader.
– Causal Selector computes feature subsets (via calls to captum or custom utility functions).
– Evaluation Module measures metrics on the selected subset vs. original output.
– Visualization Module generates images of selected superpixels and writes to results/.

c. Architectural patterns and design principles
– Separation of concerns: each module handles a distinct responsibility.
– Modular and extensible: swapping models, datasets, or causal metrics by editing config.py.

d. Key technologies and libraries
– Core language: Python 3.5+
– Deep learning: PyTorch
– Array & math: NumPy, scikit-image
– Interpretation: captum
– Plotting: Matplotlib

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraphs and modules
    subgraph "CLI Orchestrator"
        direction TB
        Main["main.py"]:::pythonModule
    end

    subgraph "Configuration"
        direction TB
        Config["config.py"]:::pythonModule
    end

    subgraph "Data Ingestion & Preprocessing"
        direction TB
        Dataset["dataset_file.py"]:::pythonModule
        DataStoreDatasets[(Datasets Directory)]:::dataStore
    end

    subgraph "Inference"
        direction TB
        ModelLoader["models_file.py"]:::pythonModule
        PretrainedWeights[(Pretrained Model Weights)]:::dataStore
    end

    subgraph "Causal Feature Selection"
        direction TB
        Selector["utils.py"]:::pythonModule
    end

    subgraph "Evaluation & Visualization"
        direction TB
        Evaluator["utils.py"]:::pythonModule
        Visualizer["utils.py"]:::pythonModule
        ResultsDir[(results/)]:::dataStore
    end

    subgraph "Documentation & Dependencies"
        direction TB
        Readme["README.md"]:::dataStore
        Req["requirements.txt"]:::dataStore
        External["External Libraries"]:::external
    end

    %% Connections
    Main -->|loads config| Config
    Config -->|provides params| Dataset
    Config -->|provides params| ModelLoader
    Config -->|provides params| Selector

    Dataset -->|provides batches| ModelLoader
    Dataset -->|provides data| Selector

    ModelLoader -->|predict & features| Selector
    Selector -->|selected features| Evaluator
    Evaluator -->|"metrics"| Visualizer
    Visualizer -->|saves results| ResultsDir

    Main -->|reads README| Readme
    Main -->|installs deps| Req
    Main -->|uses| External

    %% Click Events
    click Main "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/main.py"
    click Config "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/config.py"
    click Dataset "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/dataset_file.py"
    click ModelLoader "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/models_file.py"
    click Selector "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/utils.py"
    click Evaluator "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/utils.py"
    click Visualizer "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/utils.py"
    click ResultsDir "https://github.com/pranoy-panda/causal-feature-subset-selection/tree/main/results/"
    click Req "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/requirements.txt"
    click Readme "https://github.com/pranoy-panda/causal-feature-subset-selection/blob/main/README.md"

    %% Styles
    classDef pythonModule fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px
    classDef dataStore fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px,shape:cylinder
    classDef external fill:#FFE0B2,stroke:#E65100,stroke-width:2px,shape:cloud
```
