public static void save_output_to_file(string name, DeconvolutionLayer layer)
 {
     for (int k = 0; k < layer.feature_maps_number; k++)
     {
         save_matrix_to_file(name + " feature map " + k.ToString() + " ", layer.feature_maps[k].output, layer.map_width, layer.map_height);
     }
 }
        public UpSamplingLayer(DeconvolutionLayer inp_deconv_layer, int outputmaps_num)
        {
            this.feature_maps_number = outputmaps_num;
            this.outputs             = new List <float[, ]>();
            this.feature_maps        = new List <UpSampleFeatureMap>();
            this.inputh = inp_deconv_layer.map_height;
            this.inputw = inp_deconv_layer.map_width;
            //decompression koef=2
            this.outputwidth  = inp_deconv_layer.map_width * 2;
            this.outputheight = inp_deconv_layer.map_height * 2;
            int proportion = inp_deconv_layer.feature_maps_number / outputmaps_num;

            //average-to-one-connection
            //averaging

            for (int j = 0; j < feature_maps_number * proportion; j++)
            {
                this.feature_maps.Add(new UpSampleFeatureMap(outputwidth, outputheight, inp_deconv_layer.feature_maps[j].output));
            }
        }
        //input is a picture's matrix
        public Network(int input_w, int input_h, int FL_feature_maps_number,
                       int fl_kw, int fl_kh, int SL_feature_maps_number, int sl_kw, int sl_kh)
        {
            this.FL_feature_maps_number = FL_feature_maps_number;
            this.SL_feature_maps_number = SL_feature_maps_number;

            //create first convolutional layer(first layer)
            FirstLayer = new ConvolutionLayer(FL_feature_maps_number, fl_kw, fl_kh, input_w, input_h);

            //first subsampling layer(second layer)
            SecondLayer = new SubsamplingLayer(FirstLayer);

            //second convolutional layer(third layer).Consists of number of convolutional layers
            ThirdLayer = new ConvolutionLayer(SL_feature_maps_number, sl_kw, sl_kh, SecondLayer.outputwidth, SecondLayer.outputheight);
            //connect inputs with previous layer
            //Parallel conctruction (like RGB) 2 cards of new layer for 1 card of previous layer
            //like 6/3 = 2
            //set topology for second layer
            List <int> topology = new List <int>();
            int        counter  = 0;

            for (int i = 0; i < FL_feature_maps_number; i++)
            {
                for (int j = 0; j < SL_feature_maps_number / FL_feature_maps_number; j++)
                {
                    topology.Add(counter);
                    counter++;
                }
                SecondLayer.set_link_with_conv_next_layer(ThirdLayer, i, topology);
                topology.Clear();
            }

            //set topology for third layer
            for (int i = 0; i < SL_feature_maps_number; i++)
            {
                int nextid = i * FL_feature_maps_number / SL_feature_maps_number;
                ThirdLayer.feature_maps[i].add_input_full_connection(SecondLayer.feature_maps[nextid].output);
            }



/*
 *          //all-to-all connection
 *          List<int> topology = new List<int>();
 *          for (int i = 0; i < FL_feature_maps_number; i++)
 *          {
 *              for (int j = 0; j < SL_feature_maps_number; j++)
 *              {
 *                  topology.Add(j);
 *              }
 *              SecondLayer.set_link_with_conv_next_layer(ThirdLayer, i, topology);
 *              topology.Clear();
 *          }
 *
 *          //set topology for third layer
 *          for (int j = 0; j < ThirdLayer.feature_maps_number; j++)
 *          {
 *              for (int i = 0; i < SecondLayer.feature_maps_number; i++)
 *              {
 *                  ThirdLayer.feature_maps[j].add_input_full_connection(SecondLayer.feature_maps[i].output);
 *              }
 *          }
 */

            FourthLayer = new SubsamplingLayer(ThirdLayer);

            FifthLayer   = new UpSamplingLayer(FourthLayer);
            SixthLayer   = new DeconvolutionLayer(FifthLayer, ThirdLayer);
            SeventhLayer = new UpSamplingLayer(SixthLayer, SecondLayer.feature_maps_number);
            EightsLayer  = new DeconvolutionLayer(SeventhLayer, FirstLayer);
        }