# ryan112358/mbi architecture

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

- Interactive diagram: https://gitdiagram.com/ryan112358/mbi
- Repository: https://github.com/ryan112358/mbi

## Overview

MBI is a Python library for marginal-based graphical-model estimation and inference, with differential-privacy mechanisms and synthetic-data extensions. The main workflow is to define a discrete domain, provide marginal measurements, fit a model, then query its marginals or generate synthetic records. The graph also includes the documented alternative estimators and privacy mechanisms. Some mechanism implementations and core modules are represented from README and tree evidence only; their internal wiring is omitted where source excerpts do not establish it.

Main entry points: [`src/mbi/estimation.py`](https://github.com/ryan112358/mbi/blob/master/src/mbi/estimation.py) (Estimators), [`src/mbi/dataset.py`](https://github.com/ryan112358/mbi/blob/master/src/mbi/dataset.py) (Dataset), [`src/mbi/markov_random_field.py`](https://github.com/ryan112358/mbi/blob/master/src/mbi/markov_random_field.py) (Graphical model), [`src/mbi/marginal_oracles.py`](https://github.com/ryan112358/mbi/blob/master/src/mbi/marginal_oracles.py) (Marginal oracles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_represent["Data and measurements"]
  node_domain["Domain<br/>[domain.py]"]
  node_dataset["Dataset<br/>[dataset.py]"]
  node_measurements["Marginal measurements<br/>[marginal_loss.py]"]
  node_loss["Marginal loss<br/>[marginal_loss.py]"]
end

subgraph group_fit["Estimation and inference"]
  node_estimators["Estimators<br/>[estimation.py]"]
  node_factor["Factors and cliques<br/>[factor.py]"]
  node_oracle["Marginal oracles"]
  node_junction_tree["Junction tree<br/>[junction_tree.py]"]
end

subgraph group_results["Model outputs"]
  node_model["Graphical model"]
  node_synthetic["Synthetic generation<br/>[synthetic_data.py]"]
end

subgraph group_privacy["Private mechanisms"]
  node_aim["AIM<br/>[aim.py]"]
  node_jam["JAM<br/>[jam.py]"]
  node_mwem["MWEM + PGM<br/>[mwem+pgm.py]"]
  node_adaptive["Adaptive grid<br/>[adaptive_grid.py]"]
  node_mst["MST mechanism<br/>[mst.py]"]
  node_other_mechanisms["Other mechanisms<br/>[cdp2adp.py]"]
end

subgraph group_extensions["Extensions"]
  node_extension_estimators["Alternative estimators"]
  node_reweighted_estimator["Reweighted estimator"]
  node_message_extension["Message passing<br/>[message_passing.py]"]
  node_callbacks["Progress callbacks<br/>[callbacks.py]"]
  node_precompute["Precompute marginals"]
end

node_user(("Analyst"))

node_user -->|"defines domain"| node_domain
node_user -->|"provides measurements"| node_measurements
node_user -->|"selects estimator"| node_estimators
node_domain -->|"bounds fitting"| node_estimators
node_measurements -->|"construct loss"| node_loss
node_estimators -->|"builds objective"| node_loss
node_estimators -->|"requests marginals"| node_oracle
node_oracle -->|"uses schedules"| node_junction_tree
node_oracle -->|"computes factors"| node_factor
node_estimators -->|"returns fitted model"| node_model
node_model -->|"enables projection"| node_user
node_user -->|"chooses estimator"| node_extension_estimators
node_user -->|"chooses estimator"| node_reweighted_estimator
node_extension_estimators -->|"returns representation"| node_model
node_reweighted_estimator -->|"produces weighted data"| node_dataset
node_model -->|"generates records"| node_synthetic
node_synthetic -->|"returns synthetic data"| node_dataset
node_dataset -->|"supplies records"| node_precompute
node_precompute -->|"computes marginals"| node_factor
node_user -->|"configures progress"| node_callbacks
node_callbacks -.->|"observes progress"| node_estimators
node_user -->|"runs mechanism"| node_aim
node_user -->|"runs mechanism"| node_jam
node_user -->|"runs mechanism"| node_mwem
node_user -->|"runs mechanism"| node_adaptive
node_user -->|"runs mechanism"| node_mst
node_user -->|"runs mechanism"| node_other_mechanisms
node_dataset -->|"provides private data"| node_aim
node_dataset -->|"provides private data"| node_jam
node_dataset -->|"provides private data"| node_mwem
node_dataset -.->|"provides private data"| node_adaptive
node_aim -->|"fits model"| node_estimators
node_jam -->|"fits model"| node_estimators
node_mwem -->|"fits model"| node_estimators
node_adaptive -.->|"fits model"| node_estimators
node_message_extension -->|"computes messages"| node_factor

click node_domain "https://github.com/ryan112358/mbi/blob/master/src/mbi/domain.py"
click node_dataset "https://github.com/ryan112358/mbi/blob/master/src/mbi/dataset.py"
click node_measurements "https://github.com/ryan112358/mbi/blob/master/src/mbi/marginal_loss.py"
click node_loss "https://github.com/ryan112358/mbi/blob/master/src/mbi/marginal_loss.py"
click node_estimators "https://github.com/ryan112358/mbi/blob/master/src/mbi/estimation.py"
click node_extension_estimators "https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/mixture_of_products.py"
click node_reweighted_estimator "https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/reweighted_dataset.py"
click node_model "https://github.com/ryan112358/mbi/blob/master/src/mbi/markov_random_field.py"
click node_factor "https://github.com/ryan112358/mbi/blob/master/src/mbi/factor.py"
click node_oracle "https://github.com/ryan112358/mbi/blob/master/src/mbi/marginal_oracles.py"
click node_message_extension "https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/message_passing.py"
click node_junction_tree "https://github.com/ryan112358/mbi/blob/master/src/mbi/junction_tree.py"
click node_callbacks "https://github.com/ryan112358/mbi/blob/master/src/mbi/callbacks.py"
click node_synthetic "https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/synthetic_data.py"
click node_precompute "https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/precompute_marginals.py"
click node_aim "https://github.com/ryan112358/mbi/blob/master/mechanisms/aim.py"
click node_jam "https://github.com/ryan112358/mbi/blob/master/mechanisms/jam.py"
click node_mwem "https://github.com/ryan112358/mbi/blob/master/mechanisms/mwem%2Bpgm.py"
click node_adaptive "https://github.com/ryan112358/mbi/blob/master/mechanisms/adaptive_grid.py"
click node_mst "https://github.com/ryan112358/mbi/blob/master/mechanisms/mst.py"
click node_other_mechanisms "https://github.com/ryan112358/mbi/blob/master/mechanisms/cdp2adp.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_domain,node_dataset,node_measurements,node_loss toneBlue
class node_estimators,node_factor,node_oracle,node_junction_tree toneAmber
class node_model,node_synthetic toneMint
class node_aim,node_jam,node_mwem,node_adaptive,node_mst,node_other_mechanisms toneRose
class node_extension_estimators,node_reweighted_estimator,node_message_extension,node_callbacks,node_precompute,node_user toneIndigo
```

## Components

### Data and measurements

- [Domain](https://github.com/ryan112358/mbi/blob/master/src/mbi/domain.py): `src/mbi/domain.py`
- [Dataset](https://github.com/ryan112358/mbi/blob/master/src/mbi/dataset.py): `src/mbi/dataset.py`
- [Marginal measurements](https://github.com/ryan112358/mbi/blob/master/src/mbi/marginal_loss.py): `src/mbi/marginal_loss.py`
- [Marginal loss](https://github.com/ryan112358/mbi/blob/master/src/mbi/marginal_loss.py): `src/mbi/marginal_loss.py`

### Estimation and inference

- [Estimators](https://github.com/ryan112358/mbi/blob/master/src/mbi/estimation.py): `src/mbi/estimation.py`
- [Factors and cliques](https://github.com/ryan112358/mbi/blob/master/src/mbi/factor.py): `src/mbi/factor.py`
- [Marginal oracles](https://github.com/ryan112358/mbi/blob/master/src/mbi/marginal_oracles.py): `src/mbi/marginal_oracles.py`
- [Junction tree](https://github.com/ryan112358/mbi/blob/master/src/mbi/junction_tree.py): `src/mbi/junction_tree.py`

### Model outputs

- [Graphical model](https://github.com/ryan112358/mbi/blob/master/src/mbi/markov_random_field.py): `src/mbi/markov_random_field.py`
- [Synthetic generation](https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/synthetic_data.py): `src/mbi/extensions/synthetic_data.py`

### Private mechanisms

- [AIM](https://github.com/ryan112358/mbi/blob/master/mechanisms/aim.py): `mechanisms/aim.py`
- [JAM](https://github.com/ryan112358/mbi/blob/master/mechanisms/jam.py): `mechanisms/jam.py`
- [MWEM + PGM](https://github.com/ryan112358/mbi/blob/master/mechanisms/mwem%2Bpgm.py): `mechanisms/mwem+pgm.py`
- [Adaptive grid](https://github.com/ryan112358/mbi/blob/master/mechanisms/adaptive_grid.py): `mechanisms/adaptive_grid.py`
- [MST mechanism](https://github.com/ryan112358/mbi/blob/master/mechanisms/mst.py): `mechanisms/mst.py`
- [Other mechanisms](https://github.com/ryan112358/mbi/blob/master/mechanisms/cdp2adp.py): `mechanisms/cdp2adp.py`

### Extensions

- [Alternative estimators](https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/mixture_of_products.py): `src/mbi/extensions/mixture_of_products.py`
- [Reweighted estimator](https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/reweighted_dataset.py): `src/mbi/extensions/reweighted_dataset.py`
- [Message passing](https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/message_passing.py): `src/mbi/extensions/message_passing.py`
- [Progress callbacks](https://github.com/ryan112358/mbi/blob/master/src/mbi/callbacks.py): `src/mbi/callbacks.py`
- [Precompute marginals](https://github.com/ryan112358/mbi/blob/master/src/mbi/extensions/precompute_marginals.py): `src/mbi/extensions/precompute_marginals.py`

### Other components

- **Analyst**

## Connections

- Analyst → Domain: defines domain
- Analyst → Marginal measurements: provides measurements
- Analyst → Estimators: selects estimator
- Domain → Estimators: bounds fitting
- Marginal measurements → Marginal loss: construct loss
- Estimators → Marginal loss: builds objective
- Estimators → Marginal oracles: requests marginals
- Marginal oracles → Junction tree: uses schedules
- Marginal oracles → Factors and cliques: computes factors
- Estimators → Graphical model: returns fitted model
- Graphical model → Analyst: enables projection
- Analyst → Alternative estimators: chooses estimator
- Analyst → Reweighted estimator: chooses estimator
- Alternative estimators → Graphical model: returns representation
- Reweighted estimator → Dataset: produces weighted data
- Graphical model → Synthetic generation: generates records
- Synthetic generation → Dataset: returns synthetic data
- Dataset → Precompute marginals: supplies records
- Precompute marginals → Factors and cliques: computes marginals
- Analyst → Progress callbacks: configures progress
- Progress callbacks → Estimators: observes progress
- Analyst → AIM: runs mechanism
- Analyst → JAM: runs mechanism
- Analyst → MWEM + PGM: runs mechanism
- Analyst → Adaptive grid: runs mechanism
- Analyst → MST mechanism: runs mechanism
- Analyst → Other mechanisms: runs mechanism
- Dataset → AIM: provides private data
- Dataset → JAM: provides private data
- Dataset → MWEM + PGM: provides private data
- Dataset → Adaptive grid: provides private data
- AIM → Estimators: fits model
- JAM → Estimators: fits model
- MWEM + PGM → Estimators: fits model
- Adaptive grid → Estimators: fits model
- Message passing → Factors and cliques: computes messages
