itertoolkit 1.5.5__tar.gz → 1.5.9__tar.gz

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 (78) hide show
  1. itertoolkit-1.5.9/IMPORTS.md +48 -0
  2. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/PKG-INFO +1 -1
  3. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm-eval-metrics.pyproject.toml +2 -1
  4. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/IR/__init__.py +2 -1
  5. itertoolkit-1.5.9/bm_preprocessing/importer/IR/pagerank_mat.py +6 -0
  6. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/KALKI/__init__.py +2 -0
  7. itertoolkit-1.5.9/bm_preprocessing/importer/KALKI/pagerank_mat.py +6 -0
  8. itertoolkit-1.5.9/bm_preprocessing/importer/PY/__init__.py +5 -0
  9. itertoolkit-1.5.9/bm_preprocessing/importer/PY/vis_doc.py +6 -0
  10. itertoolkit-1.5.9/bm_preprocessing/src/IR/pagerank_mat.py +114 -0
  11. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/collaborative_filtering.py +1 -1
  12. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/content_based_filtering.py +2 -2
  13. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/pagerank.py +3 -3
  14. itertoolkit-1.5.9/bm_preprocessing/src/KALKI/pagerank_mat.py +164 -0
  15. itertoolkit-1.5.9/bm_preprocessing/src/PY/vis_doc.py +247 -0
  16. itertoolkit-1.5.9/bm_preprocessing/vsk.py +66 -0
  17. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/itertoolkit.pyproject.toml +1 -1
  18. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/pyproject.toml +1 -1
  19. itertoolkit-1.5.5/IMPORTS.md +0 -156
  20. itertoolkit-1.5.5/bm_preprocessing/importer/PY/__init__.py +0 -4
  21. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/.gitignore +0 -0
  22. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/EVAL_README.md +0 -0
  23. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/ITER_README.md +0 -0
  24. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/README.md +0 -0
  25. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/__init__.py +0 -0
  26. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/__init__.py +0 -0
  27. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/DM/__init__.py +0 -0
  28. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/DM/agg.py +0 -0
  29. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/DM/dbscan.py +0 -0
  30. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/DM/finals.py +0 -0
  31. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/DM/gsp.py +0 -0
  32. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/DM/test.py +0 -0
  33. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/Finals/__init__.py +0 -0
  34. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/Finals/kaadhal.py +0 -0
  35. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/Finals/raaka.py +0 -0
  36. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/Finals/seedan.py +0 -0
  37. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/Finals/vikram.py +0 -0
  38. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/IR/finals.py +0 -0
  39. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/IR/pagerank.py +0 -0
  40. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/IR/recommenders_pca.py +0 -0
  41. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/IR/test.py +0 -0
  42. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/KALKI/collaborative_filtering.py +0 -0
  43. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/KALKI/content_based_filtering.py +0 -0
  44. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/KALKI/pagerank.py +0 -0
  45. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/KALKI/pca.py +0 -0
  46. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/KALKI/pca_svd.py +0 -0
  47. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/KALKI/svd.py +0 -0
  48. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/PY/lib_doc.py +0 -0
  49. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/PY/python_doc.py +0 -0
  50. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/__init__.py +0 -0
  51. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/importer/_module_printer.py +0 -0
  52. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/DM/__init__.py +0 -0
  53. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/DM/agg.py +0 -0
  54. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/DM/dbscan.py +0 -0
  55. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/DM/finals.py +0 -0
  56. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/DM/gsp.py +0 -0
  57. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/DM/test.py +0 -0
  58. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/Finals/__init__.py +0 -0
  59. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/Finals/kaadhal.py +0 -0
  60. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/Finals/raaka.py +0 -0
  61. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/Finals/seedan.py +0 -0
  62. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/Finals/vikram.py +0 -0
  63. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/IR/__init__.py +0 -0
  64. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/IR/finals.py +0 -0
  65. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/IR/pagerank.py +0 -0
  66. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/IR/recommenders_pca.py +0 -0
  67. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/IR/test.py +0 -0
  68. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/__init__.py +0 -0
  69. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/item_features.csv +0 -0
  70. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/pca.py +0 -0
  71. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/pca_svd.py +0 -0
  72. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/svd.py +0 -0
  73. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/KALKI/user_items.csv +0 -0
  74. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/PY/__init__.py +0 -0
  75. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/PY/lib_doc.py +0 -0
  76. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/PY/python_doc.py +0 -0
  77. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/bm_preprocessing/src/__init__.py +0 -0
  78. {itertoolkit-1.5.5 → itertoolkit-1.5.9}/main.py +0 -0
