The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

361604 (4) [Avatar] Offline
#1
I am finding this section really confusing because the code doesn't make sense.

weights = [ [0.1, 0.1, -0.3],#hurt?
0.1, 0.2, 0.0], #win? 
[0.0, 1.3, 0.1] ]#sad?


and then lower:

pred = neural_network(input,weight)


Is that last parameter supposed to be weights?

def vect_mat_mul(vect,matrix): 
   assert(len(a) == len(b)) 
   output = 0
   for i in range(a):
      output += (a[i] * b[i])
   return output


Is a and b supposed to be vect and matrix respectively?



156064 (2) [Avatar] Offline
#2
            #toes %win #fans
weights = [ [0.1, 0.1, -0.3],   #hurt?
            [0.1, 0.2, 0.0],    #win?
            [0.0, 1.3, 0.1]]    #sad?


def neural_network(input, weights):
     pred = vect_mat_mul(input,weights)
     return pred


toes = [8.5, 9.5, 9.9, 9.0]
wlrec = [0.65,0.8, 0.8, 0.9]
nfans = [1.2, 1.3, 0.5, 1.0]


##
# Fixes
#   1) variable names a, b become vect and matix
#   2) changed  range(vect)  to range(len(vect))
##
def vect_mat_mul(vect,matrix):
    assert(len(vect) == len(matrix))
    output = 0
    for i in range(len(vect)):
       # print (vect[i] , "x",matrix[i])
       output += ( vect[i] * matrix[i])
    return output


##
#  Call neural_network on first input for each set of weights
#  and print result
#  Fixes
#    1) added variable weight to refer to current set of weights
##
input = [toes[0],wlrec[0],nfans[0]]
for i in range(len(weights)):
    weight = weights[i]
    pred = neural_network(input,weight)
    print(pred)




This prints the results

0.555
0.9800000000000001
0.9650000000000001