private void ConnectPipesToLayersOutputs(ICollection <IPipe> inp, ConvolutionNeuralLayer layer)
 {
     for (var index = 0; index < layer.Count; index++)
     {
         layer.ElementAt(index).setOutput(inp.OffsetCenteredWrappedSubset(index, ConnectionsPerNeuron).First());
     }
 }
        public ConvolutionNeuralNetwork Construct(ICollection <IPipe> inp, ICollection <IPipe> outp)
        {
            ConnectionsPerNeuron = (int)Math.Floor(cells * interconectivity);// the number of neurons each cell connects to in the prevoyus layer
            ConvolutionNeuralNetwork net = new ConvolutionNeuralNetwork();

            for (int l = 0; l < layers; l++)
            {
                var layer  = new ConvolutionNeuralLayer();
                var inputs = new IPipe[] { new IPipe() };
                layer.Fill(() => new ConvolutionNeuron(inputs, new IPipe()), cells);
                if (l == 0)
                {
                    ConnectPipesToLayersInputs(inp, layer);
                }
                else if (l == layers - 1)
                {
                    ConnectPipesToLayersOutputs(outp, layer);
                }
                else
                {
                    ConnectPipesToLayersInputs(net.ElementAt(l - 1).getOutput(), layer);
                }
                net.AddLast(layer);
            }

            return(net);
        }