# paudan/scikit-roughsets architecture

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

- Interactive diagram: https://gitdiagram.com/paudan/scikit-roughsets
- Repository: https://github.com/paudan/scikit-roughsets

## Overview

##### Project type and purpose (what you’re diagramming)
This repository is a **Python library** (not a service/app) that implements a **Rough Sets feature reduction / feature selection algorithm**, with an API that integrates with **scikit-learn-style transformers/selectors**.

Evidence:
- `scikit_roughsets/` is a small importable package.
- README shows usage identical to scikit-learn feature selection: `selector.fit(X, y).transform(X)`.
- Core “product” is an algorithmic pipeline (data in → reduction → selected features out), plus packaging/testing/CI.

##### File tree-based architecture decomposition (main components)
Top-level:
- **Library package**
- `scikit_roughsets/__init__.py` — package export surface (what users import)
- `scikit_roughsets/roughsets.py` — likely the core rough set computations
- `scikit_roughsets/rs_reduction.py` — scikit-learn integration layer (selector class)
- `scikit_roughsets/rs_reduction.py` + `roughsets.py` likely call into:
- `scikit_roughsets/rs_reduction.py` depends on numpy + sklearn base classes/patterns
- `scikit_roughsets/rs_reduction.py` uses functions in `roughsets.py` (algorithm)
- `scikit_roughsets/rs_reduction.py` may also use `rs_reduction.py` or `rs_reduction` uses `rs_reduction`? (file naming suggests it contains the reduction logic; actual core reduction might be in `roughsets.py` with helper routines elsewhere)
- **Tests**
- `tests/tests.py` — pytest-based verification of correctness; acts as executable examples of expected behavior.
- **Packaging / Distribution**
- `setup.py`, `setup.cfg` — packaging metadata and install configuration.
- **CI**
- `.travis.yml`
- `.github/workflows/python-package.yml`

Key behavioral/contract details to capture:
- **Inputs:** `X` must be an **integer matrix**, `y` must be an **integer array**
- **No NaN support:** preprocessing required (implies dependency on upstream preprocessing steps)
- **Usage pattern:** `RoughSetsSelector.fit(X, y).transform(X)` (scikit-learn transformer interface)
- **Dependency context:** integrates with scikit-learn; uses numpy arrays

These are important because, for a library, the “architecture” is heavily defined by:
- public API boundary
- data contracts
- algorithm pipeline stages
- external dependencies

##### Consumer / Host Application
- “User code / Notebook / sklearn Pipeline”
- Shows where `RoughSetsSelector` is instantiated and invoked.

##### Public API layer
- `RoughSetsSelector` in `scikit_roughsets/rs_reduction.py`
- It explicitly as **scikit-learn-style Estimator/Transformer** (Fit/Transform).

##### Core algorithm layer
- `scikit_roughsets/roughsets.py` (core rough set computations)
- Indiscernibility relation / equivalence class computation
- Lower/upper approximations
- Dependency degree / significance of attributes
- Reduct computation (feature subset selection)

##### Data / Types boundary
- Numpy `ndarray` (`X`, `y`)
- Optional upstream preprocessing component: “Discretizer / Imputer / Encoder” (external to this repo but critical for real use)

##### External libraries
- `numpy`
- `scikit-learn` (base classes, estimator API; possibly `BaseEstimator`, `TransformerMixin`)

##### Verification
- `tests/tests.py` (pytest)
- This component depends on the library API and asserts correctness.

##### Packaging & CI
- Packaging: `setup.py`, `setup.cfg`
- CI: GitHub Actions workflow + Travis config
- These are not runtime components, but are part of the “system” that delivers the library.

##### RoughSetsSelector.transform(X) → returns X_selected

Data contract / preprocessing:
- **User preprocessing → provides int, no-NaN X/y → Selector**
- Sklearn Pipeline integration:
- “Pipeline[Preprocess → RoughSetsSelector → Model]”

