Spaces:
Sleeping
Sleeping
Jensen-holm
commited on
Commit
•
38e3b7b
1
Parent(s):
14841f9
init weights and biases
Browse files- nn/__pycache__/nn.cpython-310.pyc +0 -0
- nn/__pycache__/train.cpython-310.pyc +0 -0
- nn/nn.py +14 -0
- nn/train.py +13 -0
nn/__pycache__/nn.cpython-310.pyc
CHANGED
Binary files a/nn/__pycache__/nn.cpython-310.pyc and b/nn/__pycache__/nn.cpython-310.pyc differ
|
|
nn/__pycache__/train.cpython-310.pyc
CHANGED
Binary files a/nn/__pycache__/train.cpython-310.pyc and b/nn/__pycache__/train.cpython-310.pyc differ
|
|
nn/nn.py
CHANGED
@@ -24,6 +24,8 @@ class NN:
|
|
24 |
self.target = target
|
25 |
self.data = data
|
26 |
|
|
|
|
|
27 |
self.wh: np.array = None
|
28 |
self.wo: np.array = None
|
29 |
self.bh: np.array = None
|
@@ -48,6 +50,18 @@ class NN:
|
|
48 |
assert isinstance(f, Callable)
|
49 |
self.func_prime = f
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
@classmethod
|
52 |
def from_dict(cls, dct):
|
53 |
""" Creates an instance of NN given a dictionary
|
|
|
24 |
self.target = target
|
25 |
self.data = data
|
26 |
|
27 |
+
self.input_size = len(features)
|
28 |
+
|
29 |
self.wh: np.array = None
|
30 |
self.wo: np.array = None
|
31 |
self.bh: np.array = None
|
|
|
50 |
assert isinstance(f, Callable)
|
51 |
self.func_prime = f
|
52 |
|
53 |
+
def set_bh(self, bh: np.array) -> None:
|
54 |
+
self.bh = bh
|
55 |
+
|
56 |
+
def set_wh(self, wh: np.array) -> None:
|
57 |
+
self.wh = wh
|
58 |
+
|
59 |
+
def set_bo(self, bo: np.array) -> None:
|
60 |
+
self.bo = bo
|
61 |
+
|
62 |
+
def set_wo(self, wo: np.array) -> None:
|
63 |
+
self.wo = wo
|
64 |
+
|
65 |
@classmethod
|
66 |
def from_dict(cls, dct):
|
67 |
""" Creates an instance of NN given a dictionary
|
nn/train.py
CHANGED
@@ -4,7 +4,20 @@ import pandas as pd
|
|
4 |
import numpy as np
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def train(nn: NN) -> dict:
|
|
|
8 |
X_train, X_test, y_train, y_test = train_test_split(
|
9 |
nn.X,
|
10 |
nn.y,
|
|
|
4 |
import numpy as np
|
5 |
|
6 |
|
7 |
+
def init_weights_biases(nn: NN) -> None:
|
8 |
+
np.random.seed(88)
|
9 |
+
bh = np.zeros((1, 1))
|
10 |
+
bo = np.zeros((1, 1))
|
11 |
+
wh = np.random.randn(1, nn.input_size) * np.sqrt(2 / nn.input_size)
|
12 |
+
wo = np.random.randn(1, nn.hidden_size) * np.sqrt(2 / nn.hidden_size)
|
13 |
+
nn.set_bh(bh)
|
14 |
+
nn.set_bo(bo)
|
15 |
+
nn.set_wh(wh)
|
16 |
+
nn.set_wo(wo)
|
17 |
+
|
18 |
+
|
19 |
def train(nn: NN) -> dict:
|
20 |
+
init_weights_biases(nn=nn)
|
21 |
X_train, X_test, y_train, y_test = train_test_split(
|
22 |
nn.X,
|
23 |
nn.y,
|