/// <summary> /// Returns true if the proved bound on the distance from the optimum, /// normalized by the function value, is less than the tolerance /// </summary> /// <param name="state">current state of the optimizer</param> /// <param name="message">value of criterion</param> /// <returns>true if criterion is less than tolerance</returns> public override bool Terminate(Optimizer.OptimizerState state, out string message) { var gradient = state.Grad; Float gradientNormSquared = VectorUtils.NormSquared(gradient); Float value = state.Value; Float newBoundOnMin = value - (Float)0.5 * _sigmaSq * gradientNormSquared; _bestBoundOnMin = Math.Max(_bestBoundOnMin, newBoundOnMin); Float val = (value - _bestBoundOnMin) / Math.Abs(value); message = string.Format("{0,0:0.0000e0}", val); return(val < _tol); }
public void ChangeDir() { if (_useCG) { Float newByNew = VectorUtils.NormSquared(_newGrad); Float newByOld = VectorUtils.DotProduct(ref _newGrad, ref _grad); Float oldByOld = VectorUtils.NormSquared(_grad); Float betaPR = (newByNew - newByOld) / oldByOld; Float beta = Math.Max(0, betaPR); VectorUtils.ScaleBy(ref _dir, beta); VectorUtils.AddMult(ref _newGrad, -1, ref _dir); } else { VectorUtils.ScaleInto(ref _newGrad, -1, ref _dir); } _newPoint.CopyTo(ref _point); _newGrad.CopyTo(ref _grad); _value = _newValue; }