13 #ifndef MLPACK_METHODS_ANN_LAYER_HIGHWAY_HPP 14 #define MLPACK_METHODS_ANN_LAYER_HIGHWAY_HPP 18 #include "../visitor/delete_visitor.hpp" 19 #include "../visitor/delta_visitor.hpp" 20 #include "../visitor/output_height_visitor.hpp" 21 #include "../visitor/output_parameter_visitor.hpp" 22 #include "../visitor/output_width_visitor.hpp" 55 typename InputDataType = arma::mat,
56 typename OutputDataType = arma::mat,
57 typename... CustomLayers>
70 Highway(
const size_t inSize,
const bool model =
true);
88 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
100 void Backward(
const arma::Mat<eT>& ,
101 const arma::Mat<eT>& gy,
111 template<
typename eT>
112 void Gradient(
const arma::Mat<eT>& input,
113 const arma::Mat<eT>& error,
114 arma::Mat<eT>& gradient);
121 template <
class LayerType,
class... Args>
124 network.push_back(
new LayerType(args...));
125 networkOwnerships.push_back(
true);
133 void Add(LayerTypes<CustomLayers...> layer)
135 network.push_back(layer);
136 networkOwnerships.push_back(
false);
140 std::vector<LayerTypes<CustomLayers...> >&
Model()
166 OutputDataType
const&
Delta()
const {
return delta; }
168 OutputDataType&
Delta() {
return delta; }
171 OutputDataType
const&
Gradient()
const {
return gradient; }
187 template<
typename Archive>
188 void serialize(Archive& ar,
const uint32_t );
201 std::vector<LayerTypes<CustomLayers...> > network;
204 std::vector<bool> networkOwnerships;
207 std::vector<LayerTypes<CustomLayers...> > empty;
210 OutputDataType weights;
213 OutputDataType delta;
216 OutputDataType gradient;
219 OutputDataType transformWeight;
222 OutputDataType transformBias;
225 OutputDataType transformGate;
228 OutputDataType transformGateActivation;
231 OutputDataType transformGateError;
234 InputDataType inputParameter;
237 OutputDataType outputParameter;
246 OutputDataType networkOutput;
OutputDataType const & Delta() const
Get the delta.
Definition: highway.hpp:166
DeleteVisitor executes the destructor of the instantiated object.
Definition: delete_visitor.hpp:27
OutputHeightVisitor exposes the OutputHeight() method of the given module.
Definition: output_height_visitor.hpp:27
size_t InputShape() const
Get the shape of the input.
Definition: highway.hpp:179
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: highway_impl.hpp:218
~Highway()
Destroy the Highway object.
Definition: highway_impl.hpp:56
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
InputDataType const & InputParameter() const
Get the input parameter.
Definition: highway.hpp:156
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...
Definition: highway_impl.hpp:80
InputDataType & InputParameter()
Modify the input parameter.
Definition: highway.hpp:158
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: highway.hpp:161
std::vector< LayerTypes< CustomLayers... > > & Model()
Return the modules of the model.
Definition: highway.hpp:140
Implementation of the Highway layer.
Definition: highway.hpp:58
OutputDataType & Parameters()
Modify the parameters.
Definition: highway.hpp:153
OutputParameterVisitor exposes the output parameter of the given module.
Definition: output_parameter_visitor.hpp:27
OutputDataType & Delta()
Modify the delta.
Definition: highway.hpp:168
OutputDataType & Gradient()
Modify the gradient.
Definition: highway.hpp:173
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: highway.hpp:163
size_t InSize() const
Get the number of input units.
Definition: highway.hpp:176
void Add(Args... args)
Add a new module to the model.
Definition: highway.hpp:122
DeltaVisitor exposes the delta parameter of the given module.
Definition: delta_visitor.hpp:27
OutputWidthVisitor exposes the OutputWidth() method of the given module.
Definition: output_width_visitor.hpp:27
void Add(LayerTypes< CustomLayers... > layer)
Add a new module to the model.
Definition: highway.hpp:133
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: highway_impl.hpp:156
void Reset()
Reset the layer parameter.
Definition: highway_impl.hpp:70
OutputDataType const & Parameters() const
Get the parameters.
Definition: highway.hpp:151
Highway()
Create the Highway object.
Definition: highway_impl.hpp:30
OutputDataType const & Gradient() const
Get the gradient.
Definition: highway.hpp:171