scypyy 0.1.0__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.
scypyy-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: scypyy
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Python :: 3
5
+ Classifier: Operating System :: OS Independent
6
+ Requires-Python: >=3.9
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "scypyy"
7
+ version = "0.1.0"
8
+ description = ""
9
+ requires-python = ">=3.9"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Operating System :: OS Independent",
13
+ ]
14
+
15
+ [tool.setuptools]
16
+ packages = ["scypyy"]
@@ -0,0 +1,69 @@
1
+ """scypyy — code snippets stored inside the library, accessed as attributes.
2
+
3
+ All snippet code is embedded directly in this package (see ``_data.py``).
4
+ Nothing is read from disk at runtime. Access a snippet by name::
5
+
6
+ import scypyy
7
+ scypyy.bwp # shows the stored code in the REPL
8
+ scypyy.nn_final # another snippet
9
+ print(scypyy.bwp) # prints the code
10
+ code = scypyy.bwp # a normal str you can save or exec
11
+
12
+ Use ``scypyy.available()`` to list every snippet name.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from ._data import SNIPPETS
18
+
19
+ __version__ = "0.1.0"
20
+
21
+
22
+ class Code(str):
23
+ """A ``str`` subclass that displays its raw contents in the REPL.
24
+
25
+ A normal string echoes with escaped newlines (``\\n``). This shows the
26
+ actual code instead, while still behaving like an ordinary string.
27
+ """
28
+
29
+ __slots__ = ()
30
+
31
+ def __repr__(self) -> str: # noqa: D105
32
+ return str.__str__(self)
33
+
34
+
35
+ def available():
36
+ """Return a sorted list of every stored snippet name."""
37
+ return sorted(SNIPPETS)
38
+
39
+
40
+ def get(name: str) -> Code:
41
+ """Return the stored code for ``name`` (case-insensitive) as a :class:`Code`."""
42
+ if name in SNIPPETS:
43
+ return Code(SNIPPETS[name])
44
+ for key in SNIPPETS:
45
+ if key.lower() == name.lower():
46
+ return Code(SNIPPETS[key])
47
+ raise KeyError(
48
+ f"no snippet named {name!r}. Available: {', '.join(available()) or '(none)'}"
49
+ )
50
+
51
+
52
+ def __getattr__(name: str) -> Code:
53
+ """Resolve ``scypyy.<name>`` to the stored code for ``<name>`` (PEP 562)."""
54
+ if name.startswith("_"):
55
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
56
+ try:
57
+ return get(name)
58
+ except KeyError:
59
+ raise AttributeError(
60
+ f"module {__name__!r} has no attribute {name!r}. "
61
+ f"Available snippets: {', '.join(available()) or '(none)'}"
62
+ ) from None
63
+
64
+
65
+ def __dir__():
66
+ return sorted(set(globals()) | set(SNIPPETS))
67
+
68
+
69
+ __all__ = ["available", "get", "Code"]
@@ -0,0 +1,11 @@
1
+ # Auto-generated: code snippets embedded as string constants.
2
+ # Do not read any external files at runtime — everything lives here.
3
+
4
+ SNIPPETS = {
5
+ 'LGD': '# x1,x2 are the input features\ndef LinearGradientDescent2(x1, x2, x3, y, lr, epochs):\n w0 = 0.25\n w1 = 0.65\n w2 = 0.65\n w3 = 0.65\n\n m = float(len(y))\n cost_hist = []\n\n for i in range(epochs):\n h = w0 + w1*x1 + w2*x2 + w3*x3\n cost = (1/(2*m)) * sum((h - y)**2)\n\n dw0 = (1/m) * sum(h - y)\n dw1 = (1/m) * sum((h - y) * x1)\n dw2 = (1/m) * sum((h - y) * x2)\n dw3 = (1/m) * sum((h - y) * x3)\n\n if i % 100 == 0:\n print(f"Cost: {cost} \\tIteration: {i}")\n\n w0 = w0 - lr * dw0\n w1 = w1 - lr * dw1\n w2 = w2 - lr * dw2\n w3 = w3 - lr * dw3\n\n cost_hist.append(cost)\n\n if len(cost_hist) > 1 and abs(cost_hist[-1] - cost_hist[-2]) < 1e-6:\n print(f"Converged at iteration {i}")\n break\n\n return w0, w1, w2, w3',
6
+ 'activationfunctions': 'def tanH(X):\n return (np.exp(X)-np.exp(-X))/(np.exp(X)+np.exp(-X))\n\ndef ReLU(X):\n return np.maximum(0, X)\n\ndef sigmoid(Z):\n s = 1/(1+np.exp(-Z))\n return s\n\ndef sigmoid_grad(y):\n return y * (1 - y)\n\ndef tanH_grad(y):\n return 1 - y**2\n\ndef ReLU_grad(x):\n return np.where(x > 0, 1, 0)\n\ndef eReLU(x, alpha=0.01):\n return np.where(x > 0, x, alpha * (np.exp(x) - 1))\n \ndef eReLU_grad(x, alpha=0.01):\n return np.where(x > 0, 1, alpha * np.exp(x))',
7
+ 'bwp': 'def BWP(par, cat, X, y):\n\n w1 = par["w1"]\n b1 = par["b1"]\n w2 = par["w2"]\n b2 = par["b2"]\n w3 = par["w3"]\n b3 = par["b3"]\n w4 = par["w4"]\n b4 = par["b4"]\n w5 = par["w5"]\n b5 = par["b5"]\n a1 = cat["a1"]\n a2 = cat["a2"]\n a3 = cat["a3"]\n a4 = cat["a4"]\n a5 = cat["a5"]\n\n m = y.shape[1]\n dz5 = a5 - y\n dw5 = np.dot(dz5, a4.T) / m\n db5 = np.sum(dz5, axis=1, keepdims=True) / m\n da4 = np.dot(w5.T, dz5)\n dz4 = da4 * ReLU_grad(a4)\n dw4 = np.dot(dz4, a3.T) / m\n db4 = np.sum(dz4, axis=1, keepdims=True) / m\n da3 = np.dot(w4.T, dz4)\n dz3 = da3 * eReLU_grad(a3)\n dw3 = np.dot(dz3, a2.T) / m\n db3 = np.sum(dz3, axis=1, keepdims=True) / m\n da2 = np.dot(w3.T, dz3)\n dz2 = da2 * ReLU_grad(a2)\n dw2 = np.dot(dz2, a1.T) / m\n db2 = np.sum(dz2, axis=1, keepdims=True) / m\n da1 = np.dot(w2.T, dz2)\n dz1 = da1 * ReLU_grad(a1)\n dw1 = np.dot(dz1, X.T) / m\n db1 = np.sum(dz1, axis=1, keepdims=True) / m\n\n grades = {"dw1": dw1, "db1": db1, "dw2": dw2, "db2": db2, "dw3": dw3, "db3": db3, "dw4": dw4, "db4": db4, "dw5": dw5, "db5": db5}\n return grades\n\ngrades = BWP(par,cache,x,y)\n\n\ndef update(par,grades,learning_rate = 0.01):\n w1 = par[\'w1\']\n b1 = par[\'b1\']\n w2 = par[\'w2\']\n b2 = par[\'b2\']\n w3 = par[\'w3\']\n b3 = par[\'b3\']\n w4 = par[\'w4\']\n b4 = par[\'b4\']\n w5 = par[\'w5\']\n b5 = par[\'b5\']\n dw1 = grades[\'dw1\']\n dw2 = grades[\'dw2\']\n dw3 = grades[\'dw3\']\n dw4 = grades[\'dw4\']\n dw5 = grades[\'dw5\']\n db1 = grades[\'db1\']\n db2 = grades[\'db2\']\n db3 = grades[\'db3\']\n db4 = grades[\'db4\']\n db5 = grades[\'db5\']\n w1 = w1 - learning_rate*dw1\n w2 = w2 - learning_rate*dw2\n w3 = w3 - learning_rate*dw3\n w4 = w4 - learning_rate*dw4\n w5 = w5 - learning_rate*dw5\n b1 = b1 - learning_rate*db1\n b2 = b2 - learning_rate*db2\n b3 = b3 - learning_rate*db3\n b4 = b4 - learning_rate*db4\n b5 = b5 - learning_rate*db5\n par = {"w1":w1,"b1":b1,"w2":w2,"b2":b2,"w3":w3,"b3":b3,"w4":w4,"b4":b4,"w5":w5,"b5":b5}\n return par\n\nupdate(par,grades)',
8
+ 'fwdp': 'def FWDP(X, par):\n w1 = par["w1"]\n b1 = par["b1"]\n w2 = par["w2"]\n b2 = par["b2"]\n w3 = par["w3"]\n b3 = par["b3"]\n w4 = par["w4"]\n b4 = par["b4"]\n w5 = par["w5"]\n b5 = par["b5"]\n\n z1 = np.dot(w1, X) + b1\n a1 = ReLU(z1)\n z2 = np.dot(w2, a1) + b2\n a2 = ReLU(z2)\n z3 = np.dot(w3, a2) + b3\n a3 = eReLU(z3)\n z4 = np.dot(w4, a3) + b4\n a4 = ReLU(z4)\n z5 = np.dot(w5, a4) + b5\n a5 = sigmoid(z5)\n\n cache = {\n "z1": z1, "a1": a1,\n "z2": z2, "a2": a2,\n "z3": z3, "a3": a3,\n "z4": z4, "a4": a4,\n "z5": z5, "a5": a5\n }\n\n return a5, cache\n\na5, cache = FWDP(x,par)\nprint(a5)\nprint(cache)\n\ndef compute_cost(a5,y):\n m = y.shape[1]\n cost = np.sum(y*np.log(a5)+(1-y)*np.log(1-a5))\n cost = -cost/m\n return cost\ncompute_cost(a5,y)',
9
+ 'nn_final': 'def NN(x,y,n_h1,n_h2,n_h3,n_h4,epoch = 10000,print_cost = True):\n np.random.seed(3)\n n_x,n_h1,n_h2,n_h3,n_h4, n_y = nodes(x,y,n_h1,n_h2,n_h3,n_h4)\n par = int_par(n_x,n_h1,n_h2,n_h3,n_h4,n_y)\n cost_hist=[]\n\n for i in range(epoch):\n a4,cat = FWDP(x,par)\n cost = compute_cost(a5,y)\n grades = BWP(par,cache,x,y)\n par = update(par,grades)\n if print_cost and i%1000 == 0:\n print(f"cost {cost} \\t iteration: {i}")\n\n cost_hist.append(cost)\n\n\n return par\n\n\nNN(x,y,n_h1,n_h2,n_h3,n_h4,epoch = 10000,print_cost = True)',
10
+ 'nnintro': 'import numpy as np\nnp.random.seed(123)\nx = np.random.randn(20,100) #(nx,m)\ny = np.random.randn(1,100)>0 #(1,m)\nx\ny\n\ndef nodes(x,y,n_h1,n_h2,n_h3,n_h4):\n n_x = x.shape[0]\n n_h1 = n_h1\n n_h2 = n_h2\n n_h3 = n_h3\n n_h4 = n_h4\n n_y = y.shape[0]\n return n_x,n_h1,n_h2,n_h3,n_h4,n_y\n\n n_x,n_h1,n_h2,n_h3,n_h4,n_y = nodes(x,y,n1,n2,n3,n4)\n\n def int_par(n_x,n_h1,n_h2,n_h3,n_h4,n_y):\n np.random.seed(2)\n w1 = np.random.randn(n_h1,n_x)*0.01\n b1 = np.random.randn(n_h1,1)\n w2 = np.random.randn(n_h2,n_h1)*0.01\n b2 = np.random.randn(n_h2,1)\n w3 = np.random.randn(n_h3,n_h2)*0.01\n b3 = np.random.randn(n_h3,1)\n w4 = np.random.randn(n_h4,n_h3)*0.01\n b4 = np.random.randn(n_h4,1)\n w5 = np.random.randn(n_y,n_h4)*0.01\n b5 = np.random.randn(n_y,1)\n par = {"w1":w1,"b1":b1,"w2":w2,"b2":b2,"w3":w3,"b3":b3,"w4":w4,"b4":b4,"w5":w5, "b5":b5}\n return par\n\n par = int_par(n_x,n_h1,n_h2,n_h3,n_h4,n_y)',
11
+ }
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: scypyy
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Python :: 3
5
+ Classifier: Operating System :: OS Independent
6
+ Requires-Python: >=3.9
@@ -0,0 +1,7 @@
1
+ pyproject.toml
2
+ scypyy/__init__.py
3
+ scypyy/_data.py
4
+ scypyy.egg-info/PKG-INFO
5
+ scypyy.egg-info/SOURCES.txt
6
+ scypyy.egg-info/dependency_links.txt
7
+ scypyy.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ scypyy
scypyy-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+