Beispiel #1
0
            internal virtual void UpdateDir()
            {
                if (EnforceNonNegativity)
                {
                    VBufferUtils.ApplyInto(ref _x, ref _grad, ref _steepestDescDir,
                                           (ind, xVal, gradVal) =>
                    {
                        if (xVal > 0)
                        {
                            return(-gradVal);
                        }
                        return(-Math.Min(gradVal, 0));
                    });

                    _steepestDescDir.CopyTo(ref _dir);
                }
                else
                {
                    VectorUtils.ScaleInto(ref _grad, -1, ref _dir);
                }

                MapDirByInverseHessian();

                if (EnforceNonNegativity)
                {
                    FixDirZeros();
                }
            }
Beispiel #2
0
            public LineFunc(DifferentiableFunction function, ref VBuffer <Float> initial, bool useCG = false)
            {
                int dim = initial.Length;

                initial.CopyTo(ref _point);
                _func = function;
                // REVIEW: plumb the IProgressChannelProvider through.
                _value = _func(ref _point, ref _grad, null);
                VectorUtils.ScaleInto(ref _grad, -1, ref _dir);

                _useCG = useCG;
            }
Beispiel #3
0
 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;
 }