-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_weights.py
51 lines (44 loc) · 1.79 KB
/
gen_weights.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from numpy.random import randn
from pandas import DataFrame
def gen_weights(self):
# Generate all weights randomly
"""
Take random samples from the standard normal
distribution
Three sets of weights will be generated for all synapses.
"""
def gen_input_hl_weights(self):
# Initialize input to hidden layer synapses
self.weights["Input-HL"] = DataFrame(
randn(self.input_nodes, self.hidden_neurons),
index=self.X.columns,
columns=("Input Synapses " + str(i)
for i in range(1, self.hidden_neurons + 1)),
)
def gen_hl_hl_weights(self):
# Initialize hidden layer to hidden layer synapses
self.weights["HL-HL"] = [
DataFrame(
randn(self.hidden_neurons, self.hidden_neurons),
index=("HL" + str(i) + "-Neuron " + str(j)
for j in range(1, self.hidden_neurons + 1)),
columns=("HL" + str(i) + "-Synapse " + str(j)
for j in range(1, self.hidden_neurons + 1)),
) for i in range(1, self.hidden_layers) # Offset here
]
def gen_hl_output_weights(self):
# Initialize hidden layer to output synapses
self.weights["HL-Output"] = DataFrame(
randn(self.hidden_neurons, self.output_neuron),
index=("HL" + str(self.hidden_layers) + "-Neuron " + str(i)
for i in range(1, self.hidden_neurons + 1)),
columns=["Output Synapses"],
)
def check_hl_count(self):
# If # hidden layers == 1, delete the "HL-HL" key
if not self.weights["HL-HL"]:
del self.weights["HL-HL"]
gen_input_hl_weights(self)
gen_hl_hl_weights(self)
gen_hl_output_weights(self)
check_hl_count(self)