Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mamei16 committed Aug 9, 2019
1 parent ce3075b commit 78f3da5
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions NN/Exercise3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

start_data = np.array([[1, 0, 1],
[0, 1, 1],
[1, 1, 1],
[1, 1, 0],
[0, 0, 0]])
training_set = []

Expand All @@ -18,9 +18,7 @@ def run_single_perceptron():

learning_rate = 0.2


def calc_weights(weights, input, output, correct_output):
#return weights + learning_rate*output*(1- output)*(correct_output-output)*input # sigmoid
return weights + (0.5*learning_rate*(correct_output-output)*input)

epochs = 1000
Expand All @@ -32,8 +30,7 @@ def calc_weights(weights, input, output, correct_output):
avg_error = 0
for i in range(len(training_set)):
u = np.append(training_set[i][:2], -1)
z = (w[0]*u[0]) + (w[1]*u[1]) + (w[2]*u[2])
#v = 1 / (1+(math.e**(-z)))
z = np.matmul(w, u)
if z <= 0:
v = 0
else:
Expand Down Expand Up @@ -82,8 +79,8 @@ def calc_weights(weights, error, input):
u = np.append(training_set[i][:2], -1)
x_1 = w_hidden[0]
x_2 = w_hidden[1]
z_1 = (x_1[0] * u[0]) + (x_1[1] * u[1]) + (x_1[2] * u[2])
z_2 = (x_2[0] * u[0]) + (x_2[1] * u[1]) + (x_2[2] * u[2])
z_1 = np.matmul(x_1, u)
z_2 = np.matmul(x_2, u)
x_1_output = (1 / (1+(math.e**(-z_1))))
x_2_output = (1 / (1+(math.e**(-z_2))))
z = (w_output[0] * x_1_output) + (w_output[1] * x_2_output) + (w_output[2] * -1)
Expand Down Expand Up @@ -135,8 +132,8 @@ def testweights_mlp():
u = np.append(training_set[i][:2], -1)
x_1 = w_hidden[0]
x_2 = w_hidden[1]
z_1 = (x_1[0] * u[0]) + (x_1[1] * u[1]) + (x_1[2] * u[2])
z_2 = (x_2[0] * u[0]) + (x_2[1] * u[1]) + (x_2[2] * u[2])
z_1 = np.matmul(x_1, u)
z_2 = np.matmul(x_2, u)
x_1_output = 1 / (1 + (math.e ** (-z_1)))
x_2_output = 1 / (1 + (math.e ** (-z_2)))
z = (w_output[0] * x_1_output) + (w_output[1] * x_2_output) + (w_output[2] * -1)
Expand All @@ -158,16 +155,15 @@ def testweights_single_perceptron(linenum):
np.random.shuffle(training_set)
for i in range(10):
u = np.append(training_set[i][:2], -1)
z = (w[0] * u[0]) + (w[1] * u[1]) + (w[2] * u[2])
#v = 1 / (1 + (math.e ** (-z)))
z = np.matmul(w, u)
if z <= 0:
v = 0
else:
v = 1
print("Input:", u, " Output:", v)


run_mlp()
#run_mlp()
#testweights_mlp()
#testweights_single_perceptron(0)
#run_single_perceptron()

0 comments on commit 78f3da5

Please sign in to comment.