public OutputP Execute(InputP input) { double[,] a1 = new double[8, 1]; double[,] a2 = new double[1, 1]; a1 = Matrix.Mult(w1, input.vector); a1 = Matrix.Plus(b1, a1); for (int i = 0; i < a1.GetLength(0); i++) { a1[i, 0] = fun1(a1[i, 0]); } a2 = Matrix.Mult(w2, a1); a2 = Matrix.Plus(b2, a2); for (int i = 0; i < a2.GetLength(0); i++) { a2[i, 0] = fun2(a2[i, 0]); } return(new OutputP(a2[0, 0])); }
public void Training(InputP input) { double[,] a1 = new double[8, 1]; double[,] a2 = new double[1, 1]; a1 = Matrix.Mult(w1, input.vector); a1 = Matrix.Plus(b1, a1); for (int i = 0; i < a1.GetLength(0); i++) { a1[i, 0] = fun1(a1[i, 0]); } a2 = Matrix.Mult(w2, a1); a2 = Matrix.Plus(b2, a2); for (int i = 0; i < a2.GetLength(0); i++) { a2[i, 0] = fun2(a2[i, 0]); } double[,] e = new double[1, 1]; e = Matrix.Minus(input.o.vector, a2); double[,] s2 = new double[1, 1]; double[,] s1 = new double[8, 8]; double[,] ss1 = new double[8, 1]; double[,] ss2 = new double[1, 1]; double[,] con = new double[1, 1]; con[0, 0] = -2; for (int i = 0; i < 1; i++) { s2[i, i] = dfun2(a2[i, 0]); } ss2 = Matrix.Mult(s2, e); ss2 = Matrix.Mult(ss2, con); for (int i = 0; i < 8; i++) { s1[i, i] = dfun1(a1[i, 0]); } ss1 = Matrix.Mult(Matrix.Inv(w2), ss2); ss1 = Matrix.Mult(s1, ss1); con[0, 0] = 0.5; w1 = Matrix.Minus(w1, Matrix.Mult(Matrix.Mult(ss1, con), Matrix.Inv(input.vector))); w2 = Matrix.Minus(w2, Matrix.Mult(Matrix.Mult(ss2, con), Matrix.Inv(a1))); b1 = Matrix.Minus(b1, Matrix.Mult(ss1, con)); b2 = Matrix.Minus(b2, Matrix.Mult(ss2, con)); }