ganch 0.0.1__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.
ganch/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
ganch/configs.py ADDED
File without changes
ganch/data.py ADDED
File without changes
File without changes
File without changes
ganch/losses/loss.py ADDED
File without changes
ganch/losses/mse.py ADDED
File without changes
ganch/mlp.py ADDED
File without changes
File without changes
@@ -0,0 +1,61 @@
1
+ """
2
+ activations.py
3
+ ~~~~~~~~~~~~~~
4
+
5
+ Inside of this file I am going to write ReLU, Sigmoid, Softmax
6
+ activation functions and their gradient methods for each. Also,
7
+ I will use OOP for whole file and NumPy package.
8
+ """
9
+
10
+ import numpy as np
11
+
12
+ class Activations:
13
+
14
+ """
15
+ Sigmoid activation function. Mathematical formula is f(Z) = 1 / (1 + e ^ (-Z))
16
+ and grdient or df(Z) / dZ = f(Z) x (1 - f(Z)). Basically, sigmoid is used in
17
+ output layers for classification projects
18
+ """
19
+ def sigmoid(self, Z : np.ndarray) -> np.ndarray:
20
+ result : np.ndarray = 1 / (1 + np.exp(-Z))
21
+ return result
22
+
23
+ def sigmoid_grad(self, A : np.ndarray) -> np.ndarray:
24
+ gradient : np.ndarray = A * (1 - A)
25
+ return gradient
26
+
27
+ """
28
+ ReLU activation function. Mathematical formula for ReLU is f(Z) = Max(Z).
29
+ and gradient for ReLU is f'(Z) = 1 if f(Z) > 0 else 0. Basically, ReLU
30
+ activation function is used inside of hidden layers for any kind of pro-
31
+ jects.
32
+ """
33
+ def relu(self, Z : np.ndarray) -> np.ndarray:
34
+ result : np.ndarray = np.maximum(0, Z)
35
+ return result
36
+
37
+ def relu_grad(self, A : np.ndarray) -> np.ndarray:
38
+ gradient : np.ndarray = (A > 0).astype(float)
39
+ return gradient
40
+
41
+ """
42
+ Softmax activation functions. mathematical formula for Softmax
43
+ """
44
+ def softmax(self, Z : np.ndarray) -> np.ndarray:
45
+ exp_Z : np.ndarray = np.exp(Z - np.max(Z, axis=1, keepdims=True))
46
+ result : np.ndarray = exp_Z / np.sum(exp_Z, axis=1, keepdims=True)
47
+ return result
48
+
49
+ def softmax_grad(self, A : np.ndarray, dA: np.ndarray) -> np.ndarray:
50
+ sum_term : np.ndarray = np.sum(dA * A, axis=1, keepdims=True)
51
+ gradient : np.ndarray = A * (dA - sum_term)
52
+ return gradient
53
+
54
+ """
55
+ Linear activation function is used is regression problem
56
+ """
57
+ def linear(self, Z: np.ndarray) -> np.ndarray:
58
+ return Z
59
+
60
+ def linear_grad(self, A: np.ndarray) -> np.ndarray:
61
+ return np.ones_like(A)
@@ -0,0 +1,20 @@
1
+ """
2
+ initializer.py
3
+ ~~~~~~~~~~~~~~
4
+
5
+ with a help of this file, I can create costum weight for initialization.
6
+ It is smth like clever way to train, with help of the method I can reach
7
+ faster 0 loss
8
+ """
9
+
10
+ import numpy as np
11
+
12
+ class Initializers:
13
+
14
+ def xavier(self, n_inputs: int, n_units: int) -> np.ndarray:
15
+ std = np.sqrt(2 / (n_inputs + n_units))
16
+ return np.random.randn(n_inputs, n_units) * std
17
+
18
+ def he(self, n_inputs: int, n_units: int) -> np.ndarray:
19
+ std = np.sqrt(2 / n_inputs)
20
+ return np.random.randn(n_inputs, n_units) * std
ganch/model/layers.py ADDED
@@ -0,0 +1,43 @@
1
+ """
2
+ layers.py
3
+ ~~~~~~~~~
4
+
5
+ with a help of this file, i will store each neurons, their activation functions.
6
+ This file is core of the whole project.
7
+ """
8
+
9
+ import numpy as np
10
+ from .activations import Activations
11
+ from .initializers import Initializers
12
+
13
+ class Layer:
14
+
15
+ def __init__(self, number_of_inputs : np.int_, number_of_outputs : np.int_, function : np.str_):
16
+ self.number_of_inputs : np.int_ = number_of_inputs # number of intputs for the each neuron
17
+ self.number_of_outputs : np.int_ = number_of_outputs # number of outputs for each neuron
18
+ activations = Activations() # call activation functions from activation functions stored file
19
+ self.function = function # key word for importing activation fucntions
20
+ self.activation_function = getattr(activations, self.function) # calling the activation function here
21
+ self.activation_function_derivative = getattr(activations, f"{self.function}_grad") # calling the activation functions grad methods
22
+ self.weights= Initializers().he(number_of_inputs, number_of_outputs) if self.function == "relu" else Initializers().xavier(number_of_inputs, number_of_outputs) # initialize weights based on the type of activation functions and number of inputs and outputs
23
+ self.bias = np.zeros((1, number_of_outputs)) # initialize biases as 0
24
+
25
+ # with a help of forward prop, i can reach untill output layer, the I can calculate the loss. And then, I can interact with backward
26
+ def forward(self, X : np.ndarray) -> np.ndarray:
27
+ self.X = X
28
+ Z : np.ndarray = self.X @ self.weights + self.bias
29
+ result : np.ndarray = self.activation_function(Z)
30
+ self.A = result
31
+ return result
32
+
33
+ def backward(self, grad: np.ndarray, is_output: bool = False) -> np.ndarray:
34
+ B = self.X.shape[0]
35
+ if is_output:
36
+ dZ = grad # output layer + matching loss: the loss already gives dZ
37
+ elif self.function == "softmax":
38
+ dZ = self.activation_function_derivative(self.A, grad)
39
+ else:
40
+ dZ = grad * self.activation_function_derivative(self.A)
41
+ self.dW = self.X.T @ dZ / B
42
+ self.db = dZ.sum(axis=0, keepdims=True) / B
43
+ return dZ @ self.weights.T
ganch/model/model.py ADDED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
ganch/train.py ADDED
File without changes
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.5
2
+ Name: ganch
3
+ Version: 0.0.1
4
+ Summary: A multilayer perceptron library built from scratch with NumPy
5
+ Project-URL: Homepage, https://github.com/E-Zakirovich/ganch
6
+ Author: Azamat E. Zakirovich
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.9
10
+ Requires-Dist: numpy
11
+ Description-Content-Type: text/markdown
12
+
13
+ # ganch
14
+ With the help of this project I built a whole multilayer perceptron layer from scratch by using the numpy Python library. It supports forward and backpropagation, optimizations.
@@ -0,0 +1,25 @@
1
+ ganch/__init__.py,sha256=ugyuFliEqtAwQmH4sTlc16YXKYbFWDmfyk87fErB8-8,21
2
+ ganch/configs.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ ganch/data.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ ganch/mlp.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ ganch/train.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ ganch/losses/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ ganch/losses/cross_entropy_loss.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ ganch/losses/loss.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ ganch/losses/mse.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ ganch/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ ganch/model/activations.py,sha256=r_goc5z28KMS8T8LQ04EQWB_j8h5li_207zW--VQD-M,2012
12
+ ganch/model/initializers.py,sha256=34R3tHK5FYKPnd8VcJw3TnKmsSNB7uSIktjtA6kkpMM,565
13
+ ganch/model/layers.py,sha256=qr8i7fYSKww0xk5EGZz5mBoSGYxMRCxUlQCvAdmvYmM,2231
14
+ ganch/model/model.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ ganch/optimizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ ganch/optimizers/adam.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ ganch/optimizers/momentum.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ ganch/optimizers/nesterov.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ ganch/optimizers/optimizer.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ ganch/optimizers/rmsprop.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
+ ganch/optimizers/sgd.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ ganch-0.0.1.dist-info/METADATA,sha256=YZQqa6NmC31AtUvlcbO5AhgUvS0kS5wjKNn484T94fM,527
23
+ ganch-0.0.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
24
+ ganch-0.0.1.dist-info/licenses/LICENSE,sha256=xesZpjoIeoPVfRtJhFx1dCBbjMDWtruUN6E-xXIH3cI,1077
25
+ ganch-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Azamat E. Zakirovich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.