|
| 1 | +#### **A comprehensive implementation of core **Matrix Decomposition techniques** in Linear Algebra, providing an efficient computation approach, helps in uncovering hidden relationships in data, and lets you power many scalable applications in various fields of science and engineering.** |
1 | 2 |
|
| 3 | +______________________________________________________________________ |
2 | 4 |
|
3 | | -A comprehensive implementation of **_Matrix Decomposition Techniques_**, forming the foundations of various scientific and engineering applications. |
| 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; |
4 | 6 |
|
5 | | - |
| 7 | +- **📡 Signal Processing** |
| 8 | +- **🤖 Control Systems and Robotics** |
| 9 | +- **🖼️ Image Processing** |
| 10 | +- **➗ Solving Linear Systems i.e. *AX = B*** |
6 | 11 |
|
7 | | -To gain a deeper understanding of how Orthogonalization & matrices Decomposition works in real-life applications, like, |
8 | | -- **Signal Processing** |
9 | | -- **Control Systems and Robotics** |
10 | | -- **Solving Linear Systems i.e. *AX = B*** |
| 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. |
11 | 13 |
|
12 | | -With mathematical intuition & visual introspection, the project makes most of the abstract concepts easier to grasp and connect with practical applications. |
| 14 | + |
13 | 15 |
|
14 | | -> This is the first draft of the project. More implementations—such as **Householder Reflection**, **Bidiagonalization**, **LU Decomposition**, and others—will be added soon. |
| 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*. |
15 | 17 |
|
16 | | -## Features / What's Inside |
| 18 | +## What's Inside |
17 | 19 |
|
18 | | -For a vector space, building *Orthonormal Basis* is the most essential part of Linear Algebra. |
| 20 | +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*. |
19 | 21 |
|
20 | | -You can find top discussions about certain topics like Orthogonality, and why do we need it, ....here. |
| 22 | +**Terms like Orthogonality, QR Decomposition are being discussed in the — [🗨️Discussion section](https://github.com/PragyanTiwari/Matrix-Decompositions-Implementation-for-SVD-PCA/discussions).** |
21 | 23 |
|
22 | | -#### Gram-Schmidt Orthogonalization |
| 24 | +Here's a snippet; |
23 | 25 |
|
24 | | -One of the technique for creating Orthonormal Basis from a vector space (*assuming linear independence*) by using a Vector Projection Elimination method. |
| 26 | +```bash |
| 27 | +def gs_Orthogonalization(X:np.ndarray)->np.ndarray: |
| 28 | + |
| 29 | + Q = np.copy(X).astype("float64") |
| 30 | + n_vecs = Q.shape[1] |
| 31 | + |
| 32 | + # defining a function to compute the L2-norm |
| 33 | + length = lambda x: np.linalg.norm(x) |
| 34 | + |
| 35 | + # iteration with each vector in the matrix X |
| 36 | + for nth_vec in range(n_vecs): |
| 37 | + |
| 38 | + # iteratively removing each preceding projection from nth vector |
| 39 | + for k_proj in range(nth_vec): |
25 | 40 |
|
26 | | -Here's a snippet, |
| 41 | + # the dot product would be the scaler coefficient |
| 42 | + scaler = Q[:,nth_vec] @ Q[:,k_proj] |
| 43 | + projection = scaler * Q[:,k_proj] |
| 44 | + Q[:,nth_vec] -= projection # removing the Kth projection |
27 | 45 |
|
| 46 | + norm = length(Q[:,nth_vec]) |
| 47 | + |
| 48 | + # handling the case if the loop encounters linearly dependent vectors. |
| 49 | + # Since, they come already under the span of vector space, hence their value will be 0. |
| 50 | + if np.isclose(norm,0, rtol=1e-15, atol=1e-14, equal_nan=False): |
| 51 | + Q[:,nth_vec] = 0 |
| 52 | + else: |
| 53 | + # making orthogonal vectors -> orthonormal |
| 54 | + Q[:,nth_vec] = Q[:,nth_vec] / norm |
| 55 | + |
| 56 | + return Q |
| 57 | +``` |
| 58 | +
|
| 59 | +To edit the notebook in a sandbox environment, run this; |
| 60 | +
|
| 61 | +```bash |
| 62 | +uvx marimo edit --sandbox notebooks\Gram_Schmidt_QR_Decomposition.py |
| 63 | +``` |
28 | 64 |
|
29 | 65 | ## 🧪 Testing |
30 | 66 |
|
31 | | -To test the export process, run `.github/scripts/build.py` from the root directory. |
| 67 | +The updates made on this project, can be tested for deployment, (and for personal experimentation) by the following; |
| 68 | +
|
| 69 | +- Fork the repository. |
| 70 | +
|
| 71 | +- Run uv sync to install dependencies (*uv lockfile will help*) |
32 | 72 |
|
33 | 73 | ```bash |
34 | | -uv run .github/scripts/build.py |
| 74 | +uv sync |
35 | 75 | ``` |
36 | 76 |
|
37 | | -This will export all notebooks in a folder called `_site/` in the root directory. Then to serve the site, run: |
| 77 | +- To test the export process, we'll run `.github/scripts/build.py` from the root directory through a symlink. |
38 | 78 |
|
39 | 79 | ```bash |
40 | | -python -m http.server -d _site |
| 80 | +uv run build.py |
41 | 81 | ``` |
42 | 82 |
|
43 | | -This will serve the site at `http://localhost:8000`. |
| 83 | +This will export all notebooks in a folder called `_site/` in the root directory |
| 84 | +
|
| 85 | +## 🌱 Contribution Guide |
| 86 | +
|
| 87 | +- 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). |
| 88 | +
|
| 89 | +- PR will be reviewed by the maintainers. |
| 90 | +
|
| 91 | +- Questions & Suggestions can be queried on the [Discussion section](https://github.com/PragyanTiwari/Matrix-Decompositions-Implementation-for-SVD-PCA/discussions). |
| 92 | +
|
| 93 | +______________________________________________________________________ |
0 commit comments