Dependencies:
- `rs_reduction.py` → `numpy`
- `rs_reduction.py` → `scikit-learn`
- `roughsets.py` → `numpy` (likely)
- `tests/tests.py` → `pytest` + library

Build & delivery:
- “CI (Travis / GitHub Actions) → runs pytest”
- “Packaging (setup.py/cfg) → publishes installable artifact”
- “pip install … → installs scikit_roughsets package”

##### Architectural patterns / design principles used
- **Adapter / integration layer**: `RoughSetsSelector` adapts the algorithm to sklearn’s estimator interface.
- **Separation of concerns**:
- algorithmic core (`roughsets.py`)
- sklearn-facing wrapper (`rs_reduction.py`)
- tests separate from source
- **Functional core + OO wrapper** (common in scientific Python)

##### Relevant technologies/frameworks
- Python package: `scikit_roughsets`
- Numpy arrays for data
- scikit-learn estimator API (fit/transform)
- pytest for tests
- GitHub Actions / Travis for CI
- setuptools (setup.py/setup.cfg) for packaging

##### Don’t overthink it: separate into as many components as possible (for maximum detail)
- `RoughSetsSelector` class (public API node)
- “Input validator / preconditions” node
- “Reduct computation” node
- “Selected feature application (transform)” node
- Tests + CI + packaging nodes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% Context / Consumer Layer
    %% =========================
    User["User code / Notebook / sklearn Pipeline"]:::external
    Preproc["Upstream preprocessing (external)\n- Discretizer / Encoder / Imputer\n- Ensures int-only, no-NaN"]:::external
    DataContract["Data contract\nX: integer matrix (numpy ndarray)\ny: integer array\nNo NaN supported"]:::note
    Out["Output\nX_selected (numpy ndarray)\n+ selected feature indices/mask"]:::data

    User -->|"builds_pipeline"| Preproc
    Preproc -->|"preconditions"| DataContract
    DataContract -->|"feeds_X_y"| Selector

    %% =========================
    %% Library (scikit_roughsets)
    %% =========================
    subgraph "Library: scikit_roughsets (Python package)"
        Init["__init__.py\nPublic exports / import surface"]:::module

        subgraph "Public API (sklearn adapter layer)"
            Selector["RoughSetsSelector\nEstimator/Transformer\nfit(X,y) + transform(X)"]:::api
            FitStage["fit(X, y)\n- validate inputs\n- compute reduct"]:::stage
            TransformStage["transform(X)\n- apply selected subset"]:::stage
            Selector -->|"implements"| FitStage
            Selector -->|"implements"| TransformStage
        end

        subgraph "Core algorithm (rough sets)"
            Core["roughsets.py\nCore rough set computations"]:::module
            EqClasses["Indiscernibility / equivalence classes"]:::algo
            Approximations["Lower & upper approximations"]:::algo
            Significance["Dependency degree / attribute significance"]:::algo
            Reduct["Reduct computation\n(iterative subset selection)"]:::algo

            Core -->|"computes"| EqClasses
            EqClasses -->|"drives"| Approximations
            Approximations -->|"enables"| Significance
            Significance -->|"guides"| Reduct
        end

        FitStage -->|"invokes_reduction_algorithm"| Core
        Reduct -->|"returns_indices_or_mask"| FitStage
        TransformStage -->|"outputs"| Out
        FitStage -->|"stores_selected_features"| TransformStage
    end

    User -->|"calls_fit"| Selector
    User -->|"calls_transform"| Selector
    Selector -->|"returns"| Out

    %% =========================
    %% External dependencies
    %% =========================
    Numpy["numpy\nndarray + numeric ops"]:::external
    Sklearn["scikit-learn\nBaseEstimator / Transformer API"]:::external

    Selector -.->|"depends_on"| Sklearn
    Selector -.->|"depends_on"| Numpy
    Core -.->|"depends_on"| Numpy

    %% =========================
    %% Tests
    %% =========================
    subgraph "Verification"
        TestsInit["tests/__init__.py"]:::module
        Pytest["pytest"]:::external
        Tests["tests/tests.py\ncorrectness + usage examples"]:::test
        TestsInit -->|"package_init"| Tests
        Pytest -->|"runs"| Tests
        Tests -->|"calls_fit_transform"| Selector
        Tests -->|"validates_algorithm"| Core
    end

    %% =========================
    %% Build / CI / Release
    %% =========================
    subgraph "Build & Delivery (dev-time)"
        Readme["README.rst\nUsage docs + API contract\n(int-only, no-NaN)"]:::doc
        SetupPy["setup.py\nsetuptools packaging entrypoint"]:::build
        SetupCfg["setup.cfg\npackage metadata/config"]:::build

        Travis[".travis.yml\nCI (legacy)"]:::ci
        GHA["GitHub Actions\npython-package workflow"]:::ci

        SetupPy -.->|"builds_wheel/sdist"| Init
        SetupCfg -.->|"configures"| SetupPy
        Readme -.->|"documents"| Selector

        Travis -.->|"runs_pytest"| Tests
        GHA -.->|"runs_pytest"| Tests
    end

    %% =========================
    %% Legend
    %% =========================
    subgraph "Legend"
        L1["Solid arrows: runtime calls/data flow"]:::note
        L2["Dashed arrows: build/dev-time dependencies"]:::note
    end

    %% =========================
    %% Click events (from mapping)
    %% =========================
    click Init "https://github.com/paudan/scikit-roughsets/blob/master/scikit_roughsets/__init__.py"
    click Selector "https://github.com/paudan/scikit-roughsets/blob/master/scikit_roughsets/rs_reduction.py"
    click Core "https://github.com/paudan/scikit-roughsets/blob/master/scikit_roughsets/roughsets.py"
    click Tests "https://github.com/paudan/scikit-roughsets/blob/master/tests/tests.py"
    click TestsInit "https://github.com/paudan/scikit-roughsets/blob/master/tests/__init__.py"
    click SetupPy "https://github.com/paudan/scikit-roughsets/blob/master/setup.py"
    click SetupCfg "https://github.com/paudan/scikit-roughsets/blob/master/setup.cfg"
    click Travis "https://github.com/paudan/scikit-roughsets/blob/master/.travis.yml"
    click GHA "https://github.com/paudan/scikit-roughsets/blob/master/.github/workflows/python-package.yml"
    click Readme "https://github.com/paudan/scikit-roughsets/blob/master/README.rst"

    %% =========================
    %% Styles
    %% =========================
    classDef external fill:#F3F4F6,stroke:#6B7280,stroke-width:1px,color:#111827;
    classDef module fill:#DBEAFE,stroke:#2563EB,stroke-width:1px,color:#0B1B3A;
    classDef api fill:#DCFCE7,stroke:#16A34A,stroke-width:2px,color:#052E12;
    classDef stage fill:#ECFDF5,stroke:#22C55E,stroke-width:1px,color:#052E12;
    classDef algo fill:#FFEDD5,stroke:#F97316,stroke-width:1px,color:#3B1D0B;
    classDef test fill:#FCE7F3,stroke:#DB2777,stroke-width:1px,color:#3B0A1E;
    classDef ci fill:#EDE9FE,stroke:#7C3AED,stroke-width:1px,color:#1F1147;
    classDef build fill:#E0F2FE,stroke:#0284C7,stroke-width:1px,color:#06243A;
    classDef doc fill:#FEF9C3,stroke:#CA8A04,stroke-width:1px,color:#3A2A06;
    classDef data fill:#D1FAE5,stroke:#059669,stroke-width:1px,color:#052E2B;
    classDef note fill:#FFFFFF,stroke:#9CA3AF,stroke-dasharray:4 3,stroke-width:1px,color:#111827;
```
