Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1295f2

Browse files
committed
changed the name of function to sum_dotproduct
1 parent a0d7856 commit c1295f2

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

learning.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def predict(example):
447447
for layer in learned_net[1:]:
448448
for node in layer:
449449
inc = [n.value for n in node.inputs]
450-
in_val = dotproduct(inc, node.weights)
450+
in_val = sum_dotproduct(inc, node.weights)
451451
node.value = node.activation(in_val)
452452

453453
# Hypothesis
@@ -530,7 +530,7 @@ def BackPropagationLearner(dataset, net, learning_rate, epoches):
530530
for layer in net[1:]:
531531
for node in layer:
532532
inc = [n.value for n in node.inputs]
533-
in_val = dotproduct(inc, node.weights)
533+
in_val = sum_dotproduct(inc, node.weights)
534534
node.value = node.activation(in_val)
535535

536536
# Initialize delta
@@ -554,7 +554,7 @@ def BackPropagationLearner(dataset, net, learning_rate, epoches):
554554
for k in range(h_units)]
555555

556556
delta[i] = [(layer[j].value) * (1 - layer[j].value) *
557-
dotproduct(w[j], delta[i+1])
557+
sum_dotproduct(w[j], delta[i+1])
558558
for j in range(h_units)]
559559

560560
# Update weights
@@ -591,7 +591,7 @@ def predict(example):
591591
for layer in learned_net[1:]:
592592
for node in layer:
593593
inc = [n.value for n in node.inputs]
594-
in_val = dotproduct(inc, node.weights)
594+
in_val = sum_dotproduct(inc, node.weights)
595595
node.value = node.activation(in_val)
596596

597597
# Hypothesis

tests/test_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def test_histogram():
8383
(7, 1), (5, 1)]
8484

8585

86-
def test_dotproduct():
87-
assert dotproduct([1, 2, 3], [1000, 100, 10]) == 1230
86+
def test_sum_dotproduct():
87+
assert sum_dotproduct([1, 2, 3], [1000, 100, 10]) == 1230
8888

8989

9090
def test_vector_add():
@@ -117,9 +117,9 @@ def f():
117117

118118

119119
def test_sigmoid():
120-
assert isclose(0.5, sigmoid(0))
121-
assert isclose(0.7310585786300049, sigmoid(1))
122-
assert isclose(0.2689414213699951, sigmoid(-1))
120+
assert isclose(0.5, sigmoid(0))
121+
assert isclose(0.7310585786300049, sigmoid(1))
122+
assert isclose(0.2689414213699951, sigmoid(-1))
123123

124124

125125
def test_step():

utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,17 @@ def histogram(values, mode=0, bin_function=None):
162162
return sorted(bins.items())
163163

164164

165-
def dotproduct(X, Y):
165+
def sum_dotproduct(X, Y):
166166
"""Return the sum of the element-wise product of vectors x and y."""
167167
return sum(x * y for x, y in zip(X, Y))
168168

169169

170+
def dotproduct(X, Y):
171+
"""Return element-wise product of vectors x and y"""
172+
assert len(X) == len(Y)
173+
return(list(x * y for x, y in zip(X, Y)))
174+
175+
170176
def vector_add(a, b):
171177
"""Component-wise addition of two vectors."""
172178
return tuple(map(operator.add, a, b))

0 commit comments

Comments
 (0)