juneja-codebase 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. juneja_codebase/__init__.py +6 -0
  2. juneja_codebase/main.py +197 -0
  3. juneja_codebase/templates/compiler_design/AnshJuneja_Practical10_CD.l +15 -0
  4. juneja_codebase/templates/compiler_design/AnshJuneja_Practical10_CD.y +27 -0
  5. juneja_codebase/templates/compiler_design/AnshJuneja_Practical11_CD.l +15 -0
  6. juneja_codebase/templates/compiler_design/AnshJuneja_Practical11_CD.y +36 -0
  7. juneja_codebase/templates/compiler_design/AnshJuneja_Practical12_CD.l +14 -0
  8. juneja_codebase/templates/compiler_design/AnshJuneja_Practical12_CD.y +31 -0
  9. juneja_codebase/templates/compiler_design/AnshJuneja_Practical13_CD.l +14 -0
  10. juneja_codebase/templates/compiler_design/AnshJuneja_Practical13_CD.y +38 -0
  11. juneja_codebase/templates/compiler_design/AnshJuneja_Practical1_CD.l +38 -0
  12. juneja_codebase/templates/compiler_design/AnshJuneja_Practical2_CD.l +27 -0
  13. juneja_codebase/templates/compiler_design/AnshJuneja_Practical3_CD.l +39 -0
  14. juneja_codebase/templates/compiler_design/AnshJuneja_Practical4_CD.l +32 -0
  15. juneja_codebase/templates/compiler_design/AnshJuneja_Practical5_CD.l +51 -0
  16. juneja_codebase/templates/compiler_design/AnshJuneja_Practical6_CD.l +46 -0
  17. juneja_codebase/templates/compiler_design/AnshJuneja_Practical7_CD.l +36 -0
  18. juneja_codebase/templates/compiler_design/AnshJuneja_Practical8_CD.l +33 -0
  19. juneja_codebase/templates/compiler_design/AnshJuneja_Practical9_CD.l +19 -0
  20. juneja_codebase/templates/compiler_design/AnshJuneja_Practical9_CD.y +36 -0
  21. juneja_codebase/templates/social_network_analysis/1_try.ipynb +286 -0
  22. juneja_codebase/templates/social_network_analysis/2_try.ipynb +352 -0
  23. juneja_codebase/templates/social_network_analysis/3_try.ipynb +207 -0
  24. juneja_codebase/templates/social_network_analysis/4_try.ipynb +1218 -0
  25. juneja_codebase/templates/social_network_analysis/5_try.ipynb +326 -0
  26. juneja_codebase/templates/social_network_analysis/6_try.ipynb +241 -0
  27. juneja_codebase/templates/social_network_analysis/new.ipynb +592 -0
  28. juneja_codebase-0.1.3.dist-info/LICENSE +21 -0
  29. juneja_codebase-0.1.3.dist-info/METADATA +75 -0
  30. juneja_codebase-0.1.3.dist-info/RECORD +33 -0
  31. juneja_codebase-0.1.3.dist-info/WHEEL +5 -0
  32. juneja_codebase-0.1.3.dist-info/entry_points.txt +3 -0
  33. juneja_codebase-0.1.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,352 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "36b05a3b",
6
+ "metadata": {},
7
+ "source": [
8
+ "# **Q2(A) Compute and plot the degree distribution, cumulative degree distributions of four real-world networks(networks with approx 100, 1000, 10,000, 100,000 nodes).Also compute local and global properties of the network.**"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": null,
14
+ "id": "4cd11209",
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "# KARATE CLUB\n",
19
+ "\n",
20
+ "import networkx as nx\n",
21
+ "import matplotlib.pyplot as plt\n",
22
+ "\n",
23
+ "G = nx.karate_club_graph()\n",
24
+ "\n",
25
+ "print(\"Nodes:\", G.number_of_nodes())\n",
26
+ "print(\"Edges:\", G.number_of_edges())\n",
27
+ "\n",
28
+ "degrees = [d for _, d in G.degree()]\n",
29
+ "\n",
30
+ "plt.figure(figsize=(12,5))\n",
31
+ "plt.subplot(1,2,1)\n",
32
+ "plt.hist(degrees, bins=range(1, max(degrees)+2), color='pink', edgecolor='black')\n",
33
+ "plt.xlabel('Degree')\n",
34
+ "plt.ylabel('Frequency')\n",
35
+ "plt.title('Degree Distribution')\n",
36
+ "\n",
37
+ "plt.subplot(1,2,2)\n",
38
+ "sorted_deg = sorted(set(degrees))\n",
39
+ "cum = [sum(i <= x for i in degrees)/len(degrees) for x in sorted_deg]\n",
40
+ "plt.plot(sorted_deg, cum, marker='o', color='darkblue')\n",
41
+ "plt.xlabel('Degree')\n",
42
+ "plt.ylabel('Cumulative Probability')\n",
43
+ "plt.title('Cumulative Degree Distribution')\n",
44
+ "plt.tight_layout()\n",
45
+ "plt.show()\n",
46
+ "\n",
47
+ "avg_deg = sum(degrees)/len(degrees)\n",
48
+ "clustering = nx.average_clustering(G)\n",
49
+ "density = nx.density(G)\n",
50
+ "avg_dist = nx.average_shortest_path_length(G)\n",
51
+ "radius = nx.radius(G)\n",
52
+ "diameter = nx.diameter(G)\n",
53
+ "\n",
54
+ "print(\"\\nNetwork Properties:\")\n",
55
+ "print(f\"Average Degree: {avg_deg:.2f}\")\n",
56
+ "print(f\"Clustering Coefficient: {clustering:.3f}\")\n",
57
+ "print(f\"Density: {density:.3f}\")\n",
58
+ "print(f\"Average Distance: {avg_dist:.3f}\")\n",
59
+ "print(f\"Radius: {radius}\")\n",
60
+ "print(f\"Diameter: {diameter}\")\n",
61
+ "\n",
62
+ "plt.figure(figsize=(8,6))\n",
63
+ "#other layouts\n",
64
+ "# pos = nx.spring_layout(G, seed=42)\n",
65
+ "# pos = nx.circular_layout(G)\n",
66
+ "pos = nx.kamada_kawai_layout(G)\n",
67
+ "nx.draw(G, pos, with_labels=True, node_color='pink', edge_color='blue',\n",
68
+ " node_size=800, font_color='black', font_size=8)\n",
69
+ "plt.title(\"Karate Club Network\")\n",
70
+ "plt.show()"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "execution_count": null,
76
+ "id": "0f4d1fbc",
77
+ "metadata": {},
78
+ "outputs": [],
79
+ "source": [
80
+ "# POLITICAL BOOKS\n",
81
+ "\n",
82
+ "import pandas as pd\n",
83
+ "import networkx as nx\n",
84
+ "import matplotlib.pyplot as plt\n",
85
+ "\n",
86
+ "df = pd.read_csv('PoliticalBooks.txt', sep='\\t', names=['Source', 'Target'], header=0)\n",
87
+ "G = nx.from_pandas_edgelist(df, source='Source', target='Target', create_using=nx.Graph())\n",
88
+ "\n",
89
+ "print(\"Nodes:\", G.number_of_nodes())\n",
90
+ "print(\"Edges:\", G.number_of_edges())\n",
91
+ "\n",
92
+ "degrees = [d for _, d in G.degree()]\n",
93
+ "\n",
94
+ "plt.figure(figsize=(12,5))\n",
95
+ "plt.subplot(1,2,1)\n",
96
+ "plt.hist(degrees, bins=range(1, max(degrees)+2), color='pink', edgecolor='black')\n",
97
+ "plt.xlabel('Degree')\n",
98
+ "plt.ylabel('Frequency')\n",
99
+ "plt.title('Degree Distribution')\n",
100
+ "\n",
101
+ "plt.subplot(1,2,2)\n",
102
+ "sorted_deg = sorted(set(degrees))\n",
103
+ "cum = [sum(i <= x for i in degrees)/len(degrees) for x in sorted_deg]\n",
104
+ "plt.plot(sorted_deg, cum, marker='o', color='darkblue')\n",
105
+ "plt.xlabel('Degree')\n",
106
+ "plt.ylabel('Cumulative Probability')\n",
107
+ "plt.title('Cumulative Degree Distribution')\n",
108
+ "plt.tight_layout()\n",
109
+ "plt.show()\n",
110
+ "\n",
111
+ "avg_deg = sum(degrees)/len(degrees)\n",
112
+ "clustering = nx.average_clustering(G)\n",
113
+ "density = nx.density(G)\n",
114
+ "avg_dist = nx.average_shortest_path_length(G)\n",
115
+ "radius = nx.radius(G)\n",
116
+ "diameter = nx.diameter(G)\n",
117
+ "\n",
118
+ "print(\"\\nNetwork Properties:\")\n",
119
+ "print(f\"Average Degree: {avg_deg:.2f}\")\n",
120
+ "print(f\"Clustering Coefficient: {clustering:.3f}\")\n",
121
+ "print(f\"Density: {density:.3f}\")\n",
122
+ "print(f\"Average Distance: {avg_dist:.3f}\")\n",
123
+ "print(f\"Radius: {radius}\")\n",
124
+ "print(f\"Diameter: {diameter}\")\n",
125
+ "\n",
126
+ "plt.figure(figsize=(8,6))\n",
127
+ "#pos = nx.spring_layout(G, seed=42)\n",
128
+ "# pos = nx.kamada_kawai_layout(G)\n",
129
+ "pos = nx.circular_layout(G)\n",
130
+ "\n",
131
+ "nx.draw(G, pos, with_labels=True, node_color='pink', edge_color='blue',\n",
132
+ " node_size=800, font_color='black', font_size=8)\n",
133
+ "plt.title(\"Political Books Network\")\n",
134
+ "plt.show()"
135
+ ]
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "execution_count": null,
140
+ "id": "f59953fe",
141
+ "metadata": {},
142
+ "outputs": [],
143
+ "source": [
144
+ "# HAMSTER DATASET\n",
145
+ "\n",
146
+ "import pandas as pd\n",
147
+ "import networkx as nx\n",
148
+ "import matplotlib.pyplot as plt\n",
149
+ "\n",
150
+ "df = pd.read_csv('soc-hamsterster.edges', sep=' ', names=['Source', 'Target'])\n",
151
+ "G = nx.from_pandas_edgelist(df, source='Source', target='Target', create_using=nx.Graph())\n",
152
+ "\n",
153
+ "print(\"Nodes:\", G.number_of_nodes())\n",
154
+ "print(\"Edges:\", G.number_of_edges())\n",
155
+ "\n",
156
+ "degrees = [d for _, d in G.degree()]\n",
157
+ "\n",
158
+ "plt.figure(figsize=(12,5))\n",
159
+ "plt.subplot(1,2,1)\n",
160
+ "plt.hist(degrees, bins=range(1, max(degrees)+2), color='pink', edgecolor='black')\n",
161
+ "plt.xlabel('Degree')\n",
162
+ "plt.ylabel('Frequency')\n",
163
+ "plt.title('Degree Distribution')\n",
164
+ "\n",
165
+ "plt.subplot(1,2,2)\n",
166
+ "sorted_deg = sorted(set(degrees))\n",
167
+ "cum = [sum(i <= x for i in degrees)/len(degrees) for x in sorted_deg]\n",
168
+ "plt.plot(sorted_deg, cum, marker='o', color='darkblue')\n",
169
+ "plt.xlabel('Degree')\n",
170
+ "plt.ylabel('Cumulative Probability')\n",
171
+ "plt.title('Cumulative Degree Distribution')\n",
172
+ "plt.tight_layout()\n",
173
+ "plt.show()\n",
174
+ "\n",
175
+ "avg_deg = sum(degrees)/len(degrees)\n",
176
+ "clustering = nx.average_clustering(G)\n",
177
+ "density = nx.density(G)\n",
178
+ "#avg_dist = nx.average_shortest_path_length(G) # This might be slow for large graphs\n",
179
+ "#radius = nx.radius(G) # This might be slow for large graphs\n",
180
+ "#diameter = nx.diameter(G) # This might be slow for large graphs\n",
181
+ "\n",
182
+ "print(\"\\nNetwork Properties:\")\n",
183
+ "print(f\"Average Degree: {avg_deg:.2f}\")\n",
184
+ "print(f\"Clustering Coefficient: {clustering:.3f}\")\n",
185
+ "print(f\"Density: {density:.3f}\")\n",
186
+ "#print(f\"Average Distance: {avg_dist:.3f}\")\n",
187
+ "#print(f\"Radius: {radius}\")\n",
188
+ "#print(f\"Diameter: {diameter}\")\n",
189
+ "\n",
190
+ "\n",
191
+ "plt.figure(figsize=(8,6))\n",
192
+ "#pos = nx.spring_layout(G, seed=42)\n",
193
+ "# pos = nx.kamada_kawai_layout(G)\n",
194
+ "pos = nx.circular_layout(G)\n",
195
+ "\n",
196
+ "nx.draw(G, pos, with_labels=True, node_color='pink', edge_color='blue',\n",
197
+ " node_size=800, font_color='black', font_size=8)\n",
198
+ "plt.title(\"Hamsterster Social Network\")\n",
199
+ "plt.show()"
200
+ ]
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "execution_count": null,
205
+ "id": "fef12822",
206
+ "metadata": {},
207
+ "outputs": [],
208
+ "source": [
209
+ "# EUROROAD DATASET\n",
210
+ "\n",
211
+ "import pandas as pd\n",
212
+ "import networkx as nx\n",
213
+ "import matplotlib.pyplot as plt\n",
214
+ "\n",
215
+ "df = pd.read_csv('road-euroroad.edges', sep=' ', names=['Source', 'Target'], header=0)\n",
216
+ "G = nx.from_pandas_edgelist(df, source='Source', target='Target', create_using=nx.Graph())\n",
217
+ "\n",
218
+ "print(\"Nodes:\", G.number_of_nodes())\n",
219
+ "print(\"Edges:\", G.number_of_edges())\n",
220
+ "\n",
221
+ "degrees = [d for _, d in G.degree()]\n",
222
+ "\n",
223
+ "plt.figure(figsize=(12,5))\n",
224
+ "plt.subplot(1,2,1)\n",
225
+ "plt.hist(degrees, bins=range(1, max(degrees)+2), color='pink', edgecolor='black')\n",
226
+ "plt.xlabel('Degree')\n",
227
+ "plt.ylabel('Frequency')\n",
228
+ "plt.title('Degree Distribution')\n",
229
+ "\n",
230
+ "plt.subplot(1,2,2)\n",
231
+ "sorted_deg = sorted(set(degrees))\n",
232
+ "cum = [sum(i <= x for i in degrees)/len(degrees) for x in sorted_deg]\n",
233
+ "plt.plot(sorted_deg, cum, marker='o', color='darkblue')\n",
234
+ "plt.xlabel('Degree')\n",
235
+ "plt.ylabel('Cumulative Probability')\n",
236
+ "plt.title('Cumulative Degree Distribution')\n",
237
+ "plt.tight_layout()\n",
238
+ "plt.show()\n",
239
+ "\n",
240
+ "avg_deg = sum(degrees)/len(degrees)\n",
241
+ "clustering = nx.average_clustering(G)\n",
242
+ "density = nx.density(G)\n",
243
+ "#avg_dist = nx.average_shortest_path_length(G)\n",
244
+ "#radius = nx.radius(G)\n",
245
+ "#diameter = nx.diameter(G)\n",
246
+ "\n",
247
+ "print(\"\\nNetwork Properties:\")\n",
248
+ "print(f\"Average Degree: {avg_deg:.2f}\")\n",
249
+ "print(f\"Clustering Coefficient: {clustering:.3f}\")\n",
250
+ "print(f\"Density: {density:.3f}\")\n",
251
+ "#print(f\"Average Distance: {avg_dist:.3f}\")\n",
252
+ "#print(f\"Radius: {radius}\")\n",
253
+ "#print(f\"Diameter: {diameter}\")\n",
254
+ "\n",
255
+ "\n",
256
+ "plt.figure(figsize=(8,6))\n",
257
+ "#pos = nx.spring_layout(G, seed=42)\n",
258
+ "# pos = nx.kamada_kawai_layout(G)\n",
259
+ "pos = nx.circular_layout(G)\n",
260
+ "\n",
261
+ "nx.draw(G, pos, with_labels=True, node_color='pink', edge_color='blue',\n",
262
+ " node_size=800, font_color='black', font_size=8)\n",
263
+ "plt.title(\"road-euroroad\")\n",
264
+ "plt.show()"
265
+ ]
266
+ },
267
+ {
268
+ "cell_type": "markdown",
269
+ "id": "cccc0f61",
270
+ "metadata": {},
271
+ "source": [
272
+ "# **Q2(B) Implement page rank algorithm and calculate the number of iteration to determine the convergence point and indicate your result with a pre defined page rank function.**"
273
+ ]
274
+ },
275
+ {
276
+ "cell_type": "code",
277
+ "execution_count": null,
278
+ "id": "85c29c9e",
279
+ "metadata": {},
280
+ "outputs": [],
281
+ "source": [
282
+ "import networkx as nx\n",
283
+ "import numpy as np\n",
284
+ "\n",
285
+ "G = nx.DiGraph()\n",
286
+ "\n",
287
+ "G.add_nodes_from([1, 2, 3, 4])\n",
288
+ "\n",
289
+ "edges = [(1, 2), (1, 3), (2, 3), (4, 1), (3, 4), (4, 2)]\n",
290
+ "G.add_edges_from(edges)\n",
291
+ "\n",
292
+ "print(\"Nodes:\", G.nodes())\n",
293
+ "print(\"Edges:\", G.edges())\n",
294
+ "\n",
295
+ "d = 0.85 # Damping factor\n",
296
+ "N = len(G) # Number of nodes\n",
297
+ "PR = np.ones(N) / N # Initial PageRank\n",
298
+ "M = nx.to_numpy_array(G).T # Adjacency matrix\n",
299
+ "\n",
300
+ "# Normalize columns\n",
301
+ "for i in range(N):\n",
302
+ " if M[:, i].sum() != 0:\n",
303
+ " M[:, i] = M[:, i] / M[:, i].sum()\n",
304
+ "\n",
305
+ "# Iterative PageRank computation\n",
306
+ "tolerance = 1e-6\n",
307
+ "iteration = 0\n",
308
+ "while True:\n",
309
+ " iteration += 1\n",
310
+ " new_PR = (1 - d) / N + d * np.dot(M, PR)\n",
311
+ " if np.linalg.norm(new_PR - PR, 1) < tolerance:\n",
312
+ " break\n",
313
+ " PR = new_PR\n",
314
+ "\n",
315
+ "# results\n",
316
+ "manual_pagerank = {node + 1: round(rank, 4) for node, rank in enumerate(PR)}\n",
317
+ "print(\"\\nManual PageRank Results:\")\n",
318
+ "for node, value in manual_pagerank.items():\n",
319
+ " print(f\"Node {node}: {value}\")\n",
320
+ "\n",
321
+ "print(f\"\\n Converged after {iteration} iterations\")\n",
322
+ "\n",
323
+ "# Compare with NetworkX predefined PageRank\n",
324
+ "nx_pagerank = nx.pagerank(G, alpha=0.85)\n",
325
+ "print(\"\\nNetworkX PageRank Results:\")\n",
326
+ "for node, value in nx_pagerank.items():\n",
327
+ " print(f\"Node {node}: {round(value, 4)}\")"
328
+ ]
329
+ }
330
+ ],
331
+ "metadata": {
332
+ "kernelspec": {
333
+ "display_name": "Python 3",
334
+ "language": "python",
335
+ "name": "python3"
336
+ },
337
+ "language_info": {
338
+ "codemirror_mode": {
339
+ "name": "ipython",
340
+ "version": 3
341
+ },
342
+ "file_extension": ".py",
343
+ "mimetype": "text/x-python",
344
+ "name": "python",
345
+ "nbconvert_exporter": "python",
346
+ "pygments_lexer": "ipython3",
347
+ "version": "3.10.12"
348
+ }
349
+ },
350
+ "nbformat": 4,
351
+ "nbformat_minor": 5
352
+ }