# aicip/mvcnmf-python architecture

> Architecture diagram of the GitHub repository aicip/mvcnmf-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aicip/mvcnmf-python
- Repository: https://github.com/aicip/mvcnmf-python

## Overview

##### Project Type and Purpose
- The MVCNMF project is a research and experimental tool implementing an unsupervised endmember extraction algorithm based on Minimum Volume Constrained Non-negative Matrix Factorization (NMF). The main goal is to handle highly mixed image data.
- The project is implemented in Python and includes several scripts for algorithm implementation, testing, and visualization, along with Jupyter notebooks for interactive data processing.

##### Analyzing the File Structure
- Top-level files include several Python scripts (e.g., conjugate.py, mvcnmf.py, nmf_test.py, steepdescent.py, vca.py, getSynData.py) that represent different parts or variants of the algorithm.
- The presence of the inputs directory with .mat files (A.mat, BANDS.mat) indicates where the necessary input data is stored.
- The conda environment config (env.yml) encapsulates the project’s dependencies and is key for replication.
- A README and LICENSE provide context and attribution, while the .gitignore hints at version control practices.

##### Main Components of the System
a. Environment Setup:
- Conda environment (env.yml) to ensure the correct dependencies.
b. Data Inputs:
- The inputs directory containing data files (A.mat, BANDS.mat).
c. Algorithm Modules:
- Core algorithm implementation is in mvcnmf.py.
- Supporting algorithmic scripts include conjugate.py, steepdescent.py, and vca.py (likely used for initialization or alternative optimization strategies).
- getSynData.py may be used for generating synthetic datasets for testing.
d. Testing & Execution:
- nmf_test.py is the main driver script used to execute the algorithm.
e. Data Processing and Visualization:

##### Relationships and Interactions
- The environment setup (env.yml) is foundational and is used to run any of the scripts.
- Data flows from the “inputs” directory into the algorithm modules.
- The nmf_test.py script acts as the central orchestrator, invoking various computation modules (mvcnmf.py for the core algorithm, with helper functions possibly spread across conjugate.py, steepdescent.py, and vca.py).
- The results produced from the algorithm may then be used in interactive notebooks for analysis and visualization.
- getSynData.py, if used, generates synthetic data that can be combined with real data in the workflow.

##### Architectural Patterns and Design Principles
- Input/Data Layer (inputs directory)
- Processing Layer (algorithm scripts performing data manipulation, factorization, and optimization)
- Output/Visualization Layer (notebooks for result analysis)
- The design follows a procedural experimental structure where each component has a specific role (data ingestion, algorithm computation, and output visualization).

##### Elements
- Use clear labels for each component:
- “Environment Setup” (env.yml configuration)
- “Data Input Layer” (inputs: A.mat, BANDS.mat)
- “Algorithm Core” (mvcnmf.py, conjugate.py, steepdescent.py, vca.py)
- “Test Execution” (nmf_test.py)
- (Optionally) “Synthetic Data Generator” (getSynData.py)
- Data moving from the “Data Input Layer” into the “Algorithm Core.”
- The “Algorithm Core” output flowing into the “Visualization/Analysis” components.
- The environment layer influencing all script executions.
- Orchestration/testing scripts (another styling)
- Interactive notebooks (again, a different visual style)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Environment Setup
    subgraph "Environment Setup"
        ENV("Environment Setup"):::env
    end

    %% Data Input Layer
    subgraph "Data Input Layer"
        INPUTS("Inputs Folder (A.mat, BANDS.mat)"):::data
    end

    %% Synthetic Data Generator
    subgraph "Synthetic Data Generation"
        SYN("Synthetic Data Generator"):::synthetic
    end

    %% Test Execution / Orchestration
    subgraph "Execution Driver"
        TEST("Test Execution (nmf_test.py)"):::exec
    end

    %% Algorithm Core
    subgraph "Algorithm Core"
        CORE("Core Algorithm (mvcnmf.py)"):::algo
        CONJ("Supporting Module (conjugate.py)"):::algo
        SD("Supporting Module (steepdescent.py)"):::algo
        VCA("Supporting Module (vca.py)"):::algo
    end

    %% Data Visualization and Analysis
    subgraph "Data Visualization/Analysis"
        NOTE1("Notebook (fix_data.ipynb)"):::vis
        NOTE2("Notebook (visualize.ipynb)"):::vis
    end

    %% Relationships and Flows
    ENV -->|"sets environment"| TEST
    INPUTS -->|"provides data"| TEST
    SYN -->|"generates synthetic data"| TEST
    TEST -->|"orchestrates"| CORE
    CORE -->|"uses"| CONJ
    CORE -->|"uses"| SD
    CORE -->|"uses"| VCA
    CORE -->|"outputs results"| NOTE1
    CORE -->|"outputs results"| NOTE2

    %% Click Events
    click ENV "https://github.com/aicip/mvcnmf-python/blob/master/env.yml"
    click INPUTS "https://github.com/aicip/mvcnmf-python/tree/master/inputs"
    click SYN "https://github.com/aicip/mvcnmf-python/blob/master/getSynData.py"
    click TEST "https://github.com/aicip/mvcnmf-python/blob/master/nmf_test.py"
    click CORE "https://github.com/aicip/mvcnmf-python/blob/master/mvcnmf.py"
    click CONJ "https://github.com/aicip/mvcnmf-python/blob/master/conjugate.py"
    click SD "https://github.com/aicip/mvcnmf-python/blob/master/steepdescent.py"
    click VCA "https://github.com/aicip/mvcnmf-python/blob/master/vca.py"
    click NOTE1 "https://github.com/aicip/mvcnmf-python/blob/master/fix_data.ipynb"
    click NOTE2 "https://github.com/aicip/mvcnmf-python/blob/master/visualize.ipynb"

    %% Styles
    classDef env fill:#a3c4dc,stroke:#1a6e8b,stroke-width:2px;
    classDef data fill:#c3e6cb,stroke:#155724,stroke-width:2px;
    classDef synthetic fill:#d6bbd6,stroke:#7a3175,stroke-width:2px;
    classDef exec fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef algo fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef vis fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
