Skip to content

Commit 85a26d5

Browse files
committed
add config and start with the layers
1 parent 1afd179 commit 85a26d5

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

assignment1/Config.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class Config:
2+
config = {
3+
"training": None,
4+
"validation": None,
5+
"layers": None,
6+
"activations": None,
7+
"loss_type": None,
8+
"learning_rate": None,
9+
"no_epochs": None,
10+
"L2_regularization": None
11+
}
12+
13+
def __init__(self, file_path):
14+
lines = self.read_file(file_path)
15+
self.parse_config(lines)
16+
17+
def read_file(self, file):
18+
"""
19+
:param file: The file path
20+
:return:
21+
"""
22+
f = open(file)
23+
lines = f.readlines()
24+
f.close()
25+
return lines
26+
27+
def parse_config(self, lines):
28+
for line in lines:
29+
line = line.strip()
30+
# Skip empty lines and comments and square brackets.
31+
if line == "" or line.startswith("#") or line.startswith("["):
32+
continue
33+
key, attr = line.split("=")
34+
key, attr = key.strip(), attr.strip()
35+
if key in self.config.keys():
36+
self.config[key] = attr
37+
else:
38+
print("Unknown key in config file.")

assignment1/Layer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33

44
class Layer:
5-
def __init__(self, weights, activations):
5+
def __init__(self, weights, activations, bias):
66
self.weights = weights
77
self.activations = activations
8+
self.bias = bias
89

910
def get_output(self):
11+
# TODO: Remember to change it for the first layer without activations.
1012
return np.transpose(self.weights).dot(activations)
1113

14+
def activation(self):
15+
pass
16+
1217

1318
if __name__ == '__main__':
1419
weights = np.array([[1, 2], [2, 3]])

assignment1/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from Config import Config
2+
from Layer import Layer
3+
import numpy as np
4+
5+
6+
def main():
7+
config = Config("config.txt")
8+
9+
# Input layer
10+
activations = None
11+
weights = np.array([0.2, 0.2])
12+
bias = 0.2
13+
input_layer = Layer(weights, activations, bias)
14+
15+
# Output layer
16+
activations = np.array([])
17+
18+
# Data. Simple AND example:
19+
data_X = np.array([[1, 1], [0, 1], [1, 0], [0, 0]])
20+
data_y = np.array([1, 0, 0, 0])
21+
22+
23+
if __name__ == '__main__':
24+
main()

0 commit comments

Comments
 (0)