# wt-hu/pycausalfs architecture

> Architecture diagram of the GitHub repository wt-hu/pycausalfs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wt-hu/pycausalfs
- Repository: https://github.com/wt-hu/pycausalfs

## Overview

##### Project type and purpose
- This is a pure‐Python open‐source library (not a web or client/server app) for causality‐based feature selection and Bayesian network learning.
- Its goal is to implement 30 representative causality‐based feature selection methods plus local/global BN structure learning, offering a common API to experiment, compare, extend, and integrate new algorithms.

##### File structure
Top‐level:
- README.md, manual‐pyCausalFS.pdf, UPDATELOG.md (docs)
- pyCausalFS/ (main package)
- pyBN/ (standalone Bayes‐net toolkit subpackage)
Under pyCausalFS/:
- CBD/ – Constraint‐based MB & PC learning (modules: MBs, data, example, output, evaluation scripts)
- GSL/ – Global‐structure learning (GSBN, MMHC, etc.)
- LSL/ – Local‐structure learning (MB‐by‐MB, PCD‐by‐PCD, CMB)
- SSD/ – Score‐based MB & PC learning (S2TMB, SLL, plus embedded pyBN usage)
Common patterns:
- Each algorithm family has subfolders for its implementations (MBs or PC methods), a common sub‐package for statistics/tests, a data folder for sample graphs & CSV, and example/output scripts.
- pyBN is a full BN engine (classes, io, learning, inference, classification, plotting) that SSD, GSL, and LSL modules depend on for some routines.
- No frontend/backend or service separation—this is a library to be imported and called by user scripts.

##### README for additional insights
- The README outlines 7 algorithm categories (constraint‐based MB, multiple MB, constraint‐based PC, score‐based MB/PC, local BN, local‐to‐global BN).
- It calls out manual documentation for low‐level details.
- Core dependencies (e.g., NumPy, SciPy, pandas) are implied but not shown—assume these as external services.

