예제 #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();
                }
            }
예제 #2
0
            private void MakeSteepestDescDir()
            {
                if (!EnforceNonNegativity)
                {
                    VBufferUtils.ApplyInto(ref _x, ref _grad, ref _steepestDescDir,
                                           (ind, xVal, gradVal) =>
                    {
                        if (ind < _biasCount)
                        {
                            return(-gradVal);
                        }
                        if (xVal < 0)
                        {
                            return(-gradVal + _l1weight);
                        }
                        if (xVal > 0)
                        {
                            return(-gradVal - _l1weight);
                        }
                        if (gradVal < -_l1weight)
                        {
                            return(-gradVal - _l1weight);
                        }
                        if (gradVal > _l1weight)
                        {
                            return(-gradVal + _l1weight);
                        }
                        return(0);
                    });
                }
                else
                {
                    VBufferUtils.ApplyInto(ref _x, ref _grad, ref _steepestDescDir,
                                           (ind, xVal, gradVal) =>
                    {
                        if (ind < _biasCount)
                        {
                            return(-gradVal);
                        }
                        if (xVal > 0)
                        {
                            return(-gradVal - _l1weight);
                        }
                        return(-Math.Min(gradVal + _l1weight, 0));
                    });
                }

                _steepestDescDir.CopyTo(ref _dir);
            }