Spaces:
Runtime error
Runtime error
anp-scp
commited on
Commit
•
f7111bf
1
Parent(s):
fd47e8f
initial commit
Browse files- app.py +61 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from matplotlib import pyplot as plt
|
2 |
+
import numpy as np
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
np.set_printoptions(precision=3)
|
7 |
+
|
8 |
+
st.title("Eigen Values and Eigen Vectors")
|
9 |
+
st.write(
|
10 |
+
"This app shows the effect of linear transformation with respect to eigen values and eigen vectors"
|
11 |
+
)
|
12 |
+
|
13 |
+
def getSquareY(x):
|
14 |
+
if x==-1 or x == 1:
|
15 |
+
return 0
|
16 |
+
else:
|
17 |
+
return 1
|
18 |
+
|
19 |
+
getSquareYVectorised = np.vectorize(getSquareY)
|
20 |
+
|
21 |
+
def getCircle(x):
|
22 |
+
return np.sqrt(1-np.square(x))
|
23 |
+
|
24 |
+
with st.sidebar:
|
25 |
+
data = st.selectbox('Select type of dataset', ['Square', 'Circle'])
|
26 |
+
st.write("---")
|
27 |
+
st.text("Enter transformation matrix elements")
|
28 |
+
a_00 = st.slider(label = '$A_{0,0}$', min_value = -5, max_value=5, value=1)
|
29 |
+
a_01 = st.slider(label = '$A_{0,1}$', min_value = -5, max_value=5, value=0)
|
30 |
+
a_10 = st.slider(label = '$A_{1,0}$', min_value = -5, max_value=5, value=0)
|
31 |
+
a_11 = st.slider(label = '$A_{1,1}$', min_value = -5, max_value=5, value=1)
|
32 |
+
|
33 |
+
def transform(x,y):
|
34 |
+
return a_00 * x + a_01 * y, a_10 * x + a_11 * y
|
35 |
+
|
36 |
+
|
37 |
+
x = np.linspace(-1,1,1000)
|
38 |
+
y = getSquareYVectorised(x) if data == 'Square' else getCircle(x)
|
39 |
+
|
40 |
+
x_dash_up, y_dash_up = transform(x,y)
|
41 |
+
x_dash_down, y_dash_down = transform(x,-y)
|
42 |
+
|
43 |
+
t = np.array([[a_00,a_01], [a_10, a_11]], dtype=np.float64)
|
44 |
+
|
45 |
+
try:
|
46 |
+
evl, evec = np.linalg.eig(t)
|
47 |
+
fig, ax = plt.subplots()
|
48 |
+
ax.plot(x_dash_up,y_dash_up,'r')
|
49 |
+
ax.plot(x_dash_down,y_dash_down, 'g')
|
50 |
+
ax.quiver(0,0,evec[0][0],evec[0][1],scale=1,scale_units ='xy',angles='xy', facecolor='yellow', label='$\lambda_0$')
|
51 |
+
ax.quiver(0,0,evec[1][0],evec[1][1],scale=1,scale_units ='xy',angles='xy', facecolor='blue',label='$\lambda_1$')
|
52 |
+
ax.set_xlim(-5,5)
|
53 |
+
ax.set_ylim(-5,5)
|
54 |
+
ax.set_aspect('equal', adjustable='box')
|
55 |
+
fig.legend()
|
56 |
+
st.pyplot(fig)
|
57 |
+
|
58 |
+
df = pd.DataFrame({'Eigen Values': evl, 'Eigen Vectors': [str(evec[0]), str(evec[1])]})
|
59 |
+
st.table(df)
|
60 |
+
except:
|
61 |
+
st.write("Given matrix has eigen vectors in complex space")
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
matplotlib
|
2 |
+
numpy
|
3 |
+
pandas
|
4 |
+
streamlit
|