I'm writing a Neural network in Node to play Tic Tac Toe. Currently, I am using matrices for the weights and input, and am stuck in implementing the error back-propogation for a feed-forward network, where the activation functions are sigmoid functions (and their derivatives).
I am currently using a Matrix library called mathjs (not sure if it has the functionality I need?). I understand that I need to get the error matrix, which is the matrix of output values minus the matrix of my network's predicted values.
However, after that, I'm a little confused when trying to implement gradient descent. The video at the following link (https://www.youtube.com/watch?v=GlcnxUlrtek&t=190s) says that you perform the following for the output-hidden operation:
partial_derivative = -(errors) * sig_derivative_of(this.layer_activation) *
activity_of_previous_layer;
As I understand, the layer activation matrix is just the sum of the inputs, and the activity matrix is the layer activation matrix with each element having had the sigmoid function applied to it.
If that is true, then let's say this.layer_activation, or in my case:
results[results.length - 1].sum; //size [4, 1]
You need to perform an element-wise multiplication on the sum, and for my activity matrix in the previous layer:
results[results.length - 2].result; //size [4, 3]
You need to perform a transposition operation on the activity matrix, followed by a matrix multiplication between the activity matrix and the output of:
(-(errors) * sig_derivative_of(results[results.length - 1].sum))
// [4, 1] x [4, 1] ?
Would that be correct? I have struggled hugely to understand matrices and it seems that the two operations are different from each other, except mathjs does not seem to distinguish the two.
To clarify, I am using the mathjs library from (http://mathjs.org/docs/datatypes/matrices.html). The number of inputs is 4, the number of hidden layers is just 1, and the number of nodes in the hidden layer is just 3.
Really appreciate any responses to this question!
via Daniel Soutar
No comments:
Post a Comment