@@ -0,0 +1,48 @@
1
+ # Imports Guide
2
+
3
+ ```python
4
+ # Top-level section access
5
+ from bm_preprocessing import DM
6
+ from bm_preprocessing import IR
7
+ from bm_preprocessing import PY
8
+ from bm_preprocessing import Finals
9
+ from bm_preprocessing import KALKI
10
+
11
+ # Finals exports
12
+ from bm_preprocessing.Finals import kaadhal
13
+ from bm_preprocessing.Finals import raaka
14
+ from bm_preprocessing.Finals import seedan
15
+ from bm_preprocessing.Finals import vikram
16
+
17
+ # DM exports
18
+ from bm_preprocessing.DM import agg
19
+ from bm_preprocessing.DM import dbscan
20
+ from bm_preprocessing.DM import finals
21
+ from bm_preprocessing.DM import gsp
22
+ from bm_preprocessing.DM import test
23
+
24
+ # IR exports
25
+ from bm_preprocessing.IR import finals
26
+ from bm_preprocessing.IR import pagerank
27
+ from bm_preprocessing.IR import recommenders_pca
28
+ from bm_preprocessing.IR import test
29
+
30
+ # PY exports
31
+ from bm_preprocessing.PY import lib_doc
32
+ from bm_preprocessing.PY import python_doc
33
+
34
+ # KALKI exports
35
+ from bm_preprocessing.KALKI import collaborative_filtering
36
+ from bm_preprocessing.KALKI import content_based_filtering
37
+ from bm_preprocessing.KALKI import pagerank
38
+ from bm_preprocessing.KALKI import pca
39
+ from bm_preprocessing.KALKI import pca_svd
40
+ from bm_preprocessing.KALKI import svd
41
+
42
+ # Importer-layer access
43
+ from bm_preprocessing.importer.DM import agg, dbscan, finals, gsp, test
44
+ from bm_preprocessing.importer.IR import finals, pagerank, recommenders_pca, test
45
+ from bm_preprocessing.importer.PY import lib_doc, python_doc
46
+ from bm_preprocessing.importer.Finals import kaadhal, raaka, seedan, vikram
47
+ from bm_preprocessing.importer.KALKI import collaborative_filtering, content_based_filtering, pagerank, pca, pca_svd, svd
48
+ ```
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: itertoolkit
3
- Version: 1.5.5
3
+ Version: 1.5.9
4
4
  Summary: An itertools-inspired toolkit for cached iterator and data-structure processing
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: gsppy>=5.3.0
@@ -1,10 +1,11 @@
1
1
  [project]
2
2
  name = "bm-eval-metrics"
3
- version = "1.5.4"
3
+ version = "1.5.8"
4
4
  description = "Python package providing easy-to-use evaluation metrics and utilities for Machine Learning"
5
5
  readme = "EVAL_README.md"
6
6
  requires-python = ">=3.11"
