shukdevdatta123 commited on
Commit
d04c5d3
·
verified ·
1 Parent(s): 92a2cc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py CHANGED
@@ -18,6 +18,59 @@ def draw_graph(G, pos=None, title="Graph Visualization"):
18
  nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
19
  st.pyplot(plt)
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  # Function to display properties and graph for Basic: Properties
22
  def display_graph_properties(G):
23
  pathlengths = []
 
18
  nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
19
  st.pyplot(plt)
20
 
21
+ # Function to display Eigenvalue analysis for Drawing: Eigenvalues
22
+ def display_eigenvalue_analysis():
23
+ st.title("Drawing: Eigenvalues")
24
+
25
+ option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
26
+
27
+ if option == "Default Example":
28
+ # Generate random graph with 1000 nodes and 5000 edges
29
+ n = 1000
30
+ m = 5000
31
+ G = nx.gnm_random_graph(n, m, seed=5040) # Seed for reproducibility
32
+
33
+ # Calculate the normalized Laplacian matrix
34
+ L = nx.normalized_laplacian_matrix(G)
35
+ eigenvalues = numpy.linalg.eigvals(L.toarray())
36
+
37
+ # Print largest and smallest eigenvalues
38
+ st.write(f"Largest eigenvalue: {max(eigenvalues)}")
39
+ st.write(f"Smallest eigenvalue: {min(eigenvalues)}")
40
+
41
+ # Display the histogram of eigenvalues
42
+ st.write("### Eigenvalue Histogram")
43
+ plt.hist(eigenvalues, bins=100)
44
+ plt.xlim(0, 2) # Eigenvalues between 0 and 2
45
+ st.pyplot(plt)
46
+
47
+ elif option == "Create your own":
48
+ # Allow the user to customize the number of nodes and edges
49
+ n_nodes = st.number_input("Number of nodes:", min_value=2, max_value=1000, value=100)
50
+ m_edges = st.number_input("Number of edges:", min_value=1, max_value=n_nodes*(n_nodes-1)//2, value=500)
51
+
52
+ if st.button("Generate"):
53
+ # Generate a random graph with the custom number of nodes and edges
54
+ G_custom = nx.gnm_random_graph(n_nodes, m_edges, seed=5040) # Seed for reproducibility
55
+
56
+ # Calculate the normalized Laplacian matrix
57
+ L = nx.normalized_laplacian_matrix(G_custom)
58
+ eigenvalues = numpy.linalg.eigvals(L.toarray())
59
+
60
+ # Print largest and smallest eigenvalues
61
+ st.write(f"Largest eigenvalue: {max(eigenvalues)}")
62
+ st.write(f"Smallest eigenvalue: {min(eigenvalues)}")
63
+
64
+ # Display the histogram of eigenvalues
65
+ st.write("### Eigenvalue Histogram")
66
+ plt.hist(eigenvalues, bins=100)
67
+ plt.xlim(0, 2) # Eigenvalues between 0 and 2
68
+ st.pyplot(plt)
69
+
70
+ # Display Drawing: Eigenvalues if selected
71
+ if sidebar_option == "Drawing: Eigenvalues":
72
+ display_eigenvalue_analysis()
73
+
74
  # Function to display properties and graph for Basic: Properties
75
  def display_graph_properties(G):
76
  pathlengths = []