|
| 1 | +<div align="center"> |
1 | 2 |
|
2 | | -#### **A comprehensive implementation of various Matrix Decomposition Techniques from the lens of Linear Algebra to produce efficient computing of SVD, PCA, Feature Selection & Data Analysis in Python.** |
3 | | -______________________________________________________________________ |
| 3 | +# Matrix Decomposition Implemenations |
4 | 4 |
|
5 | | -To gain a deeper understanding of how Orthogonalization & Matrices Decomposition works in real-life applications, & how they save bunch of time through an approach of vectorization, you'll find such techniques used in; |
| 5 | +**A hands-on marimo built, math-first implementations of Matrix Decomposition Functions,** |
| 6 | +**find the notebooks; hosting on molab & hf-spaces.** |
6 | 7 |
|
7 | | -- **📡 Signal Processing** |
8 | | -- **🤖 Control Systems and Robotics** |
9 | | -- **🖼️ Image Processing** |
10 | | -- **➗ Solving Linear Systems i.e. *AX = B*** |
| 8 | +<br/> |
11 | 9 |
|
12 | | -With certain mathematical intuitions (*having visual introspections*),this project simplifies most of the abstract concepts and becomes easier to grasp and connect with practical applications. |
| 10 | +[](https://molab.marimo.io/github/https://molab.marimo.io/notebooks/nb_TAVLehyiE58b5RDzjxFxSW/app) |
| 11 | +[](https://huggingface.co/spaces) |
| 12 | +[](https://www.python.org/) |
| 13 | +[](https://numpy.org/) |
| 14 | +[](https://opensource.org/licenses/Apache-2.0) |
13 | 15 |
|
14 | | - |
| 16 | +<img src=".assets/01.gif" alt="Matrix Decompositions Demo" width="620"/> |
15 | 17 |
|
16 | | -> You'll yet to see more implementations—such as **Householder Reflection**, **Bidiagonalization**, **LU Decomposition**, on this repo, and others—*these will be added soon*. |
| 18 | +</div> |
17 | 19 |
|
18 | | -## What's Inside |
| 20 | +## Table of Contents |
19 | 21 |
|
20 | | -*By latest ✨,* |
| 22 | + - [Overview](#overview) |
| 23 | + - [Marimo Apps](#marimo-apps) |
| 24 | + - [Quickstart](#quickstart) |
| 25 | + - [Implementation Notes](#implementation-notes) |
| 26 | + - [Contributing](#contributing) |
| 27 | + - [Resources \& Acknowledgements](#resources--acknowledgements) |
21 | 28 |
|
22 | | -The **Gram-Schmidt Orthogonalization** is one of the fundamental process in Linear Algebra to achieve *Orthonormal Vectors* for a given vector space. The Orthonormal Basis are produced by iteratively removing vector projections — also known as the *Vector Projection Elimination method*. |
23 | 29 |
|
24 | | -**Terms like Orthogonality, QR Decomposition are being discussed in the — [🗨️Discussion section](https://github.com/PragyanTiwari/Matrix-Decompositions-Implementation-for-SVD-PCA/discussions).** |
| 30 | +## Overview |
25 | 31 |
|
26 | | -Here's a snippet; |
| 32 | +A curated set of [marimo](https://marimo.io) notebooks based on **Matrix Decomposition** functions, written in Python, each pairing a mathematical derivation with annotated Python including an interactive visualization, inside a single reactive environment. |
| 33 | + |
| 34 | +The series is a progressive build, starting from orthogonalization fundamentals and working toward full matrix factorizations and applications: |
| 35 | + |
| 36 | +`Gram-Schmidt` → `QR` → `LU` → `Householder` → `SVD` → `PCA` |
| 37 | + |
| 38 | +> These functions reduce computationally expensive operations i.e. inversion, least squares, eigensolving, into sequences of simpler, numerically stable factors. |
| 39 | +
|
| 40 | +>> Applications such as **noise reduction, signal processing, image compression** and more will be covered as the series progresses. |
| 41 | +
|
| 42 | +## Marimo Apps |
| 43 | + |
| 44 | +| Notebook | Open in molab | Open in HF Spaces | |
| 45 | +|---|:---:|:---:| |
| 46 | +| **Gram-Schmidt Orthogonalization** | [](https://molab.marimo.io/notebooks/nb_TAVLehyiE58b5RDzjxFxSW/app) | [](https://huggingface.co/spaces) | |
| 47 | +| **QR Decomposition** | 🔜 | 🔜 | |
| 48 | +| **Householder Reflection & Bidiagonalization** | 🔜 | 🔜 | |
| 49 | + |
| 50 | +## Quickstart |
| 51 | + |
| 52 | +Requires Python `>= 3.12` and [`uv`](https://docs.astral.sh/uv/). |
| 53 | + |
| 54 | +**1. Clone and install dependencies** |
| 55 | + |
| 56 | +```bash |
| 57 | +git clone https://github.com/prgyn8/Matrix-Decomposition-Implementations.git |
| 58 | +uv sync |
| 59 | +``` |
| 60 | + |
| 61 | +**2. Run a marimo app**, (eg. gram-schmidt process) |
| 62 | + |
| 63 | +```bash |
| 64 | +uvx marimo run apps/gs_process.py # you can find the available notebooks in the apps directory. |
| 65 | +``` |
| 66 | + |
| 67 | +**3. Optionally, run a notebook in sandbox environment** |
27 | 68 |
|
28 | 69 | ```bash |
29 | | -def gs_Orthogonalization(X:np.ndarray)->np.ndarray: |
| 70 | +# Run the app |
| 71 | +uvx marimo run --sandbox apps/gs_process.py |
30 | 72 |
|
| 73 | +# Or open for editing |
| 74 | +uvx marimo edit --sandbox apps/gs_process.py |
| 75 | +``` |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Implementation Notes |
| 80 | + |
| 81 | +<details> |
| 82 | + |
| 83 | +<summary><strong>Gram-Schmidt Orthogonalization</strong></summary> |
| 84 | + |
| 85 | +<br/> |
| 86 | + |
| 87 | +```python |
| 88 | +## snippet from the notebook : https://molab.marimo.io/notebooks/nb_TAVLehyiE58b5RDzjxFxSW |
| 89 | +def gram_schmidt(X:np.ndarray)->np.ndarray: |
| 90 | + |
| 91 | + """ |
| 92 | + original -> orthogonal -> orthonormal |
| 93 | + args: |
| 94 | + A set of linearly independent vectors stored in columns in the array X. |
| 95 | + returns: |
| 96 | + Returns matrix Q of the shape of X, having orthonormal vectors for the given vectors. |
| 97 | + """ |
31 | 98 | Q = np.copy(X).astype("float64") |
32 | 99 | n_vecs = Q.shape[1] |
33 | 100 |
|
@@ -58,38 +125,50 @@ def gs_Orthogonalization(X:np.ndarray)->np.ndarray: |
58 | 125 | return Q |
59 | 126 | ``` |
60 | 127 |
|
61 | | -To run the notebook in a sandbox environment; |
62 | | -
|
63 | | -```bash |
64 | | -uvx marimo run --sandbox notebooks/Gram_Schmidt_QR_Decomposition.py |
| 128 | +```python |
| 129 | +# Verification: Q.T @ Q ≈ I |
| 130 | +A = np.array([[1, 0, 0], [2, 0, 3], [4, 5, 6]]).T |
| 131 | +assert np.allclose(gram_schmidt(A).T @ gram_schmidt(A), np.eye(3)) # ✓ |
65 | 132 | ``` |
66 | 133 |
|
67 | | -## 🧪 Testing |
| 134 | +> 💬 Questions on implementation or numerical stability? Start a thread in [Discussions](https://github.com/prgyn8/Matrix-Decomposition-Implementations/discussions). |
68 | 135 |
|
69 | | -The updates made on this project, can be tested for deployment, (and for personal experimentation) by the following; |
| 136 | +</details> |
70 | 137 |
|
71 | | -- Fork the repository. |
| 138 | +--- |
72 | 139 |
|
73 | | -- Run uv sync to install dependencies (*uv lockfile will help*) |
| 140 | +## Contributing |
74 | 141 |
|
75 | | -```bash |
76 | | -uv sync |
77 | | -``` |
| 142 | +Contributions are welcome, whether it's a bug report, a new decomposition technique, or a clearer explanation of the math. |
78 | 143 |
|
79 | | -- To test the export process, we'll run `.github/scripts/build.py` from the root directory through a symlink. |
| 144 | +1. **Fork** the repository |
| 145 | +2. **Sync** dependencies: `uv sync` |
| 146 | +3. **Create a branch** for your changes |
| 147 | +4. **Open a Pull Request** — maintainers will review it |
80 | 148 |
|
81 | | -```bash |
82 | | -uv run .github/scripts/build.py |
83 | | -``` |
| 149 | +For questions, suggestions, or discussion of the mathematics: |
| 150 | + |
| 151 | +- 💬 [Discussion Board](https://github.com/prgyn8/Matrix-Decomposition-Implementations/discussions) |
| 152 | +- 🐛 [Open an Issue](https://github.com/prgyn8/Matrix-Decomposition-Implementations/issues) |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## Resources & Acknowledgements |
84 | 157 |
|
85 | | -This will export all notebooks in a folder called `_site/` in the root directory |
| 158 | +- [**Wikipedia** — Gram-Schmidt Process](https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process) — foundational definitions and mathematical references |
| 159 | +- [**DataCamp** — Orthogonal Matrices](https://www.datacamp.com/tutorial/orthogonal-matrix) — accessible article on orthogonality |
| 160 | +- [**MIT OpenCourseWare** — Lecture 17](https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-17-orthogonal-matrices-and-gram-schmidt/) — in-depth treatment by *Prof. Gilbert Strang* |
| 161 | +- [**Steve Brunton**](https://www.youtube.com/@Eigensteve) — original spark for this project; exceptional intuition on engineering applications of linear algebra |
| 162 | +- [**Graphical Linear Algebra**](https://graphicallinearalgebra.net/2017/08/09/orthogonality-and-projections/) — visual treatment of orthogonality and projections |
86 | 163 |
|
87 | | -## 🌱 Contribution Guide |
| 164 | +--- |
88 | 165 |
|
89 | | -- If you find a bug or have a feature request, please open an [Issue](https://github.com/PragyanTiwari/Matrix-Decompositions-Implementation-for-SVD-PCA/issues). |
| 166 | +<div align="center"> |
90 | 167 |
|
91 | | -- PR will be reviewed by the maintainers. |
| 168 | +<br/> |
92 | 169 |
|
93 | | -- Questions & Suggestions can be queried on the [Discussion section](https://github.com/PragyanTiwari/Matrix-Decompositions-Implementation-for-SVD-PCA/discussions). |
| 170 | +[⭐ Star this repo](https://github.com/prgyn8/Matrix-Decomposition-Implementations/stargazers) · |
| 171 | +[💬 Join the Discussion](https://github.com/prgyn8/Matrix-Decomposition-Implementations/discussions) · |
| 172 | +[Author →](https://github.com/prgyn8) |
94 | 173 |
|
95 | | -______________________________________________________________________ |
| 174 | +</div> |
0 commit comments