mlpack  master
add_merge.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_ADD_MERGE_HPP
14 #define MLPACK_METHODS_ANN_LAYER_ADD_MERGE_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 #include "../visitor/delete_visitor.hpp"
19 #include "../visitor/delta_visitor.hpp"
20 #include "../visitor/output_parameter_visitor.hpp"
21 
22 #include "layer_types.hpp"
23 
24 namespace mlpack {
25 namespace ann {
26 
36 template<
37  typename InputDataType = arma::mat,
38  typename OutputDataType = arma::mat
39 >
40 class AddMerge
41 {
42  public:
44  AddMerge();
45 
53  template<typename InputType, typename OutputType>
54  void Forward(const InputType&& /* input */, OutputType&& output);
55 
65  template<typename eT>
66  void Backward(const arma::Mat<eT>&& /* input */,
67  arma::Mat<eT>&& gy,
68  arma::Mat<eT>&& g);
69 
70  /*
71  * Add a new module to the model.
72  *
73  * @param layer The Layer to be added to the model.
74  */
75  void Add(LayerTypes layer) { network.push_back(layer); }
76 
77  /*
78  * Add a new module to the model.
79  *
80  * @param layer The Layer to be added to the model.
81  */
82  template<typename LayerType>
83  void Add(const LayerType& layer) { network.push_back(new LayerType(layer)); }
84 
85  /*
86  * Add a new module to the model.
87  *
88  * @param args The layer parameter.
89  */
90  template <class LayerType, class... Args>
91  void Add(Args... args) { network.push_back(new LayerType(args...)); }
92 
94  InputDataType const& InputParameter() const { return inputParameter; }
96  InputDataType& InputParameter() { return inputParameter; }
97 
99  OutputDataType const& OutputParameter() const { return outputParameter; }
101  OutputDataType& OutputParameter() { return outputParameter; }
102 
104  OutputDataType const& Delta() const { return delta; }
106  OutputDataType& Delta() { return delta; }
107 
111  template<typename Archive>
112  void Serialize(Archive& ar, const unsigned int /* version */);
113 
114  private:
115  std::vector<LayerTypes> network;
116 
119 
122 
125 
127  OutputDataType delta;
128 
130  InputDataType inputParameter;
131 
133  OutputDataType outputParameter;
134 }; // class AddMerge
135 
136 } // namespace ann
137 } // namespace mlpack
138 
139 // Include implementation.
140 #include "add_merge_impl.hpp"
141 
142 #endif
DeleteVisitor executes the destructor of the instantiated object.
OutputDataType & Delta()
Modify the delta.
Definition: add_merge.hpp:106
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
Implementation of the AddMerge module class.
Definition: add_merge.hpp:40
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Add(Args...args)
Definition: add_merge.hpp:91
OutputParameterVisitor outputParameterVisitor
Locally-stored output parameter visitor module object.
Definition: add_merge.hpp:121
void Add(LayerTypes layer)
Definition: add_merge.hpp:75
DeltaVisitor deltaVisitor
Locally-stored delta visitor module object.
Definition: add_merge.hpp:124
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: add_merge.hpp:101
DeleteVisitor deleteVisitor
Locally-stored delete visitor module object.
Definition: add_merge.hpp:118
OutputParameterVisitor exposes the output parameter of the given module.
InputDataType inputParameter
Locally-stored input parameter object.
Definition: add_merge.hpp:130
boost::variant< Add< arma::mat, arma::mat > *, AddMerge< arma::mat, arma::mat > *, BaseLayer< LogisticFunction, arma::mat, arma::mat > *, BaseLayer< IdentityFunction, arma::mat, arma::mat > *, BaseLayer< TanhFunction, arma::mat, arma::mat > *, BaseLayer< RectifierFunction, arma::mat, arma::mat > *, Concat< arma::mat, arma::mat > *, ConcatPerformance< NegativeLogLikelihood< arma::mat, arma::mat >, arma::mat, arma::mat > *, Constant< arma::mat, arma::mat > *, Convolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, DropConnect< arma::mat, arma::mat > *, Dropout< arma::mat, arma::mat > *, Glimpse< arma::mat, arma::mat > *, HardTanH< arma::mat, arma::mat > *, Join< arma::mat, arma::mat > *, LeakyReLU< arma::mat, arma::mat > *, Linear< arma::mat, arma::mat > *, LinearNoBias< arma::mat, arma::mat > *, LogSoftMax< arma::mat, arma::mat > *, Lookup< arma::mat, arma::mat > *, LSTM< arma::mat, arma::mat > *, MaxPooling< arma::mat, arma::mat > *, MeanPooling< arma::mat, arma::mat > *, MeanSquaredError< arma::mat, arma::mat > *, MultiplyConstant< arma::mat, arma::mat > *, NegativeLogLikelihood< arma::mat, arma::mat > *, PReLU< arma::mat, arma::mat > *, Recurrent< arma::mat, arma::mat > *, RecurrentAttention< arma::mat, arma::mat > *, ReinforceNormal< arma::mat, arma::mat > *, Select< arma::mat, arma::mat > *, Sequential< arma::mat, arma::mat > *, VRClassReward< arma::mat, arma::mat > * > LayerTypes
void Add(const LayerType &layer)
Definition: add_merge.hpp:83
void Backward(const arma::Mat< eT > &&, 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...
OutputDataType delta
Locally-stored delta object.
Definition: add_merge.hpp:127
AddMerge()
Create the AddMerge object.
void Forward(const InputType &&, OutputType &&output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
OutputDataType outputParameter
Locally-stored output parameter object.
Definition: add_merge.hpp:133
DeltaVisitor exposes the delta parameter of the given module.
InputDataType & InputParameter()
Modify the input parameter.
Definition: add_merge.hpp:96
OutputDataType const & Delta() const
Get the delta.
Definition: add_merge.hpp:104
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: add_merge.hpp:99
InputDataType const & InputParameter() const
Get the input parameter.
Definition: add_merge.hpp:94
std::vector< LayerTypes > network
Definition: add_merge.hpp:115