7
7
  dependencies = [
8
+ "groq>=1.1.2",
8
9
  "gsppy>=5.3.0",
9
10
  "matplotlib>=3.10.8",
10
11
  "networkx>=3.6.1",
@@ -2,5 +2,6 @@ from .finals import finals
2
2
  from .pagerank import pagerank
3
3
  from .recommenders_pca import recommenders_pca
4
4
  from .test import test
5
+ from .pagerank_mat import pagerank_mat
5
6
 
6
- __all__ = ["finals", "test", "pagerank", "recommenders_pca"]
7
+ __all__ = ["finals", "test", "pagerank", "recommenders_pca", "pagerank_mat"]
@@ -0,0 +1,6 @@
1
+ from pathlib import Path
2
+
3
+ from .._module_printer import SourceCodeModule
4
+
5
+ _source_file = Path(__file__).parents[2] / "src" / "IR" / "pagerank_mat.py"
6
+ pagerank_mat = SourceCodeModule("bm_preprocessing.IR.pagerank_mat", _source_file)
@@ -4,6 +4,7 @@ from .pagerank import pagerank
4
4
  from .pca import pca
5
5
  from .pca_svd import pca_svd
6
6
  from .svd import svd
7
+ from .pagerank_mat import pagerank_mat
7
8
 
8
9
  __all__ = [
9
10
  "collaborative_filtering",
@@ -12,4 +13,5 @@ __all__ = [
12
13
  "pca",
13
14
  "pca_svd",
14
15
  "svd",
16
+ "pagerank_mat",
15
17
  ]
@@ -0,0 +1,6 @@
1
+ from pathlib import Path
2
+
3
+ from .._module_printer import SourceCodeModule
4
+
5
+ _source_file = Path(__file__).parents[2] / "src" / "KALKI" / "pagerank_mat.py"
6
+ pagerank_mat = SourceCodeModule("bm_preprocessing.KALKI.pagerank_mat", _source_file)
@@ -0,0 +1,5 @@
1
+ from .lib_doc import lib_doc
2
+ from .python_doc import python_doc
3
+ from .vis_doc import vis_doc
4
+
5
+ __all__ = ["lib_doc", "python_doc", "vis_doc"]
@@ -0,0 +1,6 @@
1
+ from pathlib import Path
2
+
3
+ from .._module_printer import SourceCodeModule
4
+
5
+ _source_file = Path(__file__).parents[2] / "src" / "PY" / "vis_doc.py"
6
+ vis_doc = SourceCodeModule("bm_preprocessing.PY.vis_doc", _source_file)
@@ -0,0 +1,114 @@
1
+ import matplotlib.pyplot as plt
2
+ import networkx as nx
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+ # ===== INPUT =====
7
+ pages = ["A", "B", "C", "D"]
8
+ A = np.array(
9
+ [
10
+ [0, 1, 1, 0], # A -> B,C
11
+ [0, 0, 1, 0], # B -> C
12
+ [1, 0, 0, 0], # C -> A
13
+ [0, 0, 1, 0], # D -> C
14
+ ],
15
+ dtype=float,
16
+ )
17
+
18
+ d = 0.85
19
+ max_iter = 20
20
+ tol = 1e-8
21
+ n = len(pages)
22
+
23
+ # ===== STEP 1: TRANSITION MATRIX (COLUMN STOCHASTIC) =====
24
+ S = np.zeros_like(A)
25
+
26
+ for j in range(n):
27
+ out_degree = A[j].sum()
28
+ if out_degree > 0:
29
+ S[j] = A[j] / out_degree
30
+ else:
31
+ S[j] = np.ones(n) / n # dangling node
32
+
33
+ S = S.T # convert to column-stochastic
34
+
35
+ print("Transition Matrix S:")
36
+ print(pd.DataFrame(S, index=pages, columns=pages))
37
+
38
+ # ===== STEP 2: GOOGLE MATRIX =====
39
+ M = d * S + (1 - d) / n * np.ones((n, n))
40
+
41
+ print("\nGoogle Matrix M:")
42
+ print(pd.DataFrame(M, index=pages, columns=pages))
43
+
44
+ # ===== STEP 3: INITIAL RANK =====
45
+ r = np.ones(n) / n
46
+ history = [r.copy()]
47
+
48
+ print("\nInitial PageRank:")
49
+ print(pd.DataFrame({"Page": pages, "PR": r}))
50
+
51
+ # ===== STEP 4: ITERATIONS =====
52
+ for it in range(1, max_iter + 1):
53
+ r_new = M @ r
54
+ history.append(r_new.copy())
55
+
56
+ print(f"\nIteration {it}")
57
+ print(pd.DataFrame({"Page": pages, "PR": r_new.round(6)}))
58
+
59
+ diff = np.linalg.norm(r_new - r, 1)
60
+ r = r_new
61
+
62
+ if diff < tol:
63
+ break
64
+
65
+ # ===== FINAL RESULT =====
66
+ final_df = pd.DataFrame({"Page": pages, "Final PR": r})
67
+ final_df = final_df.sort_values("Final PR", ascending=False)
68
+
69
+ print("\nFinal PageRank:")
70
+ print(final_df.round(6))
71
+
72
+ # ===== GRAPH VISUALIZATION (NODE SIZE ∝ PageRank) =====
73
+ G = nx.DiGraph()
74
+ for i, src in enumerate(pages):
75
+ for j, dst in enumerate(pages):
76
+ if A[i, j] == 1:
77
+ G.add_edge(src, dst)
78
+
79
+ plt.figure(figsize=(6, 4))
80
+ pos = nx.spring_layout(G, seed=42)
81
+
82
+ # --- Min-Max scaling for node sizes ---
83
+ pr_dict = {pages[i]: r[i] for i in range(n)}
84
+ pr_values = np.array([pr_dict[p] for p in G.nodes()])
85
+
86
+ min_size, max_size = 500, 5000
87
+ sizes = min_size + (pr_values - pr_values.min()) / (pr_values.max() - pr_values.min()) * (max_size - min_size)
88
+
89
+ nx.draw(G, pos, with_labels=True, node_size=sizes, arrows=True)
90
+ plt.title("Graph Visualization (node size ∝ PageRank)")
91
+ plt.show()
92
+
93
+ # ===== VISUALIZATION 2: CONVERGENCE =====
94
+ history_arr = np.array(history)
95
+
96
+ plt.figure()
97
+ for i, p in enumerate(pages):
98
+ plt.plot(history_arr[:, i], label=p)
99
+
100
+ plt.xlabel("Iteration")
101
+ plt.ylabel("PageRank")
102
+ plt.title("PageRank Convergence")
103
+ plt.legend()
104
+ plt.grid()
105
+ plt.show()
106
+
107
+ # ===== VISUALIZATION 3: FINAL SCORES =====
108
+ plt.figure()
109
+ plt.bar(final_df["Page"], final_df["Final PR"])
110
+ plt.xlabel("Page")
111
+ plt.ylabel("PageRank Score")
112
+ plt.title("Final PageRank Ranking")
113
+ plt.grid()
114
+ plt.show()
@@ -224,7 +224,7 @@ for i in range(df_iu.shape[0]):
224
224
  if i == ti and j == tu:
225
225
  ax.add_patch(
226
226
  plt.Rectangle(
227
- (j - 0.5, i - 0.5), 1, 1, fill=True, color="#4fc3f7", zorder=2
227
+ (j - 0.5, i - 0.5), 1, 1, fill=True, color="lightblue", zorder=2
228
228
  )
229
229
  )
230
230
  ax.text(
@@ -369,12 +369,12 @@ def set_tick_labels(ax, df):
369
369
  ax = axes[0, 0]
370
370
  ti = list(df_iu.index).index(target_item)
371
371
  tu = list(df_iu.columns).index(target_user)
372
- im = ax.imshow(df_iu.values.astype(float), cmap="YlGn", aspect="auto", vmin=1, vmax=5)
372
+ im = ax.imshow(df_iu.values.astype(float), cmap="viridis", aspect="auto", vmin=1, vmax=5)
373
373
  for i in range(df_iu.shape[0]):
374
374
  for j in range(df_iu.shape[1]):
375
375
  val = df_iu.iloc[i, j]
376
376
  if i == ti and j == tu:
377
- ax.add_patch(plt.Rectangle((j-.5, i-.5), 1, 1, fill=True, color="#4fc3f7", zorder=2))
377
+ ax.add_patch(plt.Rectangle((j-.5, i-.5), 1, 1, fill=True, color="lightblue", zorder=2))
378
378
  ax.text(j, i, "?", ha="center", va="center", fontsize=9, fontweight="bold", color="navy", zorder=3)
379
379
  elif pd.notna(val):
380
380
  ax.text(j, i, int(val), ha="center", va="center", fontsize=8)
@@ -104,8 +104,8 @@ for it in range(1, max_iter + 1):
104
104
 
105
105
  if terms:
106
106
  # Standard formula shown in full symbolic form
107
- print(f" PR({p}) = (1-d)/N + d × ( {' + '.join(terms)} )")
108
- print(f" = {base:.4f} + {d} × ( {' + '.join(nums)} )")
107
+ print(f" PR({p}) = (1-d)/N + d x ( {' + '.join(terms)} )")
108
+ print(f" = {base:.4f} + {d} x ( {' + '.join(nums)} )")
109
109
  # Google formula (symbolic) — uncomment if using Formula B above
110
110
  # print(f" [Google] PR({p}) = (1-d) + d × ( {' + '.join(terms)} )")
111
111
  # print(f" = {1-d:.4f} + {d} × ( {' + '.join(nums)} )")
@@ -132,7 +132,7 @@ for it in range(1, max_iter + 1):
132
132
  print(iter_df.to_string(index=False))
133
133
 
134
134
  if diff < tol:
135
- print(f"\n Converged at iteration {it} (Σ|ΔPR| = {diff:.2e} < tol={tol})")
135
+ print(f"\n Converged at iteration {it} (Σ|ΔPR| = {diff:.2e} < tol={tol})")
136
136
  break
137
137
 
138
138
  # ===== CONVERGENCE TABLE =====
@@ -0,0 +1,164 @@
1
+ import matplotlib.pyplot as plt
2
+ import networkx as nx
3
+ import numpy as np
4
+ import pandas as pd
5
+ from matplotlib.gridspec import GridSpec
6
+
7
+ # ===== INPUT =====
8
+ pages = ["A", "B", "C", "D"]
9
+ A = np.array(
10
+ [
11
+ [0, 1, 1, 0], # A -> B,C
12
+ [0, 0, 1, 0], # B -> C
13
+ [1, 0, 0, 0], # C -> A
14
+ [0, 0, 1, 0], # D -> C
15
+ ],
16
+ dtype=float,
17
+ )
18
+
19
+ d = 0.85
20
+ max_iter = 20
21
+ tol = 1e-8
22
+ n = len(pages)
23
+
24
+ # ===== STEP 1: TRANSITION MATRIX =====
25
+ S = np.zeros_like(A)
26
+
27
+ for j in range(n):
28
+ out_degree = A[j].sum()
29
+ if out_degree > 0:
30
+ S[j] = A[j] / out_degree
31
+ else:
32
+ S[j] = np.ones(n) / n # dangling node
33
+
34
+ S = S.T # column-stochastic
35
+
36
+ # ===== STEP 2: GOOGLE MATRIX =====
37
+ M = d * S + (1 - d) / n * np.ones((n, n))
38
+
39
+ # ===== STEP 3: INITIAL RANK =====
40
+ r = np.ones(n) / n
41
+ history = [r.copy()]
42
+
43
+ # ===== STEP 4: ITERATIONS =====
44
+ for _ in range(max_iter):
45
+ r_new = M @ r
46
+ history.append(r_new.copy())
47
+
48
+ diff = np.linalg.norm(r_new - r, 1)
49
+ r = r_new
50
+
51
+ if diff < tol:
52
+ print(f"Converged after {_+1} iterations with diff={diff:.2e}")
53
+ break
54
+
55
+ # ===== FINAL RESULT =====
56
+ final_df = pd.DataFrame({"Page": pages, "Final PR": r})
57
+ final_df = final_df.sort_values("Final PR", ascending=False)
58
+
59
+ print("\nFinal PageRank:")
60
+ print(final_df.round(6))
61
+
62
+ # ===== TABULATE ITERATIONS =====
63
+ history_arr = np.array(history)
64
+
65
+ iter_cols = [f"Iter_{i}" for i in range(history_arr.shape[0])]
66
+ iter_df = pd.DataFrame(history_arr.T, index=pages, columns=iter_cols)
67
+
68
+ print("\nPageRank Iterations Table:")
69
+ print(iter_df.round(6).to_string())
70
+
71
+ # ===== CONVERT FOR VISUALIZATION =====
72
+ pr = {pages[i]: r[i] for i in range(n)}
73
+
74
+ history_dict = []
75
+ for vec in history:
76
+ history_dict.append({pages[i]: vec[i] for i in range(n)})
77
+
78
+ # ===== GRAPH =====
79
+ G = nx.DiGraph()
80
+ for i, src in enumerate(pages):
81
+ for j, dst in enumerate(pages):
82
+ if A[i, j] == 1:
83
+ G.add_edge(src, dst)
84
+
85
+ # ===== VISUALIZATION =====
86
+ fig = plt.figure(figsize=(16, 10))
87
+ gs = GridSpec(2, 3, figure=fig, hspace=0.45, wspace=0.35)
88
+
89
+ ax_graph = fig.add_subplot(gs[:, :2])
90
+ ax_bar = fig.add_subplot(gs[0, 2])
91
+ ax_conv = fig.add_subplot(gs[1, 2])
92
+
93
+ # ── GRAPH ─────────────────────────────
94
+ pos = nx.spring_layout(G, seed=42, k=2.2)
95
+
96
+ pr_vals = np.array([pr[p] for p in G.nodes()])
97
+ den = (pr_vals.max() - pr_vals.min()) + 1e-9 # avoid zero division
98
+ pr_norm = (pr_vals - pr_vals.min()) / den
99
+ node_sizes = pr_norm * 3500 + 900
100
+
101
+ node_colors = [plt.cm.tab10(i / len(pages)) for i in range(len(G.nodes()))]
102
+
103
+ nx.draw_networkx_edges(
104
+ G, pos, ax=ax_graph,
105
+ arrows=True, arrowsize=22,
106
+ connectionstyle="arc3,rad=0.12",
107
+ width=1.8,
108
+ )
109
+
110
+ nx.draw_networkx_nodes(
111
+ G, pos, ax=ax_graph,
112
+ node_size=node_sizes,
113
+ node_color=node_colors,
114
+ )
115
+
116
+ labels = {p: f"{p}\n{pr[p]:.4f}" for p in G.nodes()}
117
+ nx.draw_networkx_labels(
118
+ G, pos, labels=labels, ax=ax_graph,
119
+ font_size=10, font_weight="bold",
120
+ )
121
+
122
+ ax_graph.set_title("PageRank Graph (node size ∝ PR)", fontweight="bold")
123
+ ax_graph.axis("off")
124
+
125
+ # ── BAR CHART ─────────────────────────
126
+ sorted_pages = final_df["Page"].tolist()
127
+ sorted_prs = final_df["Final PR"].tolist()
128
+
129
+ bars = ax_bar.barh(sorted_pages, sorted_prs)
130
+
131
+ for bar, val in zip(bars, sorted_prs):
132
+ ax_bar.text(
133
+ bar.get_width() + 0.003,
134
+ bar.get_y() + bar.get_height() / 2,
135
+ f"{val:.4f}",
136
+ va="center",
137
+ fontsize=9,
138
+ )
139
+
140
+ ax_bar.set_title("Final PR Ranking", fontweight="bold")
141
+ ax_bar.set_xlim(0, max(sorted_prs) * 1.25)
142
+ ax_bar.invert_yaxis()
143
+
144
+ # ── CONVERGENCE ───────────────────────
145
+ for p in pages:
146
+ vals = [history_dict[i][p] for i in range(len(history_dict))]
147
+ ax_conv.plot(
148
+ range(len(vals)),
149
+ vals,
150
+ marker="o",
151
+ linewidth=1.8,
152
+ label=p,
153
+ )
154
+
155
+ ax_conv.set_title("Convergence", fontweight="bold")
156
+ ax_conv.set_xlabel("Iteration")
157
+ ax_conv.set_ylabel("PageRank")
158
+ ax_conv.legend()
159
+ ax_conv.grid(True, alpha=0.3)
160
+
161
+ # ===== FINAL LAYOUT =====
162
+ fig.suptitle("PageRank Algorithm", fontsize=16, fontweight="bold")
163
+ plt.tight_layout()
164
+ plt.show()
@@ -0,0 +1,247 @@
1
+ # =========================================================
2
+ # VISUALIZATION CHEAT SHEET (Matplotlib, Seaborn, Plotly, NetworkX)
3
+ # =========================================================
4
+
5
+ import numpy as np
6
+ import pandas as pd
7
+
8
+ import matplotlib.pyplot as plt
9
+ import seaborn as sns
10
+ import plotly.express as px
11
+ import networkx as nx
12
+
13
+ # =========================================================
14
+ # SAMPLE DATA
15
+ # =========================================================
16
+ np.random.seed(42)
17
+
18
+ x = np.arange(1, 11)
19
+ y = np.random.randint(10, 100, size=10)
20
+
21
+ df = pd.DataFrame({
22
+ "x": x,
23
+ "y": y,
24
+ "category": ["A", "B"] * 5
25
+ })
26
+
27
+ # =========================================================
28
+ # MATPLOTLIB
29
+ # =========================================================
30
+
31
+ # ---- BAR CHART ----
32
+ plt.figure()
33
+ plt.bar(x, y)
34
+ plt.title("Bar Chart")
35
+ plt.xlabel("X")
36
+ plt.ylabel("Y")
37
+ plt.show()
38
+
39
+ # ---- PIE CHART ----
40
+ plt.figure()
41
+ plt.pie(y, labels=x, autopct="%1.1f%%")
42
+ plt.title("Pie Chart")
43
+ plt.show()
44
+
45
+ # ---- HISTOGRAM ----
46
+ plt.figure()
47
+ plt.hist(y, bins=5)
48
+ plt.title("Histogram")
49
+ plt.show()
50
+
51
+ # ---- LINE CHART ----
52
+ plt.figure()
53
+ plt.plot(x, y, marker='o')
54
+ plt.title("Line Chart")
55
+ plt.show()
56
+
57
+ # ---- BOX PLOT ----
58
+ plt.figure()
59
+ plt.boxplot(y)
60
+ plt.title("Box Plot")
61
+ plt.show()
62
+
63
+ # ---- HEATMAP (imshow) ----
64
+ data = np.random.rand(5, 5)
65
+ plt.figure()
66
+ plt.imshow(data, cmap='viridis')
67
+ plt.colorbar()
68
+ plt.title("Heatmap (imshow)")
69
+ plt.show()
70
+
71
+
72
+ # =========================================================
73
+ # 2SEABORN
74
+ # =========================================================
75
+
76
+ # ---- BAR ----
77
+ sns.barplot(x="x", y="y", data=df)
78
+ plt.title("Seaborn Bar")
79
+ plt.show()
80
+
81
+ # ---- PIE (not native, use matplotlib) ----
82
+
83
+ # ---- HISTOGRAM ----
84
+ sns.histplot(df["y"], bins=5, kde=True)
85
+ plt.title("Seaborn Histogram")
86
+ plt.show()
87
+
88
+ # ---- LINE ----
89
+ sns.lineplot(x="x", y="y", data=df)
90
+ plt.title("Seaborn Line")
91
+ plt.show()
92
+
93
+ # ---- BOX ----
94
+ sns.boxplot(y="y", data=df)
95
+ plt.title("Seaborn Box")
96
+ plt.show()
97
+
98
+ # ---- HEATMAP ----
99
+ sns.heatmap(data, annot=True, cmap="coolwarm")
100
+ plt.title("Seaborn Heatmap")
101
+ plt.show()
102
+
103
+
104
+ # =========================================================
105
+ # PLOTLY (INTERACTIVE)
106
+ # =========================================================
107
+
108
+ # ---- BAR ----
109
+ fig = px.bar(df, x="x", y="y", title="Plotly Bar")
110
+ fig.show()
111
+
112
+ # ---- PIE ----
113
+ fig = px.pie(df, values="y", names="x", title="Plotly Pie")
114
+ fig.show()
115
+
116
+ # ---- HISTOGRAM ----
117
+ fig = px.histogram(df, x="y", nbins=5, title="Plotly Histogram")
118
+ fig.show()
119
+
120
+ # ---- LINE ----
121
+ fig = px.line(df, x="x", y="y", title="Plotly Line")
122
+ fig.show()
123
+
124
+ # ---- BOX ----
125
+ fig = px.box(df, y="y", title="Plotly Box")
126
+ fig.show()
127
+
128
+ # ---- HEATMAP ----
129
+ fig = px.imshow(data, title="Plotly Heatmap")
130
+ fig.show()
131
+
132
+
133
+ # =========================================================
134
+ # NETWORKX (GRAPH VISUALIZATION)
135
+ # =========================================================
136
+
137
+ G = nx.DiGraph()
138
+ edges = [("A", "B"), ("A", "C"), ("B", "C"), ("C", "A")]
139
+ G.add_edges_from(edges)
140
+
141
+ plt.figure()
142
+ pos = nx.spring_layout(G)
143
+ nx.draw(G, pos, with_labels=True, node_size=1000, arrows=True)
144
+ plt.title("Network Graph")
145
+ plt.show()
146
+
147
+
148
+ # =========================================================
149
+ # MATPLOTLIB NUANCES / CONFIGURATION
150
+ # =========================================================
151
+
152
+ # ---- MULTIPLE PLOTS (SUBPLOTS) ----
153
+ fig, axs = plt.subplots(2, 2, figsize=(8, 6))
154
+
155
+ axs[0, 0].plot(x, y)
156
+ axs[0, 0].set_title("Line")
157
+
158
+ axs[0, 1].bar(x, y)
159
+ axs[0, 1].set_title("Bar")
160
+
161
+ axs[1, 0].hist(y)
162
+ axs[1, 0].set_title("Histogram")
163
+
164
+ axs[1, 1].boxplot(y)
165
+ axs[1, 1].set_title("Box")
166
+
167
+ plt.tight_layout()
168
+ plt.show()
169
+
170
+
171
+ # ---- MULTIPLE LINES ----
172
+ plt.figure()
173
+ plt.plot(x, y, label="Line1")
174
+ plt.plot(x, y[::-1], label="Line2")
175
+ plt.legend()
176
+ plt.title("Multiple Lines")
177
+ plt.show()
178
+
179
+
180
+ # ---- AXES CONFIG ----
181
+ plt.figure()
182
+ plt.plot(x, y)
183
+ plt.xlim(0, 12)
184
+ plt.ylim(0, 120)
185
+ plt.xticks(rotation=45)
186
+ plt.grid(True)
187
+ plt.title("Axis Config")
188
+ plt.show()
189
+
190
+
191
+ # ---- STYLE ----
192
+ plt.style.use("ggplot")
193
+
194
+
195
+ # =========================================================
196
+ # 🎛️ PARAMETERS CHEAT SHEET
197
+ # =========================================================
198
+
199
+ """
200
+ MATPLOTLIB:
201
+ -----------
202
+ plt.plot(x, y, color='blue', linestyle='--', marker='o')
203
+ plt.bar(x, y, width=0.5)
204
+ plt.hist(data, bins=10)
205
+ plt.imshow(data, cmap='viridis')
206
+
207
+ COMMON PARAMS:
208
+ color, cmap, alpha, linewidth, linestyle, marker, label
209
+
210
+
211
+ SEABORN:
212
+ --------
213
+ sns.barplot(x=, y=, data=, palette=)
214
+ sns.histplot(data, bins=, kde=True)
215
+ sns.heatmap(data, annot=True, cmap=)
216
+
217
+ COMMON PARAMS:
218
+ palette, hue, style, size, linewidth
219
+
220
+
221
+ PLOTLY:
222
+ -------
223
+ px.bar(df, x=, y=, color=)
224
+ px.line(df, x=, y=)
225
+ px.imshow(data)
226
+
227
+ COMMON PARAMS:
228
+ title, color, labels, template
229
+
230
+
231
+ NETWORKX:
232
+ ---------
233
+ nx.draw(G, pos, node_size=, node_color=, with_labels=True)
234
+
235
+ LAYOUTS:
236
+ spring_layout, circular_layout, shell_layout
237
+
238
+
239
+ GENERAL:
240
+ --------
241
+ figsize=(w, h)
242
+ title()
243
+ xlabel(), ylabel()
244
+ legend()
245
+ grid(True)
246
+ tight_layout()
247
+ """
@@ -0,0 +1,66 @@
1
+ from __future__ import annotations
2
+ from groq import Groq
3
+
4
+ # ─── HYPERPARAMETERS ──────────────────────────────────────────────────────────
5
+ API_KEY = "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"
6
+ MODEL_NAME = "openai/gpt-oss-120b"
7
+ TEMPERATURE = 0.2
8
+
9
+ SYSTEM_PROMPT = """
10
+ You are an expert Python engineer and code reviewer.
11
+
12
+ When given a query or task, you MUST respond with:
13
+ 1. Production-ready Python code that is:
14
+ - Fully error-proof (all exceptions handled gracefully)
15
+ - Bug-free and logically correct
16
+ - Edge-case covered (empty input, None, type mismatches, boundary values, etc.)
17
+ - Clean, readable, and PEP-8 compliant
18
+ - Well-structured with clear variable names and docstrings
19
+
20
+ 2. A short "Changes / Config" section listing:
21
+ - Any hyperparameters or constants the user should adjust
22
+ - File paths, API keys, or environment variables needed
23
+ - Optional improvements or flags
24
+
25
+ 3. A brief explanation of what the code does and why key decisions were made.
26
+
27
+ Always wrap code in proper Python markdown code blocks.
28
+ Never leave placeholders like `pass` or `# TODO` unless explicitly asked.
29
+ """.strip()
30
+ # ─────────────────────────────────────────────────────────────────────────────
31
+
32
+
33
+ def parrot(query: str) -> str:
34
+ """
35
+ Send a query to Groq and stream the model response to the terminal,
36
+ then return the full response text.
37
+
38
+ Args:
39
+ query: A non-empty string prompt/question.
40
+
41
+ Returns:
42
+ The model's response as a stripped string.
43
+
44
+ Raises:
45
+ ValueError: If query is not a non-empty string.
46
+ groq.APIError: On API-level failures.
47
+ """
48
+ if not isinstance(query, str) or not query.strip():
49
+ raise ValueError("query must be a non-empty string")
50
+
51
+ client = Groq(api_key=API_KEY)
52
+
53
+ response = client.chat.completions.create(
54
+ model=MODEL_NAME,
55
+ messages=[
56
+ {"role": "system", "content": SYSTEM_PROMPT},
57
+ {"role": "user", "content": query.strip()},
58
+ ],
59
+ temperature=TEMPERATURE,
60
+ )
61
+
62
+ content = response.choices[0].message.content
63
+ result = content.strip() if content else ""
64
+
65
+ print(result)
66
+ return result
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "itertoolkit"
3
- version = "1.5.4"
3
+ version = "1.5.8"
4
4
  description = "An itertools-inspired toolkit for cached iterator and data-structure processing"
5
5
  readme = "ITER_README.md"
6
6
  requires-python = ">=3.11"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "itertoolkit"
3
- version = "1.5.5"
3
+ version = "1.5.9"
4
4
  description = "An itertools-inspired toolkit for cached iterator and data-structure processing"
5
5
  readme = "ITER_README.md"
6
6
  requires-python = ">=3.11"
@@ -1,156 +0,0 @@
1
- # Imports Guide
2
-
3
- Below are the same import patterns grouped package-wise.
4
-
5
- ## 1) bm_preprocessing
6
-
7
- ```python
8
- # Top-level section access
9
- from bm_preprocessing import DM
10
- from bm_preprocessing import IR
11
- from bm_preprocessing import PY
12
- from bm_preprocessing import Finals
13
- from bm_preprocessing import KALKI
14
-
15
- # Finals exports
16
- from bm_preprocessing.Finals import kaadhal
17
- from bm_preprocessing.Finals import raaka
18
- from bm_preprocessing.Finals import seedan
19
- from bm_preprocessing.Finals import vikram
20
-
21
- # DM exports
22
- from bm_preprocessing.DM import agg
23
- from bm_preprocessing.DM import dbscan
24
- from bm_preprocessing.DM import finals
25
- from bm_preprocessing.DM import gsp
26
- from bm_preprocessing.DM import test
27
-
28
- # IR exports
29
- from bm_preprocessing.IR import finals
30
- from bm_preprocessing.IR import pagerank
31
- from bm_preprocessing.IR import recommenders_pca
32
- from bm_preprocessing.IR import test
33
-
34
- # PY exports
35
- from bm_preprocessing.PY import lib_doc
36
- from bm_preprocessing.PY import python_doc
37
-
38
- # KALKI exports
39
- from bm_preprocessing.KALKI import collaborative_filtering
40
- from bm_preprocessing.KALKI import content_based_filtering
41
- from bm_preprocessing.KALKI import pagerank
42
- from bm_preprocessing.KALKI import pca
43
- from bm_preprocessing.KALKI import pca_svd
44
- from bm_preprocessing.KALKI import svd
45
-
46
- # Importer-layer access
47
- from bm_preprocessing.importer.DM import agg, dbscan, finals, gsp, test
48
- from bm_preprocessing.importer.IR import finals, pagerank, recommenders_pca, test
49
- from bm_preprocessing.importer.PY import lib_doc, python_doc
50
- from bm_preprocessing.importer.Finals import kaadhal, raaka, seedan, vikram
51
- from bm_preprocessing.importer.KALKI import collaborative_filtering, content_based_filtering, pagerank, pca, pca_svd, svd
52
- ```
53
-
54
- ## 2) bm_eval_metrics
55
-
56
- ```python
57
- # Top-level section access
58
- from bm_eval_metrics import DM
59
- from bm_eval_metrics import IR
60
- from bm_eval_metrics import PY
61
- from bm_eval_metrics import Finals
62
- from bm_eval_metrics import KALKI
63
-
64
- # Finals exports
65
- from bm_eval_metrics.Finals import kaadhal
66
- from bm_eval_metrics.Finals import raaka
67
- from bm_eval_metrics.Finals import seedan
68
- from bm_eval_metrics.Finals import vikram
69
-
70
- # DM exports
71
- from bm_eval_metrics.DM import agg
72
- from bm_eval_metrics.DM import dbscan
73
- from bm_eval_metrics.DM import finals
74
- from bm_eval_metrics.DM import gsp
75
- from bm_eval_metrics.DM import test
76
-
77
- # IR exports
78
- from bm_eval_metrics.IR import finals
79
- from bm_eval_metrics.IR import pagerank
80
- from bm_eval_metrics.IR import recommenders_pca
81
- from bm_eval_metrics.IR import test
82
-
83
- # PY exports
84
- from bm_eval_metrics.PY import lib_doc
85
- from bm_eval_metrics.PY import python_doc
86
-
87
- # KALKI exports
88
- from bm_eval_metrics.KALKI import collaborative_filtering
89
- from bm_eval_metrics.KALKI import content_based_filtering
90
- from bm_eval_metrics.KALKI import pagerank
91
- from bm_eval_metrics.KALKI import pca
92
- from bm_eval_metrics.KALKI import pca_svd
93
- from bm_eval_metrics.KALKI import svd
94
-
95
- # Importer-layer access
96
- from bm_eval_metrics.importer.DM import agg, dbscan, finals, gsp, test
97
- from bm_eval_metrics.importer.IR import finals, pagerank, recommenders_pca, test
98
- from bm_eval_metrics.importer.PY import lib_doc, python_doc
99
- from bm_eval_metrics.importer.Finals import kaadhal, raaka, seedan, vikram
100
- from bm_eval_metrics.importer.KALKI import collaborative_filtering, content_based_filtering, pagerank, pca, pca_svd, svd
101
- ```
102
-
103
- ## 3) itertoolkit
104
-
105
- ```python
106
- # Top-level section access
107
- from itertoolkit import DM
108
- from itertoolkit import IR
109
- from itertoolkit import PY
110
- from itertoolkit import Finals
111
- from itertoolkit import KALKI
112
-
113
- # Finals exports
114
- from itertoolkit.Finals import kaadhal
115
- from itertoolkit.Finals import raaka
116
- from itertoolkit.Finals import seedan
117
- from itertoolkit.Finals import vikram
118
-
119
- # DM exports
120
- from itertoolkit.DM import agg
121
- from itertoolkit.DM import dbscan
122
- from itertoolkit.DM import finals
123
- from itertoolkit.DM import gsp
124
- from itertoolkit.DM import test
125
-
126
- # IR exports
127
- from itertoolkit.IR import finals
128
- from itertoolkit.IR import pagerank
129
- from itertoolkit.IR import recommenders_pca
130
- from itertoolkit.IR import test
131
-
132
- # PY exports
133
- from itertoolkit.PY import lib_doc
134
- from itertoolkit.PY import python_doc
135
-
136
- # KALKI exports
137
- from itertoolkit.KALKI import collaborative_filtering
138
- from itertoolkit.KALKI import content_based_filtering
139
- from itertoolkit.KALKI import pagerank
140
- from itertoolkit.KALKI import pca
141
- from itertoolkit.KALKI import pca_svd
142
- from itertoolkit.KALKI import svd
143
-
144
- # Importer-layer access
145
- from itertoolkit.importer.DM import agg, dbscan, finals, gsp, test
146
- from itertoolkit.importer.IR import finals, pagerank, recommenders_pca, test
147
- from itertoolkit.importer.PY import lib_doc, python_doc
148
- from itertoolkit.importer.Finals import kaadhal, raaka, seedan, vikram
149
- from itertoolkit.importer.KALKI import collaborative_filtering, content_based_filtering, pagerank, pca, pca_svd, svd
150
- ```
151
-
152
- Example:
153
-
154
- ```python
155
- from bm_preprocessing.Finals import raaka
156
- ```
@@ -1,4 +0,0 @@
1
- from .lib_doc import lib_doc
2
- from .python_doc import python_doc
3
-
4
- __all__ = ["lib_doc", "python_doc"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes