public void learn(Matrix target) { Matrix outputError = MatrixMath.Subtraction(target, this.learningOut); // this is the error of my output layer will use a f**k ton of math for next steps // This is the gradient from output to Matrix dSigmoidOutput = dsigmoid(learningOut); //dsig rows: 4 Col: 1 outputError Rows: 4 Col: 1 Matrix temp = MatrixMath.HMultiplication(dSigmoidOutput, outputError); Matrix gradient = MatrixMath.Multiplication(temp, this.lr); // Debug.Log(gradient.getColumns() + " " + gradient.getRows() + " " + temp.getColumns() + " " + temp.getRows()); Matrix hiddenTranspose = MatrixMath.Transpose(hiddenLearn); Matrix weightHODeltas = MatrixMath.Multiplication(gradient, hiddenTranspose); //hiddenLearn.Print(); this.weightH2 = MatrixMath.Addition(this.weightH2, weightHODeltas); Matrix weightH2Transpose = MatrixMath.Transpose(weightH2); Matrix hiddenErrors = MatrixMath.Multiplication(weightH2Transpose, outputError); //calcl hidden gradient Matrix dSigmoidHidden = dsigmoid(hiddenLearn); Matrix hiddenTemp = MatrixMath.HMultiplication(dSigmoidHidden, hiddenErrors); Matrix hiddenGradient = MatrixMath.Multiplication(hiddenTemp, this.lr); //clac input to hidden deltas Matrix inputTranspose = MatrixMath.Transpose(input); Matrix weight1Delta = MatrixMath.Multiplication(hiddenGradient, inputTranspose); this.weightH1 = MatrixMath.Addition(this.weightH1, weight1Delta); // this.weightH1.Print(); }
public Matrix feedforward(Matrix inputs) { this.input = inputs; Matrix hidden = MatrixMath.Multiplication(weightH1, inputs); Matrix hOut = MatrixMath.Addition(hidden, bias1); Matrix hiddenOut = activationFunction(hidden); Matrix output = MatrixMath.Multiplication(weightH2, hiddenOut); Matrix oOut = MatrixMath.Addition(output, bias2); Matrix outputOut = activationFunction(output); learningOut = outputOut; hiddenLearn = hidden; outputOut.Print(); Debug.Log(""); return(outputOut); }