panddu 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.
Potentially problematic release.
This version of panddu might be problematic. Click here for more details.
- panddu-0.1.0/PKG-INFO +6 -0
- panddu-0.1.0/panddu/__init__.py +79 -0
- panddu-0.1.0/panddu/__init__.pyi +16 -0
- panddu-0.1.0/panddu/_data.py +11 -0
- panddu-0.1.0/panddu/py.typed +0 -0
- panddu-0.1.0/panddu.egg-info/PKG-INFO +6 -0
- panddu-0.1.0/panddu.egg-info/SOURCES.txt +9 -0
- panddu-0.1.0/panddu.egg-info/dependency_links.txt +1 -0
- panddu-0.1.0/panddu.egg-info/top_level.txt +1 -0
- panddu-0.1.0/pyproject.toml +19 -0
- panddu-0.1.0/setup.cfg +4 -0
panddu-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""panddu — 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 panddu
|
|
7
|
+
panddu.bwp # shows the stored code in the REPL
|
|
8
|
+
panddu.nn_final # another snippet
|
|
9
|
+
print(panddu.bwp) # prints the code
|
|
10
|
+
code = panddu.bwp # a normal str you can save or exec
|
|
11
|
+
|
|
12
|
+
Type ``panddu.`` in a REPL/editor to autocomplete the available snippet names,
|
|
13
|
+
or call ``panddu.available()`` to list them.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from ._data import SNIPPETS
|
|
19
|
+
|
|
20
|
+
__version__ = "0.1.0"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Code(str):
|
|
24
|
+
"""A ``str`` subclass that displays its raw contents in the REPL.
|
|
25
|
+
|
|
26
|
+
A normal string echoes with escaped newlines (``\\n``). This shows the
|
|
27
|
+
actual code instead, while still behaving like an ordinary string.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
__slots__ = ()
|
|
31
|
+
|
|
32
|
+
def __repr__(self) -> str: # noqa: D105
|
|
33
|
+
return str.__str__(self)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Expose every snippet as a REAL module attribute so that editors, IPython,
|
|
37
|
+
# Jupyter and the REPL all show them in autocomplete (dynamic __getattr__ alone
|
|
38
|
+
# is invisible to completion tools).
|
|
39
|
+
for _name, _code in SNIPPETS.items():
|
|
40
|
+
globals()[_name] = Code(_code)
|
|
41
|
+
del _name, _code
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def available():
|
|
45
|
+
"""Return a sorted list of every stored snippet name."""
|
|
46
|
+
return sorted(SNIPPETS)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get(name: str) -> Code:
|
|
50
|
+
"""Return the stored code for ``name`` (case-insensitive) as a :class:`Code`."""
|
|
51
|
+
if name in SNIPPETS:
|
|
52
|
+
return Code(SNIPPETS[name])
|
|
53
|
+
for key in SNIPPETS:
|
|
54
|
+
if key.lower() == name.lower():
|
|
55
|
+
return Code(SNIPPETS[key])
|
|
56
|
+
raise KeyError(
|
|
57
|
+
f"no snippet named {name!r}. Available: {', '.join(available()) or '(none)'}"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def __getattr__(name: str) -> Code:
|
|
62
|
+
"""Fallback for case-insensitive access and a friendly error (PEP 562)."""
|
|
63
|
+
if name.startswith("_"):
|
|
64
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
65
|
+
try:
|
|
66
|
+
return get(name)
|
|
67
|
+
except KeyError:
|
|
68
|
+
raise AttributeError(
|
|
69
|
+
f"module {__name__!r} has no attribute {name!r}. "
|
|
70
|
+
f"Available snippets: {', '.join(available()) or '(none)'}"
|
|
71
|
+
) from None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def __dir__():
|
|
75
|
+
"""Clean autocomplete list: snippet names plus the public helpers."""
|
|
76
|
+
return sorted(list(SNIPPETS) + ["available", "get", "Code", "__version__"])
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
__all__ = sorted(SNIPPETS) + ["available", "get", "Code"]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
class Code(str): ...
|
|
4
|
+
|
|
5
|
+
def available() -> List[str]: ...
|
|
6
|
+
def get(name: str) -> Code: ...
|
|
7
|
+
|
|
8
|
+
__version__: str
|
|
9
|
+
|
|
10
|
+
# Snippets (each is the stored code as a string):
|
|
11
|
+
LGD: Code
|
|
12
|
+
activationfunctions: Code
|
|
13
|
+
bwp: Code
|
|
14
|
+
fwdp: Code
|
|
15
|
+
nn_final: Code
|
|
16
|
+
nnintro: 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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
panddu
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "panddu"
|
|
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 = ["panddu"]
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.package-data]
|
|
19
|
+
panddu = ["*.pyi", "py.typed"]
|
panddu-0.1.0/setup.cfg
ADDED