Exemplo n.º 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 = () =>
                {
                    //Ops.AddTanhD(m1.TGradient, m1.TGradient, res.TWeight, res.TGradient);
                    //Ops.AddTanhD(m2.TGradient, m2.TGradient, res.TWeight, res.TGradient);

                    m1.AddTanhGradient(res);
                    m2.AddTanhGradient(res);


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

            return(res);
        }
Exemplo n.º 2
0
        public IWeightTensor AddTanh(IWeightTensor w1, IWeightTensor w2)
        {
            WeightTensor m1  = w1 as WeightTensor;
            WeightTensor m2  = w2 as WeightTensor;
            WeightTensor res = m_weightTensorFactory.CreateWeightTensor(m1.Sizes, m_deviceId, name: $"{GetHashString(w1.Name, w2.Name)}.AddTanh");

            VisualizeNodes(new IWeightTensor[] { w1, w2 }, res);

            Ops.AddTanh(res.TWeight, m1.TWeight, m2.TWeight);
            if (m_needsBackprop)
            {
                Action backward = () =>
                {
                    m1.AddTanhGradient(res);
                    m2.AddTanhGradient(res);
                    res.Dispose();
                };
                m_backprop.Add(backward);
            }

            return(res);
        }