Skip to content

Commit 49cdf8a

Browse files
committed
updated file
1 parent b8cd39b commit 49cdf8a

File tree

3 files changed

+155
-47
lines changed

3 files changed

+155
-47
lines changed

apps/gram_schmidt_process.py

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
# /// script
2+
# requires-python = ">=3.13"
3+
# dependencies = [
4+
# "marimo",
5+
# "pyzmq",
6+
# ]
7+
# ///
8+
19
import marimo
210

3-
__generated_with = "0.14.16"
11+
__generated_with = "0.18.4"
412
app = marimo.App(css_file="")
513

614

@@ -76,7 +84,9 @@ def _(mo, style_dict):
7684

7785
@app.cell
7886
def _(mo):
79-
mo.md(r"""<br>""")
87+
mo.md(r"""
88+
<br>
89+
""")
8090
return
8191

8292

@@ -117,13 +127,11 @@ def _(mo):
117127

118128
@app.cell
119129
def _(mo):
120-
mo.md(
121-
r"""
130+
mo.md(r"""
122131
---
123132
124133
## **A mathematical Intuition,**
125-
"""
126-
)
134+
""")
127135
return
128136

129137

@@ -222,27 +230,26 @@ def _(mo):
222230

223231
@app.cell
224232
def _(mo):
225-
mo.md(
226-
r"""
233+
mo.md(r"""
227234
---
228235
## **Python Implemenation Of Gram-Schmidt**
229236
230237
looking at the python implementation of gram-schimdt process step wise, and defining a function for it, which then, we'll use it later too.
231-
"""
232-
)
238+
""")
233239
return
234240

235241

236242
@app.cell(hide_code=True)
237243
def _(mo):
238-
mo.md(r"""**1. firstly, defining a vector space, calling it A.**""")
244+
mo.md(r"""
245+
**1. firstly, defining a vector space, calling it A.**
246+
""")
239247
return
240248

241249

242250
@app.cell
243251
def _(mo):
244-
mo.md(
245-
r"""
252+
mo.md(r"""
246253
```python {.marimo}
247254
import numpy as np
248255
```
@@ -256,8 +263,7 @@ def _(mo):
256263
```python {.marimo}
257264
print(A)
258265
```
259-
"""
260-
)
266+
""")
261267
return
262268

263269

@@ -277,7 +283,9 @@ def _(A, mo, to_latex):
277283

278284
@app.cell(hide_code=True)
279285
def _(mo):
280-
mo.md(r"""**2. Now, let's define a func. `gram_schmidt` utilizing the Gram-Schmidt Process,**""")
286+
mo.md(r"""
287+
**2. Now, let's define a func. `gram_schmidt` utilizing the Gram-Schmidt Process,**
288+
""")
281289
return
282290

283291

@@ -322,14 +330,12 @@ def gram_schmidt(X:np.ndarray)->np.ndarray:
322330
Q[:,nth_vec] = Q[:,nth_vec] / norm
323331

324332
return Q
325-
326333
return (gram_schmidt,)
327334

328335

329336
@app.cell(hide_code=True)
330337
def _(mo):
331-
mo.md(
332-
r"""
338+
mo.md(r"""
333339
```python
334340
def gram_schmidt(X:np.ndarray)->np.ndarray:
335341
'''
@@ -351,14 +357,14 @@ def gram_schmidt(X:np.ndarray)->np.ndarray:
351357
# iteratively removing each preceding projection from nth vector
352358
for k_proj in range(nth_vec):
353359
354-
# the dot product would be the scaler coefficient
360+
# the dot product would be the scaler coefficient
355361
scaler = Q[:,nth_vec] @ Q[:,k_proj]
356362
projection = scaler * Q[:,k_proj]
357363
Q[:,nth_vec] -= projection # removing the Kth projection
358364
359365
norm = length(Q[:,nth_vec])
360366
361-
# handling the case if the loop encounters linearly dependent vectors.
367+
# handling the case if the loop encounters linearly dependent vectors.
362368
# Since, they come already under the span of vector space, hence their value will be 0.
363369
if np.isclose(norm,0, rtol=1e-15, atol=1e-14, equal_nan=False):
364370
Q[:,nth_vec] = 0
@@ -368,8 +374,7 @@ def gram_schmidt(X:np.ndarray)->np.ndarray:
368374
369375
return Q
370376
```
371-
"""
372-
)
377+
""")
373378
return
374379

375380

@@ -403,14 +408,12 @@ def is_Orthonormal(Q: np.ndarray)->bool:
403408

404409
# calling the function
405410
Q_A = gram_schmidt(A)
406-
407411
return Q_A, is_Orthonormal
408412

409413

410414
@app.cell(hide_code=True)
411415
def _(mo):
412-
mo.md(
413-
r"""
416+
mo.md(r"""
414417
```python {.marimo}
415418
def is_Orthonormal(Q: np.ndarray)->bool:
416419
'''
@@ -428,8 +431,7 @@ def is_Orthonormal(Q: np.ndarray)->bool:
428431
# checking the condition
429432
is_Orthonormal(Q_A)
430433
```
431-
"""
432-
)
434+
""")
433435
return
434436

