protected void EvaluateGradient() { if (!ValueEvaluated) { EvaluateValue(); } var tmpPoint = Point.Clone(); var tmpObj = InnerObjectiveFunction.CreateNew(); for (int ii = 0; ii < _gradient.Count; ++ii) { var origPoint = tmpPoint[ii]; var relIncr = origPoint * RelativeIncrement; var h = Math.Max(relIncr, MinimumIncrement); var mult = 1; if (origPoint + h > UpperBound[ii]) { mult = -1; } tmpPoint[ii] = origPoint + mult * h; tmpObj.EvaluateAt(tmpPoint); double bumpedValue = tmpObj.Value; _gradient[ii] = (mult * bumpedValue - mult * InnerObjectiveFunction.Value) / h; tmpPoint[ii] = origPoint; } GradientEvaluated = true; }
public IObjectiveFunction CreateNew() { var tmp = new ForwardDifferenceGradientObjectiveFunction(InnerObjectiveFunction.CreateNew(), LowerBound, UpperBound, RelativeIncrement, MinimumIncrement); return(tmp); }