public ConvolutionalLayer2D(int radius, int sliceCount, Layer2D prevLayer, string activationFunction) : base(prevLayer, activationFunction, sliceCount)
        {
            this.radius = radius;
            var x = (int)prevLayer.GetActivatedBuffer(0).Extent.X;
            var y = (int)prevLayer.GetActivatedBuffer(0).Extent.Y;

            this.fac = GetSuitableFactorForFunction(function, (2 * radius + 1) * (2 * radius + 1));
            for (int i = 0; i < sliceCount; i++)
            {
                float[] source = { Config.learningRate, fac, radius };
                this.variable[i]  = GPUHelper.CreateBuffer(source, source.Length);
                this.bias[i]      = GPUHelper.CreateBuffer(x, y);
                this.activated[i] = GPUHelper.CreateBuffer(x, y);
                this.sumInput[i]  = GPUHelper.CreateBuffer(x, y);
                this.error[i]     = GPUHelper.CreateBuffer(x, y);
                this.weight[i]    = GPUHelper.CreateBuffer(x, y, this.GetWeightCount());
                this.derived[i]   = GPUHelper.CreateBuffer(x, y);
            }
        }
Пример #2
0
        public RandomLayer2D(Layer2D prevLayer, int sliceCount, int maxConnectionsPerNeuron) : base(prevLayer, null, sliceCount)
        {
            var x             = (int)prevLayer.GetActivatedBuffer(0).Extent.X;
            var y             = (int)prevLayer.GetActivatedBuffer(0).Extent.Y;
            var fac           = GetSuitableFactorForFunction(function, x * y);
            var weightFactory = new RandomMatrixFactory(x, y, maxConnectionsPerNeuron, RandomMatrixFactory.GenerationType.Float);
            var conFactory    = new RandomMatrixFactory(x, y, maxConnectionsPerNeuron * 2, RandomMatrixFactory.GenerationType.Integer, maxConnectionsPerNeuron);

            connectionInfo    = new MemoryBuffer3D <int> [sliceCount];
            newConnectionInfo = new MemoryBuffer3D <int> [sliceCount];
            for (int i = 0; i < sliceCount; i++)
            {
                float[] source = { Config.learningRate, fac };
                this.variable[i]  = GPUHelper.CreateBuffer(source, 2);
                this.bias[i]      = GPUHelper.CreateBuffer(x, y);
                this.activated[i] = GPUHelper.CreateBuffer(x, y);
                this.sumInput[i]  = GPUHelper.CreateBuffer(x, y);
                this.error[i]     = GPUHelper.CreateBuffer(x, y);
                this.weight[i]    = GPUHelper.CreateBuffer(x, y, maxConnectionsPerNeuron);
                this.derived[i]   = GPUHelper.CreateBuffer(x, y);
                bool b = true;
                while (b)
                {
                    if (conFactory.intQueue3D.Count > 1)
                    {
                        b = false;
                    }
                }
                int[,,] arr;
                conFactory.intQueue3D.TryDequeue(out arr);
                this.connectionInfo[i] = GPUHelper.CreateBuffer(arr, x, y, maxConnectionsPerNeuron * 2);
                conFactory.intQueue3D.TryDequeue(out arr);
                this.newConnectionInfo[i] = GPUHelper.CreateBuffer(arr, x, y, maxConnectionsPerNeuron * 2);
            }
            var extent = connectionInfo[0].Extent;
        }