コード例 #1
0
        public IWeightMatrix AddTanh(IWeightMatrix w1, IWeightMatrix w2)
        {
            var m1  = w1 as WeightTensor;
            var m2  = w2 as WeightTensor;
            var res = weightTensorFactory.CreateWeightTensor(m1.Rows, m1.Columns, deviceId);

            Ops.AddTanh(res.TWeight, m1.TWeight, m2.TWeight);

            if (this.needs_backprop)
            {
                Action backward = () =>
                {
                    //Tensor tTmp = Ops.TanhD(null, res.TWeight, res.TGradient);
                    //Ops.Add(m1.TGradient, m1.TGradient, tTmp);
                    //Ops.Add(m2.TGradient, m2.TGradient, tTmp);
                    //tTmp.Dispose();


                    Ops.AddTanhD(m1.TGradient, m1.TGradient, res.TWeight, res.TGradient);
                    Ops.AddTanhD(m2.TGradient, m2.TGradient, res.TWeight, res.TGradient);


                    res.Dispose();
                };
                this.backprop.Add(backward);
            }

            return(res);
        }
コード例 #2
0
        public void AddTanhGradient(WeightTensor src)
        {
            if (m_TGradient == null)
            {
                allocator   = TensorAllocator.Allocator(DeviceId);
                m_TGradient = new Tensor(allocator, DType.Float32, src.TWeight.Sizes);

                Ops.TanhD(m_TGradient, src.TWeight, src.TGradient);
            }
            else
            {
                Ops.AddTanhD(m_TGradient, m_TGradient, src.TWeight, src.TGradient);
            }
        }
コード例 #3
0
        public IWeightMatrix Tanh(IWeightMatrix w)
        {
            var m   = w as WeightTensor;
            var res = weightTensorFactory.CreateWeightTensor(m.Rows, m.Columns, deviceId);

            Ops.Tanh(res.TWeight, m.TWeight);

            if (this.needs_backprop)
            {
                Action backward = () =>
                {
                    Ops.AddTanhD(m.TGradient, m.TGradient, res.TWeight, res.TGradient);
                };
                this.backprop.Add(backward);
            }

            return(res);
        }