Beispiel #1
0
        public override Value PassBackward(Value value)
        {
            var output = new double[_inputeFm.Channels, _inputeFm.Size, _inputeFm.Size];

            for (int i = 0; i < _numberOfKernels; i++)
            {
                var kernel = value.Multi.GetSlice(i);
                kernel = MatrixProcessor.Pad(kernel, _kernelSize - 1);

                for (int j = 0; j < _inputeFm.Channels; j++)
                {
                    var weight = _kernels[i].Weights.GetSlice(j);
                    weight = MatrixProcessor.Flip(weight);
                    var conv = MatrixProcessor.Convolute(kernel, weight);

                    conv.ForEach((q, ii, jj) => output[j, ii, jj] += q);
                }
            }

            return(new MultiValue(output));
        }
Beispiel #2
0
            public void PadMatrixTest()
            {
                var initial = new double[2, 3, 3]
                {
                    {
                        { 11, 12, 13 },
                        { 21, 22, 23 },
                        { 31, 32, 33 }
                    },
                    {
                        { 11, 12, 13 },
                        { 21, 22, 23 },
                        { 31, 32, 33 }
                    },
                };
                var expected = new double[2, 7, 7]
                {
                    {
                        { 0, 0, 0, 0, 0, 0, 0 },
                        { 0, 0, 0, 0, 0, 0, 0 },
                        { 0, 0, 11, 12, 13, 0, 0 },
                        { 0, 0, 21, 22, 23, 0, 0 },
                        { 0, 0, 31, 32, 33, 0, 0 },
                        { 0, 0, 0, 0, 0, 0, 0 },
                        { 0, 0, 0, 0, 0, 0, 0 },
                    },
                    {
                        { 0, 0, 0, 0, 0, 0, 0 },
                        { 0, 0, 0, 0, 0, 0, 0 },
                        { 0, 0, 11, 12, 13, 0, 0 },
                        { 0, 0, 21, 22, 23, 0, 0 },
                        { 0, 0, 31, 32, 33, 0, 0 },
                        { 0, 0, 0, 0, 0, 0, 0 },
                        { 0, 0, 0, 0, 0, 0, 0 },
                    },
                };
                var actual = MatrixProcessor.Pad(initial, 2);

                Helper.CompareArrays(expected, actual);
            }