# danielbgoncalves/percolation_based_rp_for_xai architecture

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

- Interactive diagram: https://gitdiagram.com/danielbgoncalves/percolation_based_rp_for_xai
- Repository: https://github.com/danielbgoncalves/percolation_based_rp_for_xai

## Overview

This repository implements a histopathology classification and interpretability pipeline: images yield fractal percolation descriptors and recurrence-plot representations, which are classified by CNN branches and examined through XAI. The graph distinguishes documented stages and the sampled runtime calls. CSV descriptors and experiment-result directories are described in the README but absent from the supplied tree, so they are represented only as documented external data/results. Several analysis modules are included because they are major documented capabilities; unsampled wiring is not asserted.

Main entry points: [`xai/run_analise_completa.py`](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/run_analise_completa.py) (XAI orchestration), [`extract_fractal_features/ScriptPercLACDF3Distances.py`](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/ScriptPercLACDF3Distances.py) (Feature scripts), [`xai/loader.py`](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/loader.py) (Branch loader), [`model/train.py`](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/train.py) (K-fold training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_features["Fractal features"]
  node_feature_algorithms["Percolation metrics<br/>[clustperc.py]"]
  node_metric_variants["Distance variants<br/>[clustpercEucl.py]"]
  node_pmr_metrics["PMR distances<br/>[pmr.py]"]
  node_lacunar["Lacunarity<br/>[lacunaridade.py]"]
  node_feature_scripts["Feature scripts"]
  node_descriptor_csv[("Descriptor CSVs")]
end

subgraph group_represent["RP representations"]
  node_rp_build["RP generation"]
  node_rp_transform["RP encoding<br/>[RP.py]"]
  node_rp_images["Recurrence plots"]
end

subgraph group_classify["CNN classification"]
  node_data_loading["Image datasets<br/>[dataset.py]"]
  node_transforms["Input transforms<br/>[utils.py]"]
  node_cnn["CNN architectures<br/>[model.py]"]
  node_training["K-fold training<br/>[train.py]"]
  node_run_model["Model runner<br/>[run.py]"]
  node_evaluation["Evaluation metrics<br/>[metrics.py]"]
  node_model_weights[("Model weights")]
  node_predictions[("Predictions")]
end

subgraph group_explain["XAI analysis"]
  node_xai_orchestrator["XAI orchestration"]
  node_branch_loader["Branch loader<br/>[loader.py]"]
  node_attributions["Attribution maps<br/>[attributions.py]"]
  node_case_selection["Case selection<br/>[case_selection.py]"]
  node_mapping["Descriptor mapping<br/>[recplot_mapping.py]"]
  node_sanity["Sanity checks<br/>[sanity_check.py]"]
  node_aggregation["Seed aggregation"]
  node_threshold["Threshold analysis"]
  node_comparisons["Experiment comparisons"]
  node_xai_metrics["XAI metrics<br/>[xai_metrics.py]"]
  node_xai_results[("XAI results")]
end

node_medical(("Medical images"))

node_medical -->|"analyzes images"| node_feature_scripts
node_feature_scripts -->|"calls metrics"| node_feature_algorithms
node_feature_scripts -->|"calls variants"| node_metric_variants
node_feature_scripts -->|"calls metrics"| node_pmr_metrics
node_feature_scripts -->|"calls calculation"| node_lacunar
node_feature_scripts -.->|"writes descriptors"| node_descriptor_csv
node_descriptor_csv -->|"supplies vectors"| node_rp_build
node_rp_build -->|"uses encoding"| node_rp_transform
node_rp_build -->|"generates plots"| node_rp_images
node_rp_images -.->|"loads images"| node_data_loading
node_data_loading -.->|"applies transforms"| node_transforms
node_run_model -->|"runs training"| node_training
node_run_model -->|"loads samples"| node_data_loading
node_training -->|"builds batches"| node_data_loading
node_training -->|"creates model"| node_cnn
node_training -.->|"saves weights"| node_model_weights
node_run_model -->|"computes metrics"| node_evaluation
node_evaluation -.->|"records predictions"| node_predictions
node_xai_orchestrator -->|"loads branches"| node_branch_loader
node_branch_loader -->|"loads architecture"| node_cnn
node_branch_loader -->|"loads weights"| node_model_weights
node_xai_orchestrator -->|"selects cases"| node_case_selection
node_xai_orchestrator -->|"analyzes thresholds"| node_threshold
node_xai_orchestrator -->|"aggregates seeds"| node_aggregation
node_xai_orchestrator -->|"compares datasets"| node_comparisons
node_xai_orchestrator -->|"runs checks"| node_sanity
node_xai_orchestrator -->|"exports metrics"| node_xai_metrics
node_threshold -->|"selects examples"| node_case_selection
node_threshold -->|"loads models"| node_branch_loader
node_threshold -.->|"generates maps"| node_attributions
node_aggregation -->|"loads models"| node_branch_loader
node_aggregation -->|"generates maps"| node_attributions
node_sanity -->|"loads models"| node_branch_loader
node_sanity -->|"tests maps"| node_attributions
node_comparisons -->|"uses mapping"| node_mapping
node_comparisons -->|"aggregates seeds"| node_aggregation
node_xai_orchestrator -->|"writes analyses"| node_xai_results

click node_feature_algorithms "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/clustperc.py"
click node_metric_variants "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/clustpercEucl.py"
click node_pmr_metrics "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/pmr.py"
click node_lacunar "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/lacunaridade.py"
click node_feature_scripts "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/ScriptPercLACDF3Distances.py"
click node_rp_build "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/representations/create_representations.py"
click node_rp_transform "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/representations/RP.py"
click node_data_loading "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/dataset.py"
click node_transforms "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/utils.py"
click node_cnn "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/model.py"
click node_training "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/train.py"
click node_run_model "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/run.py"
click node_evaluation "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/metrics.py"
click node_xai_orchestrator "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/run_analise_completa.py"
click node_branch_loader "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/loader.py"
click node_attributions "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/attributions.py"
click node_case_selection "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/case_selection.py"
click node_mapping "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/recplot_mapping.py"
click node_sanity "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/sanity_check.py"
click node_aggregation "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/seed_aggregation.py"
click node_threshold "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/threshold_analysis.py"
click node_comparisons "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/comparacao_datasets.py"
click node_xai_metrics "https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/xai_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_feature_algorithms,node_metric_variants,node_pmr_metrics,node_lacunar,node_feature_scripts,node_descriptor_csv toneBlue
class node_rp_build,node_rp_transform,node_rp_images toneAmber
class node_data_loading,node_transforms,node_cnn,node_training,node_run_model,node_evaluation,node_model_weights,node_predictions toneMint
class node_xai_orchestrator,node_branch_loader,node_attributions,node_case_selection,node_mapping,node_sanity,node_aggregation,node_threshold,node_comparisons,node_xai_metrics,node_xai_results toneRose
class node_medical toneIndigo
```

## Components

### Fractal features

- [Percolation metrics](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/clustperc.py): `extract_fractal_features/clustperc.py`
- [Distance variants](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/clustpercEucl.py): `extract_fractal_features/clustpercEucl.py`
- [PMR distances](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/pmr.py): `extract_fractal_features/pmr.py`
- [Lacunarity](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/lacunaridade.py): `extract_fractal_features/lacunaridade.py`
- [Feature scripts](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/extract_fractal_features/ScriptPercLACDF3Distances.py): `extract_fractal_features/ScriptPercLACDF3Distances.py`
- **Descriptor CSVs**

### RP representations

- [RP generation](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/representations/create_representations.py): `representations/create_representations.py`
- [RP encoding](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/representations/RP.py): `representations/RP.py`
- **Recurrence plots**

### CNN classification

- [Image datasets](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/dataset.py): `model/dataset.py`
- [Input transforms](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/utils.py): `model/utils.py`
- [CNN architectures](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/model.py): `model/model.py`
- [K-fold training](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/train.py): `model/train.py`
- [Model runner](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/run.py): `model/run.py`
- [Evaluation metrics](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/model/metrics.py): `model/metrics.py`
- **Model weights**
- **Predictions**

### XAI analysis

- [XAI orchestration](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/run_analise_completa.py): `xai/run_analise_completa.py`
- [Branch loader](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/loader.py): `xai/loader.py`
- [Attribution maps](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/attributions.py): `xai/attributions.py`
- [Case selection](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/case_selection.py): `xai/case_selection.py`
- [Descriptor mapping](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/recplot_mapping.py): `xai/recplot_mapping.py`
- [Sanity checks](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/sanity_check.py): `xai/sanity_check.py`
- [Seed aggregation](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/seed_aggregation.py): `xai/seed_aggregation.py`
- [Threshold analysis](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/threshold_analysis.py): `xai/threshold_analysis.py`
- [Experiment comparisons](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/comparacao_datasets.py): `xai/comparacao_datasets.py`
- [XAI metrics](https://github.com/danielbgoncalves/percolation_based_rp_for_xai/blob/main/xai/xai_metrics.py): `xai/xai_metrics.py`
- **XAI results**

### Other components

- **Medical images**

## Connections

- Medical images → Feature scripts: analyzes images (evidence: `README.md`)
- Feature scripts → Percolation metrics: calls metrics (evidence: `extract_fractal_features/ScriptPercLACDF3Distances.py`)
- Feature scripts → Distance variants: calls variants (evidence: `extract_fractal_features/ScriptPercLACDF3Distances.py`)
- Feature scripts → PMR distances: calls metrics (evidence: `extract_fractal_features/ScriptPercLACDF3Distances.py`)
- Feature scripts → Lacunarity: calls calculation (evidence: `extract_fractal_features/ScriptPercLACDF3Distances.py`)
- Feature scripts → Descriptor CSVs: writes descriptors
- Descriptor CSVs → RP generation: supplies vectors (evidence: `README.md`)
- RP generation → RP encoding: uses encoding (evidence: `representations/create_representations.py`)
- RP generation → Recurrence plots: generates plots (evidence: `README.md`)
- Recurrence plots → Image datasets: loads images
- Image datasets → Input transforms: applies transforms
- Model runner → K-fold training: runs training (evidence: `model/run.py`)
- Model runner → Image datasets: loads samples (evidence: `model/run.py`)
- K-fold training → Image datasets: builds batches (evidence: `model/train.py`)
- K-fold training → CNN architectures: creates model (evidence: `model/train.py`)
- K-fold training → Model weights: saves weights
- Model runner → Evaluation metrics: computes metrics (evidence: `model/run.py`)
- Evaluation metrics → Predictions: records predictions
- XAI orchestration → Branch loader: loads branches (evidence: `xai/run_analise_completa.py`)
- Branch loader → CNN architectures: loads architecture (evidence: `xai/loader.py`)
- Branch loader → Model weights: loads weights (evidence: `xai/loader.py`)
- XAI orchestration → Case selection: selects cases (evidence: `xai/run_analise_completa.py`)
- XAI orchestration → Threshold analysis: analyzes thresholds (evidence: `xai/run_analise_completa.py`)
- XAI orchestration → Seed aggregation: aggregates seeds (evidence: `xai/run_analise_completa.py`)
- XAI orchestration → Experiment comparisons: compares datasets (evidence: `xai/run_analise_completa.py`)
- XAI orchestration → Sanity checks: runs checks (evidence: `xai/run_analise_completa.py`)
- XAI orchestration → XAI metrics: exports metrics (evidence: `xai/run_analise_completa.py`)
- Threshold analysis → Case selection: selects examples (evidence: `xai/threshold_analysis.py`)
- Threshold analysis → Branch loader: loads models (evidence: `xai/threshold_analysis.py`)
- Threshold analysis → Attribution maps: generates maps (evidence: `xai/threshold_analysis.py`)
- Seed aggregation → Branch loader: loads models (evidence: `xai/seed_aggregation.py`)
- Seed aggregation → Attribution maps: generates maps (evidence: `xai/seed_aggregation.py`)
- Sanity checks → Branch loader: loads models (evidence: `xai/sanity_check.py`)
- Sanity checks → Attribution maps: tests maps (evidence: `xai/sanity_check.py`)
- Experiment comparisons → Descriptor mapping: uses mapping (evidence: `xai/comparacao_datasets.py`)
- Experiment comparisons → Seed aggregation: aggregates seeds (evidence: `xai/comparacao_datasets.py`)
- XAI orchestration → XAI results: writes analyses (evidence: `README.md`)
