Exemplo n.º 1
0
        public Matrix Nonlin(INonlinearity neuron, Matrix m)
        {
            Matrix returnObj = new Matrix(m.Rows, m.Cols);
            int    n         = m.W.Length;

            for (int i = 0; i < n; i++)
            {
                if (!m.Dropped[i])
                {
                    returnObj.W[i] = neuron.Forward(m.W[i]);
                }
            }
            if (this.ApplyBackprop)
            {
                Runnable bp = new Runnable();
                bp.Run = delegate()
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (!m.Dropped[i])
                        {
                            m.Dw[i] += neuron.Backward(m.W[i]) * returnObj.Dw[i];
                        }
                    }
                };
                Backprop.Add(bp);
            }
            return(returnObj);
        }
Exemplo n.º 2
0
        public NNValue Nonlin(INonlinearity neuron, NNValue m)
        {
            NNValue returnObj = new NNValue(m.H, m.W);
            int     n         = m.DataInTensor.Length;

            returnObj = neuron.Forward(m);

            if (this.ApplyBackprop)
            {
                Runnable bp = new Runnable();
                bp.Run = delegate()
                {
                    var data = neuron.Backward(m);

                    for (int i = 0; i < n; i++)
                    {
                        m.DifData[i] += data.DataInTensor[i] * returnObj.DifData[i];
                    }
                };
                Backprop.Add(bp);
            }
            return(returnObj);
        }
Exemplo n.º 3
0
        public Matrix Nonlin(INonlinearity neuron, Matrix m)
        {
            Matrix returnObj = new Matrix(m.Rows, m.Cols);
            int n = m.W.Length;
            for (int i = 0; i < n; i++)
            {
                returnObj.W[i] = neuron.Forward(m.W[i]);
            }
            if (this.ApplyBackprop)
            {
                Runnable bp = new Runnable();
                bp.Run = delegate()
                {
                    for (int i = 0; i < n; i++)
                    {
                        m.Dw[i] += neuron.Backward(m.W[i]) * returnObj.Dw[i];
                    }

                };
                Backprop.Add(bp);
            }
            return returnObj;
        }