12 #ifndef MLPACK_METHODS_ANN_LAYER_LP_POOLING_HPP    13 #define MLPACK_METHODS_ANN_LAYER_LP_POOLING_HPP    29     typename InputDataType = arma::mat,
    30     typename OutputDataType = arma::mat
    49             const size_t kernelWidth,
    50             const size_t kernelHeight,
    51             const size_t strideWidth = 1,
    52             const size_t strideHeight = 1,
    53             const bool floor = 
true);
    63   void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
    76                 const arma::Mat<eT>& gy,
    85   OutputDataType 
const& 
Delta()
 const { 
return delta; }
    87   OutputDataType& 
Delta() { 
return delta; }
   141   bool const& 
Floor()
 const { 
return floor; }
   151   template<
typename Archive>
   152   void serialize(Archive& ar, 
const uint32_t );
   161   template<
typename eT>
   162   void Pooling(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
   164     arma::Mat<eT> inputPre = input;
   165     inputPre = arma::pow(inputPre, normType);
   167     for (
size_t i = 1; i < input.n_cols; ++i)
   168       inputPre.col(i) += inputPre.col(i - 1);
   170     for (
size_t i = 1; i < input.n_rows; ++i)
   171       inputPre.row(i) += inputPre.row(i - 1);
   173     for (
size_t j = 0, colidx = 0; j < output.n_cols;
   174          ++j, colidx += strideHeight)
   176       for (
size_t i = 0, rowidx = 0; i < output.n_rows;
   177            ++i, rowidx += strideWidth)
   180         size_t rowEnd = rowidx + kernelWidth - 1;
   181         size_t colEnd = colidx + kernelHeight - 1;
   183         if (rowEnd > input.n_rows - 1)
   184           rowEnd = input.n_rows - 1;
   185         if (colEnd > input.n_cols - 1)
   186           colEnd = input.n_cols - 1;
   188         val += inputPre(rowEnd, colEnd);
   192             val += inputPre(rowidx - 1, colidx - 1);
   193           val -= inputPre(rowidx - 1, colEnd);
   197           val -= inputPre(rowEnd, colidx - 1);
   203     output = arma::pow(output, 1.0 / normType);
   212   template<
typename eT>
   213   void Unpooling(
const arma::Mat<eT>& input,
   214                  const arma::Mat<eT>& error,
   215                  arma::Mat<eT>& output)
   217     arma::Mat<eT> unpooledError;
   218     for (
size_t j = 0, colidx = 0; j < input.n_cols; j += strideHeight,
   221       for (
size_t i = 0, rowidx = 0; i < input.n_rows; i += strideWidth,
   224         size_t rowEnd = i + kernelWidth - 1;
   225         size_t colEnd = j + kernelHeight - 1;
   227         if (rowEnd > input.n_rows - 1)
   231           rowEnd = input.n_rows - 1;
   234         if (colEnd > input.n_cols - 1)
   238           colEnd = input.n_cols - 1;
   241         arma::mat InputArea = input(arma::span(i, rowEnd),
   242             arma::span(j, colEnd));
   244         size_t sum = pow(arma::accu(arma::pow(InputArea, normType)),
   245             (normType - 1) / normType);
   246         unpooledError = arma::Mat<eT>(InputArea.n_rows, InputArea.n_cols);
   247         unpooledError.fill(error(rowidx, colidx) / InputArea.n_elem);
   248         unpooledError %= arma::pow(InputArea, normType - 1);
   249         unpooledError /= sum;
   250         output(arma::span(i, i + InputArea.n_rows - 1),
   251             arma::span(j, j + InputArea.n_cols - 1)) += unpooledError;
   299   arma::cube outputTemp;
   302   arma::cube inputTemp;
   308   OutputDataType delta;
   311   OutputDataType gradient;
   314   OutputDataType outputParameter;
   322 #include "lp_pooling_impl.hpp" size_t const  & InputWidth() const
Get the intput width. 
 
void serialize(Archive &ar, const uint32_t)
Serialize the layer. 
 
size_t StrideWidth() const
Get the stride width. 
 
LpPooling()
Create the LpPooling object. 
 
Linear algebra utility functions, generally performed on matrices or vectors. 
 
size_t & StrideWidth()
Modify the stride width. 
 
Implementation of the LPPooling. 
 
size_t & KernelWidth()
Modify the kernel width. 
 
size_t KernelHeight() const
Get the kernel height. 
 
size_t OutputSize() const
Get the output size. 
 
The core includes that mlpack expects; standard C++ includes and Armadillo. 
 
size_t WeightSize() const
Get the size of the weights. 
 
OutputDataType const  & Delta() const
Get the delta. 
 
size_t & InputWidth()
Modify the input width. 
 
size_t StrideHeight() const
Get the stride height. 
 
bool & Floor()
Modify the value of the rounding operation. 
 
size_t KernelWidth() const
Get the kernel width. 
 
size_t & NormType()
Modify the normType. 
 
OutputDataType const  & OutputParameter() const
Get the output parameter. 
 
size_t const  & OutputWidth() const
Get the output width. 
 
size_t & OutputWidth()
Modify the output width. 
 
OutputDataType & OutputParameter()
Modify the output parameter. 
 
size_t & StrideHeight()
Modify the stride height. 
 
size_t & KernelHeight()
Modify the kernel height. 
 
size_t const  & InputHeight() const
Get the input height. 
 
size_t const  & OutputHeight() const
Get the output height. 
 
size_t & OutputHeight()
Modify the output height. 
 
size_t NormType() const
Get the normType. 
 
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
 
OutputDataType & Delta()
Modify the delta. 
 
size_t & InputHeight()
Modify the input height. 
 
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of a neural network, using 3rd-order tensors as input, calculating the function f(x) by propagating x backwards through f. 
 
size_t InputSize() const
Get the input size. 
 
bool const  & Floor() const
Get the value of the rounding operation.