示例#1
0
        public AmsBoundParameter(NdArray parameter, AmsBound optimizer) : base(parameter)
        {
            this.m    = new Real[parameter.Data.Length];
            this.v    = new Real[parameter.Data.Length];
            this.vhat = new Real[parameter.Data.Length];

            this._optimizer = optimizer;
        }
示例#2
0
        public static void UpdateFunctionParameters(Real alpha, Real initialAlpha, Real gamma, Real beta1, Real beta2, Real epsilon, Real eta, long updateCount, NdArray <Real> functionParameter, Real[] m, Real[] v, Real[] vhat, ref Real finalLr, out Real lower, out Real upper, Func <Real, Real> clip)
        {
            Real alphaT = AdamParameter.GetAlphaT(alpha, beta1, beta2, updateCount);

            AmsBound.UpdateBound(alpha, initialAlpha, gamma, updateCount, ref finalLr, out lower, out upper);

            for (int i = 0; i < functionParameter.Data.Length; i++)
            {
                Real grad = functionParameter.Grad[i];

                m[i] += (1 - beta1) * (grad - m[i]);
                v[i] += (1 - beta2) * (grad * grad - v[i]);

                if (vhat[i] < v[i])
                {
                    vhat[i] = v[i];
                }

                Real step = clip(alphaT / (Math.Sqrt(vhat[i]) + epsilon));

                functionParameter.Data[i] -= eta * step * m[i];
            }
        }