dimanche 26 mai 2019

Why do we multiply calls to numpy.random.random by numbers and subtract numbers?

I found this snippet of code in an article about backpropagation and I got confused on how exactly it works. The article says the following

"This is our weight matrix for this neural network. It's called "syn0" to imply "synapse zero". Since we only have 2 layers (input and output), we only need one matrix of weights to connect them. Its dimension is (3,1) because we have 3 inputs and 1 output."

I want to specify that by input the author is referring to array "X" and output refers to array "Y".

My first question is why does the article claim we have only 3 inputs. A glance at the code reveals that our array, X, has size 4. Am I just misunderstanding something?

My second question is why are multiplying the call to np.random.random() by 2?

Thanks for the help!

import numpy as np    

X = np.array([ [0,0,1],
               [0,1,1],
               [1,0,1],
               [1,1,1] ])

y = np.array([[0,0,1,1]]).T  

# initialize weights randomly with mean 0
syn0 = 2*np.random.random((3,1)) - 1




Aucun commentaire:

Enregistrer un commentaire