##### Elements
- Algorithm modules (e.g., blue)
- Common utilities (green)
- Data & I/O (orange)
- External/dependency modules (gray)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External User
    User["User/Application"]:::external

    %% pyCausalFS Library
    subgraph "pyCausalFS Library"
        direction TB

        subgraph "Constraint-Based (CBD)"
            direction TB
            CBD_MB["MBs Submodule"]:::algorithm
            CBD_common["CBD Tests/Utilities"]:::utils
            CBD_data["CBD Data Samples"]:::data
            CBD_example["CBD Examples"]:::data
            CBD_output["CBD Outputs"]:::data
        end

        subgraph "Global-Structure Learning (GSL)"
            direction TB
            GSL_gsbn["GSBN Implementation"]:::algorithm
            GSL_mmhc["MMHC Algorithm"]:::algorithm
            GSL_common["GSL Common Utilities"]:::utils
            GSL_pc["P-C Script"]:::algorithm
        end

        subgraph "Local-Structure Learning (LSL)"
            direction TB
            LSL_mbs["MB-by-MB, PCD-by-PCD & CMB"]:::algorithm
            LSL_common["LSL Utilities"]:::utils
            LSL_data["LSL Data Samples"]:::data
            LSL_example["LSL Examples"]:::data
            LSL_eval1["eva_LSL.py"]:::data
            LSL_eval2["evaluation_LSLalgorithm.py"]:::data
            LSL_output["LSL Outputs"]:::data
        end

        subgraph "Score-Based Module (SSD)"
            direction TB
            SSD_mbs["Score-Based MBs"]:::algorithm
            SSD_common["SSD Utilities"]:::utils
            SSD_pybn["SSD Embedded pyBN"]:::algorithm
            SSD_data["SSD Data Samples"]:::data
            SSD_example["SSD Example Script"]:::data
            SSD_output["SSD Outputs"]:::data
        end
    end

    %% pyBN Engine
    subgraph "pyBN Engine"
        direction TB
        pyBN_classes["Core Classes"]:::bn
        pyBN_io["I/O Handlers"]:::bn
        pyBN_learn["Structure & Parameter Learning"]:::bn
        pyBN_inf["Inference Algorithms"]:::bn
        pyBN_clf["Classification & Feature Selection"]:::bn
        pyBN_plot["Plotting Utilities"]:::bn
        pyBN_utils["BN-specific Utilities"]:::utils
    end

    %% Dependencies
    ExternalDeps["External Libraries\n(NumPy, SciPy, Pandas, networkx)"]:::external

    %% Connections
    User -->|"calls API"| CBD_MB
    User -->|"calls API"| GSL_gsbn
    User -->|"calls API"| LSL_mbs
    User -->|"calls API"| SSD_mbs

    CBD_MB -->|"uses tests"| CBD_common
    CBD_MB -->|"loads data"| CBD_data
    CBD_MB -->|"runs MB alg"| CBD_output
    CBD_example -->|"demos"| CBD_MB

    GSL_gsbn -->|"uses utils"| GSL_common
    GSL_gsbn -->|"imports pyBN"| pyBN_learn
    GSL_mmhc -->|"imports pyBN"| pyBN_learn
    GSL_pc -->|"uses utils"| GSL_common

    LSL_mbs -->|"uses utils"| LSL_common
    LSL_mbs -->|"loads data"| LSL_data
    LSL_mbs -->|"runs alg"| LSL_output
    LSL_eval1 -->|"evaluation"| LSL_mbs
    LSL_eval2 -->|"evaluation"| LSL_mbs

    SSD_mbs -->|"uses utils"| SSD_common
    SSD_mbs -->|"loads data"| SSD_data
    SSD_pybn -->|"imports pyBN"| pyBN_learn
    SSD_mbs -->|"runs MB alg"| SSD_output
    SSD_example -->|"demos"| SSD_mbs

    %% Shared BN Utils
    pyBN_utils --> pyBN_classes
    pyBN_utils --> pyBN_io

    ExternalDeps --> CBD_MB
    ExternalDeps --> GSL_gsbn
    ExternalDeps --> LSL_mbs
    ExternalDeps --> SSD_mbs
    ExternalDeps --> pyBN_classes

    %% Click Events for Component Mapping
    click CBD_MB "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/CBD/MBs/"
    click CBD_common "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/CBD/MBs/common/"
    click CBD_data "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/CBD/data/"
    click CBD_example "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/CBD/example/"
    click CBD_output "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/CBD/output/"
    click GSL_gsbn "https://github.com/wt-hu/pycausalfs/blob/master/pyCausalFS/GSL/GSBN.py"
    click GSL_mmhc "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/GSL/MMHC/"
    click GSL_common "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/GSL/common/"
    click GSL_pc "https://github.com/wt-hu/pycausalfs/blob/master/pyCausalFS/GSL/P-C.py"
    click LSL_mbs "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/LSL/MBs/"
    click LSL_common "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/LSL/MBs/common/"
    click LSL_data "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/LSL/data/"
    click LSL_example "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/LSL/example/"
    click LSL_eval1 "https://github.com/wt-hu/pycausalfs/blob/master/pyCausalFS/LSL/eva_LSL.py"
    click LSL_eval2 "https://github.com/wt-hu/pycausalfs/blob/master/pyCausalFS/LSL/evaluation_LSLalgorithm.py"
    click LSL_output "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/LSL/output/"
    click SSD_mbs "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/SSD/MBs/"
    click SSD_common "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/SSD/MBs/common/"
    click SSD_pybn "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/SSD/MBs/pyBN/"
    click SSD_data "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/SSD/data/"
    click SSD_example "https://github.com/wt-hu/pycausalfs/blob/master/pyCausalFS/SSD/example/example_SSD.py"
    click SSD_output "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/SSD/output/"
    click pyBN_classes "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/pyBN/classes/"
    click pyBN_io "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/pyBN/io/"
    click pyBN_learn "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/pyBN/learning/"
    click pyBN_inf "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/pyBN/inference/"
    click pyBN_clf "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/pyBN/classification/"
    click pyBN_plot "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/pyBN/plotting/"
    click pyBN_utils "https://github.com/wt-hu/pycausalfs/tree/master/pyCausalFS/pyBN/utils/"

    %% Styles
    classDef algorithm fill:#D0E6FF,stroke:#000;
    classDef utils fill:#DFFFD0,stroke:#000;
    classDef data fill:#FFE0B2,stroke:#000;
    classDef bn fill:#E8E8E8,stroke:#000;
    classDef external fill:#CCCCCC,stroke:#000;
```
