BirkhoffVisο
Status: π’ Active
Language: Python
Category: Research Software
Repository: https://github.com/st7ma784/birkhoff_visualizer
Overviewο
Mathematical conceptual ML view
Key Featuresο
Demo GraphML
WEB UI
docker
Recent Activityο
Last Commit: 2025-09-08 by Steve Mander
Commit: 10770dcd - fx
Repository Documentationο
Birkhoff Polytope Visualizerο
This is a lightweight web interface for visualizing doubly stochastic matrices and permutation matrices, which form the Birkhoff polytope - a convex polytope whose vertices are the permutation matrices.
The application now includes three main components:
Matrix Heatmap View - Visualizes matrices as heatmaps with value annotations
Graph View - Interactive graph visualization showing the navigable structure of the Birkhoff polytope
ML Experiment - Reinforcement learning experiment using PPO to solve the Linear Sum Assignment problem
Featuresο
Matrix Heatmap Viewο
Generate random matrices and project them onto the Birkhoff polytope using Sinkhorn iterations
Create permutation matrices (vertices of the Birkhoff polytope)
Generate convex combinations of permutation matrices
Project custom matrices onto the Birkhoff polytope
Visualize matrices as heatmaps with value annotations
Display row and column sums to verify doubly stochastic properties
Graph Viewο
Interactive visualization of mathematical structures as graphs using D3.js
Two visualization modes toggleable in the interface:
Birkhoff Polytope Mode: Visualizes the Birkhoff polytope as a Cayley graph
Nodes represent permutation matrices (vertices of the polytope)
Edges connect permutations that differ by a single transposition
Click on nodes to visualize the corresponding permutation matrix
Detailed analysis of row/column overlaps and intersections
Assignment Lattice Mode: Visualizes the constraint structure of matrix assignments
Nodes represent matrix positions (i,j)
Edges connect positions that share the same row or column
Shows how assignments block other values in their row/column
ML Experimentο
Reinforcement learning solution to the Linear Sum Assignment problem using Proximal Policy Optimization (PPO)
Environment treats each permutation of assignments as a vertex in a graph, with edges between permutations differing by exactly 2 assignments
Agent learns to traverse the graph to find optimal assignment solutions
Enhanced with early stopping, layer normalization, and dropout for better training stability
Action space pruning implemented to address factorial growth bottleneck for larger matrices
Solution quality comparison with Hungarian algorithm for benchmarking
Detailed agent logging and graph traversal visualization for interpretability
Weights & Biases integration for experiment tracking
Requirementsο
Python 3.7+
PyTorch
NumPy
Matplotlib
Flask
PyTorch Lightning
SciPy
Weights & Biases
Installationο
Install the required packages:
pip install -r requirements.txt
For the ML experiment, additional dependencies are required:
pip install pytorch-lightning wandb scipy
Usageο
Web Interfaceο
Run the Flask application:
python app.py
Open your browser and navigate to
http://localhost:5001For the matrix heatmap view, use the controls to generate different types of matrices:
Random Matrix: Creates a random matrix and projects it onto the Birkhoff polytope
Permutation Matrix: Generates a permutation matrix (vertex of the polytope)
Convex Combination: Creates a doubly stochastic matrix as a combination of permutation matrices
You can also enter custom matrix values in the text area and project them onto the Birkhoff polytope.
Navigate to
http://localhost:5001/graphto access the interactive graph visualization.In the graph view, you can:
Select matrix size (2-5) for visualization
Toggle between Birkhoff Polytope and Assignment Lattice modes
Generate the graph with the βGenerate Graphβ button
Drag nodes to reposition them in the visualization
Click nodes to view detailed information in the matrix view
Switch between graph and matrix views using the toggle buttons
ML Experimentο
Navigate to the ML directory:
cd ML
Run the training script with desired hyperparameters:
python train.py --matrix_size 4 --epochs 50 --lr 3e-4 --gamma 0.99 --epsilon 0.2 --entropy_coef 0.01 --value_coef 0.5 --update_timesteps 20
The experiment will automatically log to Weights & Biases and save checkpoints.
View the results and metrics in the console output or on the W&B dashboard.
Understanding the Birkhoff Polytopeο
The Birkhoff polytope B_n is the set of all nΓn doubly stochastic matrices (matrices with non-negative entries where each row and column sums to 1).
Key properties:
It has n! vertices, each corresponding to a permutation matrix
Any doubly stochastic matrix can be represented as a convex combination of permutation matrices (Birkhoff-von Neumann theorem)
The visualization shows how matrices relate to this polytope structure
Quick Startο
# Clone the repository
git clone https://github.com/st7ma784/birkhoff_visualizer
cd BirkhoffVis
# Install dependencies (if requirements.txt exists)
pip install -r requirements.txt
# Or install in development mode
pip install -e .
Linksο
Repository: https://github.com/st7ma784/birkhoff_visualizer
This page is automatically generated from the repository. Last updated: 2025-09-16