public void Calculate_ShouldReturnXPosWhereFunctionResultIsMinimum() { var functionHandler = new TwoVarsFunc("2 * x1 ^ 2 + x1 * x2 + x2 ^ 2"); var constantStepGradientDescent = new ConstantStepGradientDescent(0.5, 1, 0.5, 0.1, 0.15, 10, 0.5, functionHandler); var pair = constantStepGradientDescent.Calculate(); var result = Math.Round(functionHandler.Calculate(pair.x1, pair.x2) * 10000) / 10000; Assert.AreEqual(0.0075, result); }
public void Calculate_ShouldReturnXPosesWhereFunctionResultIsMinimum() { var functionHandler = new TwoVarsFunc("2 * x1 ^ 2 + x1 * x2 + x2 ^ 2"); var constantSlope = new SteppestGradientDescent(0.5, 1, 0.1, 0.15, 10, functionHandler); var pair = constantSlope.Calculate(); var predict = new Pair { x1 = -0.0176, x2 = 0.032 }; var result = UnderError(pair.x1, predict.x1, 7) && UnderError(pair.x2, predict.x2, 7); Assert.AreEqual(true, result); }
public ConstantStepGradientDescent(double x1, double x2, double e, double e1, double e2, int M, double tk, TwoVarsFunc twoVarsFunc) { this.xPairs = new List <Pair>(); this.deltaFResults = new List <Pair>(); this.functionHandler = twoVarsFunc; this.xPairs.Add(new Pair() { x1 = x1, x2 = x2 }); this.e = e; this.e1 = e1; this.e2 = e2; this.M = M; this.tk = tk; }
public SteppestGradientDescent(double x1, double x2, double e1, double e2, int M, TwoVarsFunc func) { this.functionHandler = func; this.xPairs.Add(new Pair { x1 = x1, x2 = x2 }); this.e1 = e1; this.e2 = e2; this.M = M; }