Beispiel #1
0
        public override void Connect(Layer inLayer)
        {
            if (inLayer.Shape != InputShape)
            {
                throw new ShapeMismatchException(nameof(inLayer));
            }

            ShapedArray <Neuron> padded = Padder.PadArray(inLayer.Neurons.ToShape(Shape), Paddings, () => new Neuron()
            {
                OutVal = PadVal
            });

            var inConnections = new ShapedArray <List <Synapse> >(PaddedShape, () => new List <Synapse>());

            IndexGen.ByStrides(PaddedShape, Strides, KernelShape).ForEach((idxKernel, i) =>
            {
                Neuron outN = base.Neurons[i];

                outN.InSynapses = IndexGen.ByStart(KernelShape, Array <int> .FromRef(idxKernel)).Select((idx, j) =>
                {
                    var S = new Synapse(padded[idx], outN);
                    inConnections[idx].Add(S);
                    return(S);
                });
            });

            padded.ForEach((N, i) => N.OutSynapses = Array <Synapse> .FromRef(inConnections[i].ToArray()));
        }
Beispiel #2
0
        public override void Connect(Layer inLayer)
        {
            if (inLayer.Shape != InputShape)
            {
                throw new ShapeMismatchException(nameof(inLayer));
            }

            ShapedArray <Neuron> padded = Padder.PadArray(inLayer.Neurons.ToShape(Shape), Paddings, () => new Neuron()
            {
                OutVal = PadVal
            });

            var inConnections = new ShapedArray <List <Synapse> >(PaddedShape, () => new List <Synapse>());

            Kernels.ForEach((kernel, i) =>
            {
                int offset = i * Shape.Volume / KernelsNum;

                IndexGen.ByStrides(PaddedShape, Strides, KernelShape).ForEach((idxKernel, j) =>
                {
                    var outN = (CNeuron)Neurons[offset + j];

                    outN.KernelBias = kernel.Bias;

                    outN.InSynapses = IndexGen.ByStart(KernelShape, Array <int> .FromRef(idxKernel)).Select((idx, k) =>
                    {
                        var S = new CSynapse(padded[idx], outN)
                        {
                            KernelWeight = kernel.Weights[k]
                        };

                        inConnections[idx].Add(S);
                        return((Synapse)S);
                    });
                });
            });

            padded.ForEach((N, i) => N.OutSynapses = Array <Synapse> .FromRef(inConnections[i].ToArray()));
        }