435437

@@ -442,19 +444,19 @@ def _(Q_A, is_Orthonormal):
442444

443445
@app.cell(hide_code=True)
444446
def _(mo):
445-
mo.md(r"""> The Orthonormal condition satisifies and hence results in TRUE. So, the above justifying the orthogonality of the matrix `Q_A`.""")
447+
mo.md(r"""
448+
> The Orthonormal condition satisifies and hence results in TRUE. So, the above justifying the orthogonality of the matrix `Q_A`.
449+
""")
446450
return
447451

448452

449453
@app.cell(hide_code=True)
450454
def _(mo):
451-
mo.md(
452-
r"""
455+
mo.md(r"""
453456
<wbr>
454457
**4. You can find the transformation we've made so far in the matrix below,**
455458
<wbr>
456-
"""
457-
)
459+
""")
458460
return
459461

460462

@@ -554,16 +556,14 @@ def _(A, Q_A, mo, np, plt):
554556

555557
@app.cell(hide_code=True)
556558
def _(mo):
557-
mo.md(
558-
"""
559+
mo.md("""
559560
---
560561
## **Try it on your own,**
561562
562563
Slide the values of Matrix A, experiment with different values and check out their Orthonormal Vectors respectively.
563564
564565
The radar plot showing the orientations of **Original Matrix** `(A)` and **Orthonormal Matrix** `(Q)`. The radar plot will form triangle for Q for every linear independent vectors in `A`, otherwise, the shape will be distorted.
565-
"""
566-
)
566+
""")
567567
return
568568

569569

@@ -693,16 +693,14 @@ def _(additional_info, mo, playground):
693693

694694
@app.cell
695695
def _(mo):
696-
mo.md(
697-
r"""
696+
mo.md(r"""
698697
---
699698
## **Moving to the next Notebook**
700699
701-
This notebook covered up the basics of gram-schimdt process and how orthonormal vectors are produced through it.
700+
This notebook covered up the basics of gram-schimdt process and how orthonormal vectors are produced through it.
702701
703702
One of its basic application is in **QR Decomposition**, which we'll be exploring in the next notebook, and seeing how the matrix A will be decomposed at fixed two matrices (One will be Orthonormal & other to be Upper-Triangular).
704-
"""
705-
)
703+
""")
706704
return
707705

708706

@@ -728,19 +726,17 @@ def _():
728726

729727
@app.cell(hide_code=True)
730728
def _(mo):
731-
mo.md(
732-
r"""
729+
mo.md(r"""
733730
---
734731
## **Acknowledgements (Resources I learnt from...)**
735732
736733
This project is undertaken through many resources, the topmost resources I learnt from,
737734
738-
- [Wikipedia](https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process) – for providing foundational definitions and mathematical references.
735+
- [Wikipedia](https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process) – for providing foundational definitions and mathematical references.
739736
- [DataCamp](https://www.datacamp.com/tutorial/orthogonal-matrix) – for providing informational article upon Orthogonality.
740737
- [MIT OpenCourseWare](https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-17-orthogonal-matrices-and-gram-schmidt/) – for refurbishing the in-depth knowledge of Gram-Schmidt Process, taught by *Prof. Gilbert Strang*.
741738
- [Steve Brunton (*Amazing Guy*)](https://www.google.com/search?q=steve+brunton&sca_esv=55a910f019e63594&rlz=1C1GCEA_enIN1112IN1112&sxsrf=AE3TifMoAjuMLl0MOCAV5lyl_Ga8KboiEg%3A1755118367776&ei=H_ucaP-UL_Of4-EPrsmB8QY&ved=0ahUKEwi_oOa21YiPAxXzzzgGHa5kIG4Q4dUDCBA&uact=5&oq=steve+brunton&gs_lp=Egxnd3Mtd2l6LXNlcnAiDXN0ZXZlIGJydW50b24yBBAjGCcyCxAuGIAEGJECGIoFMgsQABiABBiRAhiKBTIKEAAYgAQYQxiKBTIFEAAYgAQyBRAAGIAEMgUQABiABDIFEAAYgAQyBRAAGIAEMgUQABiABEiZC1CRBljLCHABeACQAQCYAaoBoAGvAqoBAzAuMrgBA8gBAPgBAZgCA6ACwgLCAggQABiwAxjvBcICCxAAGIAEGLADGKIEwgIKEC4YgAQYQxiKBZgDAIgGAZAGBZIHAzEuMqAHuROyBwMwLjK4B7sCwgcDMi0zyAcP&sclient=gws-wiz-serp) – for sparking the interest, this is from where I started this project. *He has a great interest in Physics Implementation of every engineering field.*
742-
"""
743-
)
739+
""")
744740
return
745741

746742

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies = [
1010
"numpy>=2.4.0",
1111
"pandas>=2.3.3",
1212
"plotly>=6.5.0",
13+
"pyzmq>=27.1.0",
1314
"wigglystuff>=0.2.5",
1415
]
1516

0 commit comments

Comments
 (0)