https://github.com/benami171/financial_algos-ex_09
https://github.com/benami171/financial_algos-ex_09
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/benami171/financial_algos-ex_09
- Owner: benami171
- Created: 2025-05-21T15:33:36.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-05-21T15:38:07.000Z (5 months ago)
- Last Synced: 2025-06-29T07:42:12.465Z (4 months ago)
- Language: Python
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Birkhoff Decomposition Demo
A small Python module to perform and visualize the Birkhoff decomposition of any doubly‑stochastic matrix.
## Requirements
* Python 3.7+
* NumPy
* NetworkX
* MatplotlibYou can install dependencies with:
```bash
pip install numpy networkx matplotlib
```## Usage
1. Clone or download this repository.
2. Open a terminal in the project folder.
3. Run the demo script:
```bash
python Q_2.py
```4. The script will pop up a series of plots—one per iteration—showing the residual bipartite graph, the extracted matching (in red), and edge weights.
## Custom Matrix
To decompose your own matrix:
* Edit the `A` variable at the bottom of `Q_2.py` with your $n \times n$ doubly‑stochastic matrix (rows and columns sum to 1).
* Rerun the script.```python
# example 4×4 matrix
a = np.array([
[0.25, 0.25, 0.25, 0.25],
[0.40, 0.10, 0.30, 0.20],
[0.20, 0.30, 0.40, 0.10],
[0.15, 0.35, 0.25, 0.25]
])
demonstrate_birkhoff(a)
```## Notes
* If your matrix isn’t exactly doubly‑stochastic (within a small tolerance), the script will print a **bold red** warning.
---