12 #ifndef MLPACK_METHODS_ANN_LAYER_SUBVIEW_HPP 13 #define MLPACK_METHODS_ANN_LAYER_SUBVIEW_HPP 31 typename InputDataType = arma::mat,
32 typename OutputDataType = arma::mat
48 const size_t beginRow = 0,
49 const size_t endRow = 0,
50 const size_t beginCol = 0,
51 const size_t endCol = 0) :
68 template<
typename InputType,
typename OutputType>
69 void Forward(
const InputType& input, OutputType& output)
71 size_t batchSize = input.n_cols / inSize;
74 endRow = ((endRow < input.n_rows) && (endRow >= beginRow))?
75 endRow : (input.n_rows - 1);
76 endCol = ((endCol < inSize) && (endCol >= beginCol)) ?
77 endCol : (inSize - 1);
80 (endRow - beginRow + 1) * (endCol - beginCol + 1), batchSize);
82 size_t batchBegin = beginCol;
83 size_t batchEnd = endCol;
86 if ((input.n_rows != ((endRow - beginRow + 1) *
87 (endCol - beginCol + 1))) || (input.n_cols != batchSize))
89 for (
size_t i = 0; i < batchSize; ++i)
91 output.col(i) = arma::vectorise(
92 input.submat(beginRow, batchBegin, endRow, batchEnd));
114 template<
typename eT>
116 const arma::Mat<eT>& gy,
128 OutputDataType
const&
Delta()
const {
return delta; }
130 OutputDataType&
Delta() {
return delta; }
136 size_t const&
BeginRow()
const {
return beginRow; }
141 size_t const&
EndRow()
const {
return endRow; }
146 size_t const&
BeginCol()
const {
return beginCol; }
151 size_t const&
EndCol()
const {
return endCol; }
158 template<
typename Archive>
161 ar(CEREAL_NVP(inSize));
162 ar(CEREAL_NVP(beginRow));
163 ar(CEREAL_NVP(endRow));
164 ar(CEREAL_NVP(beginCol));
165 ar(CEREAL_NVP(endCol));
185 OutputDataType delta;
188 OutputDataType outputParameter;
size_t & EndCol()
Modify the width of each sample.
Definition: subview.hpp:153
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: subview.hpp:159
void Forward(const InputType &input, OutputType &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
Definition: subview.hpp:69
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
size_t const & EndRow() const
Get the ending row index of subview vector or matrix.
Definition: subview.hpp:141
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t InSize() const
Get the width of each sample.
Definition: subview.hpp:133
size_t & BeginCol()
Modify the width of each sample.
Definition: subview.hpp:148
size_t const & EndCol() const
Get the ending column index of subview vector or matrix.
Definition: subview.hpp:151
size_t const & BeginCol() const
Get the width of each sample.
Definition: subview.hpp:146
OutputDataType const & Delta() const
Get the delta.
Definition: subview.hpp:128
Subview(const size_t inSize=1, const size_t beginRow=0, const size_t endRow=0, const size_t beginCol=0, const size_t endCol=0)
Create the Subview layer object using the specified range of input to accept.
Definition: subview.hpp:47
Implementation of the subview layer.
Definition: subview.hpp:34
size_t & EndRow()
Modify the width of each sample.
Definition: subview.hpp:143
size_t const & BeginRow() const
Get the starting row index of subview vector or matrix.
Definition: subview.hpp:136
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: subview.hpp:125
OutputDataType & Delta()
Modify the delta.
Definition: subview.hpp:130
size_t & BeginRow()
Modify the width of each sample.
Definition: subview.hpp:138
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
Definition: subview.hpp:115
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: subview.hpp:123