jpsember / ml_old

Python and machine learning experiments
0 stars 0 forks source link

Investigate how backpropagation can be done using numpy #13

Open jpsember opened 7 years ago

jpsember commented 7 years ago

Up to now, we've been using our 'func' graph to represent the neural network. This is good for educational purposes but we should now figure out how backpropagation (i.e., calculating gradients) can be done more efficiently by using numpy (matrix representations and operations).

jpsember commented 7 years ago

This will also let us process the (N * k) training samples in one go, instead of iterating through them as we were doing.

jpsember commented 7 years ago

The training samples appear as a matrix on the left side of the function, and the scores similarly appear as outputs on the right. The matrices in between represent the edges between the layers, and the values of the layers (i.e., the 'nodes' within the layers) are implicit in the matrix multiplications that occur as the calculation proceeds from left to right. (Some operations, like ReLU, cannot be represented as a matrix, since they aren't linear operations; but they can be thought of as 'pseudo matrices' here).

So, in our spiral neural network example:

jpsember commented 7 years ago

Can we experiment by adding a second hidden layer to improve the performance of the network? Reduce the value of H, since it probably doesn't need to be 100 in this case (especially since by dimension analysis we need the second hidden layer to have size H x H).

Opening another issue for this... worth checking out.

jpsember commented 7 years ago

I think it's calculating correctly:

py> rake
Samples:
[[ 2.  6.  2.  1.]
 [ 0.  7.  6.  6.]
 [ 0.  6.  6.  1.]
 [ 5.  2.  6.  7.]
 [ 1.  6.  3.  7.]
 [ 5.  4.  6.  3.]]
Types:
[[3]
 [2]
 [3]
 [3]
 [3]
 [1]]
SVM loss:
[[ 10.]
 [  3.]
 [ 12.]
 [  0.]
 [  0.]
 [  5.]]
py>