Skip to content
Snippets Groups Projects
Commit d1c47221 authored by Michael Mutote's avatar Michael Mutote
Browse files

22202956 - touch up on heuristics, N-QUEENS

parent b878bbe2
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ class Perceptron: ...@@ -26,7 +26,7 @@ class Perceptron:
self.activation = activation self.activation = activation
self.weights = rng.random(input_count + 1) self.weights = rng.random(input_count + 1)
def train(self, ETA): def train_thres(self, ETA):
teach_data = Training_data.make_testset(TEACHDATA) teach_data = Training_data.make_testset(TEACHDATA)
for i in range(TEACHDATA): for i in range(TEACHDATA):
old_weights = np.copy(self.weights) old_weights = np.copy(self.weights)
...@@ -38,7 +38,6 @@ class Perceptron: ...@@ -38,7 +38,6 @@ class Perceptron:
delta = ETA * \ delta = ETA * \
(T - self.activation(ix.dot(self.weights))) * ix (T - self.activation(ix.dot(self.weights))) * ix
self.weights = self.weights + delta self.weights = self.weights + delta
# print(self.weights[0], self.weights[1], self.weights[2], self.weights[3], self.weights[4], self.weights[5], self.weights[6])
if np.linalg.norm(old_weights - self.weights) == 0.00: if np.linalg.norm(old_weights - self.weights) == 0.00:
return self.weights return self.weights
return self.weights return self.weights
......
...@@ -34,7 +34,7 @@ class PerceptronSGD: ...@@ -34,7 +34,7 @@ class PerceptronSGD:
RI = self.activation(z) RI = self.activation(z)
error = T - RI error = T - RI
delta = ETA * error * self.activation_derivative(z) * ix delta = ETA * error * self.activation_derivative(z) * ix
self.weights += delta self.weights += delta
return self.weights return self.weights
def test(self): def test(self):
......
import Perceptrons import Perceptrons
import PerceptronsSGD
def test_function(ETA): def test_function(ETA):
...@@ -6,14 +7,14 @@ def test_function(ETA): ...@@ -6,14 +7,14 @@ def test_function(ETA):
results = [] results = []
p = Perceptrons.Perceptron(input_count) p = Perceptrons.Perceptron(input_count)
p.train(ETA) p.train_thres(ETA)
output = p.test() output = p.test()
results.append((ETA, output)) results.append((ETA, output))
return results return results
for ETA in ([0.05, 0.1, 0.2, 0.4, 0.75, 1, 2, 5]): # the list of values for ETA for ETA in ([0.05, 0.1, 0.2, 0.4, 0.75, 1, 2, 5]): # the list of values for ETA
for i in range(5): for i in range(1):
res = test_function(ETA) res = test_function(ETA)
print(res) # print the results list print(res) # print the results list
print("\n\n") print("\n\n")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment