bhardwajsatyam commited on
Commit
45c2c87
1 Parent(s): 5362842

Added description

Browse files
Files changed (2) hide show
  1. app.py +9 -6
  2. description.md +42 -0
app.py CHANGED
@@ -8,9 +8,9 @@ np.set_printoptions(precision=3)
8
  xlim = (-10,10)
9
  ylim = (-10,10)
10
 
11
- st.title("Eigen Values and Eigen Vectors")
12
  st.write(
13
- "This app shows the effect of linear transformation with respect to eigen values and eigen vectors")
14
 
15
  with st.sidebar:
16
  data = st.selectbox('Select type of dataset', ['Square', 'Circle'])
@@ -68,10 +68,13 @@ ax.set_yticks([])
68
  fig.legend(bbox_to_anchor=(1.05, 0.86), loc=1, borderaxespad=0., fontsize=8)
69
  st.pyplot(fig)
70
 
71
- df = pd.DataFrame({'Eigen Values': evl, 'Eigen Vectors': [str(evec[:,0]), str(evec[:,1])],\
72
- 'Transformed Eigen Vectors': [str(evec[:,0]*evl[0]), str(evec[:,1]*evl[1])]})
73
  st.table(df)
74
 
75
  if np.iscomplex(evl).any() or np.iscomplex(evec).any():
76
- st.write("Due to complex eigen vectors or eigne values, the transformed eigen vectors are not\
77
- displayed...")
 
 
 
 
8
  xlim = (-10,10)
9
  ylim = (-10,10)
10
 
11
+ st.title("Visualizing Eigenvectors with 2x2 Linear Transformations")
12
  st.write(
13
+ "This app shows the effect of a 2x2 linear transformation on simple shapes to understand the role of eigenvectors and eigenvalues in quantifying the nature of a transformation.")
14
 
15
  with st.sidebar:
16
  data = st.selectbox('Select type of dataset', ['Square', 'Circle'])
 
68
  fig.legend(bbox_to_anchor=(1.05, 0.86), loc=1, borderaxespad=0., fontsize=8)
69
  st.pyplot(fig)
70
 
71
+ df = pd.DataFrame({'Eigenvalues': evl, 'Eigenvectors': [str(evec[:,0]), str(evec[:,1])],\
72
+ 'Transformed Eigenvectors': [str(evec[:,0]*evl[0]), str(evec[:,1]*evl[1])]})
73
  st.table(df)
74
 
75
  if np.iscomplex(evl).any() or np.iscomplex(evec).any():
76
+ st.write("Due to complex eigenvectors and eigenvalues, the transformed eigenvectors are not\
77
+ displayed...")
78
+
79
+ file = open("description.md", "r")
80
+ st.markdown(file.read())
description.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ You might observe that sometimes the shapes collapse to a line, or sometimes the eigenvectors won't show due to them being complex. Let us look at why this happens in some detail.
2
+
3
+ A point $(x, y)$ transforms under $A$ to $(x',y')$ as follows
4
+
5
+ $$
6
+ \begin{bmatrix} x'\\ y' \end{bmatrix} = \underbrace{\begin{bmatrix} a_{00} & a_{01} \\ a_{10} & a_{11} \end{bmatrix}}_{A} \begin{bmatrix} x\\ y \end{bmatrix}
7
+ $$
8
+
9
+ It is helpful to see where the unit basis vectors map to under the transformation.
10
+
11
+ $$
12
+ \begin{bmatrix}
13
+ 1\\
14
+ 0
15
+ \end{bmatrix} \stackrel{A}{\longrightarrow} \begin{bmatrix}
16
+ a_{00}\\
17
+ a_{10}
18
+ \end{bmatrix} \;\;\;\;\;\;\;\;
19
+ \begin{bmatrix}
20
+ 0\\
21
+ 1
22
+ \end{bmatrix} \stackrel{A}{\longrightarrow} \begin{bmatrix}
23
+ a_{01}\\
24
+ a_{11}
25
+ \end{bmatrix}
26
+ $$
27
+
28
+ Eigenvectors are precisely those vectors that satisfy the following property
29
+ $$ Av = \lambda v $$
30
+ They determine the directions that remain invariant under the transformation. Their corresponding eigenvalues $\lambda$ determine how much the space is stretched or squished in that direction. An eigenvalue of zero would imply that the transformed space collapses in that direction. Since the determinant is the product of the eigenvalues, it quantifies how much the transform amplifies the area measure.
31
+
32
+ To obtain the eigenvalues, we solve the characteristic equation $\left| A - \lambda I \right| = 0$ which in our case expands to
33
+
34
+ $$ \lambda^2 -(a_{00}+a_{11})\lambda + (a_{00}a_{11} - a_{01}a_{10})=0 $$
35
+
36
+ When the matrix $A$ is singular, then the transformed space collapses to a line. We can verify that $\lambda = 0$ is a solution only when $\left|A\right| = a_{00}a_{11} - a_{01}a_{10} = 0$. The following conditions are also equivalent to $A$ being singular:
37
+ * A row is a multiple of the other. Trivially true when any row is identically zero. Same is true for the columns.
38
+ * Three (or more) elements are zero.
39
+
40
+ Solving for $\lambda$, we get $$ \frac{1}{2} \left(a_{00}+a_{11}\pm \sqrt{a_{00}^2-2 a_{11} a_{00}+a_{11}^2+4 a_{01} a_{10}}\right) $$
41
+
42
+ The quantity under the square root sign is called the Discriminant, denoted by $D$. When $D < 0$, the eigenvalues and consequently the eigenvectors are complex. On the other hand, when $A$ is symmetric $a_{01} = a_{10}$, then the discriminant is always positive and the eigendecomposition is real.