Example #1
0
        /// <summary>
        /// Updates the specified iteration.
        /// </summary>
        /// <param name="iteration">The iteration.</param>
        /// <param name="layer">The layer.</param>
        internal override void Update(int iteration, BaseLayer layer)
        {
            if (DecayRate > 0)
            {
                LearningRate = LearningRate * (1 / (1 + DecayRate * iteration));
            }

            float t    = iteration + 1;
            float lr_t = Convert.ToSingle(LearningRate / (1f - Math.Pow(Beta1, t)));

            foreach (var item in layer.Params)
            {
                var param = item.Value;

                if (!ms.ContainsKey(param.Name))
                {
                    ms[param.Name] = SuperArray.Constant(0f, param.Data.Shape);
                    us[param.Name] = SuperArray.Constant(0f, param.Data.Shape);
                }

                var m_t = (Beta1 * ms[param.Name]) + (1 - Beta1) * param.Grad;
                var u_t = Ops.Maximum((Beta2 * us[param.Name]), Ops.Abs(param.Grad));

                param.Data     = param.Data - LearningRate * m_t / (u_t + Ops.EPSILON);
                ms[param.Name] = m_t;
                us[param.Name] = u_t;

                param.ApplyConstraint();
            }
        }
Example #2
0
        public static void RunArraySimplified()
        {
            //Create an array with values
            SuperArray a = SuperArray.Create(new float[, ] {
                { 1, 2 }, { 3, 4 }, { 5, 6 }
            });

            //Create a array with constant value 2
            SuperArray b = SuperArray.Constant <float>(2, (3, 2));

            var sum = a + b;
            //Perform Math operation on the array: 2A + Log(B) + Exp(A)
            var r = 2 * a - Ops.Log(b) + Ops.Exp(a);

            //Print the Array
            r.Print();
        }