public static unsafe void bb() { Terms.Variable w = new Terms.Variable(new Shape(1, 3)); w.SetValue(new float[1, 3] { { 2, 3, 1 } }); Terms.Variable w2 = new Terms.Variable(new Shape(1, 3)); w2.SetValue(new float[1, 3] { { 1, 1, 1 } }); Terms.Add s = new Terms.Add(w, w2); Hyperparameters.LearningRate = 1; Console.WriteLine(s.GetResult()); for (int i = 0; i < 1000; i++) { s.Minimize(); } s.DeleteResults(); Console.WriteLine(s.GetResult()); Console.WriteLine(w.GetResult()); w.Clean(); w2.Clean(); s.DeleteResults(); //Variables should be cleaned manually and disposed manually! All other terms should call dispose method. }
public override dynamic Forward(Term[] x) { Term[] res = new Term[x.Length]; for (int i = 0; i < x.Length; i++) { dynamic xn = x[i]; xn = new Terms.Add(new Terms.MatrixMultiply(xn, w), new Terms.Expand(b, new Shape(xn.Shape[0], 1))); if (this.activation == "sigmoid") { xn = new Terms.Sigmoid(xn); } else { throw new Exception(); } res[i] = xn; } //todo add activation function return(res); }