mlpack  master
constant.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_CONSTANT_HPP
14 #define MLPACK_METHODS_ANN_LAYER_CONSTANT_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace ann {
20 
30 template <
31  typename InputDataType = arma::mat,
32  typename OutputDataType = arma::mat
33 >
34 class Constant
35 {
36  public:
44  Constant(const size_t outSize, const double scalar);
45 
53  template<typename InputType, typename OutputType>
54  void Forward(const InputType&& input, OutputType&& output);
55 
64  template<typename DataType>
65  void Backward(const DataType&& /* input */,
66  DataType&& /* gy */,
67  DataType&& g);
68 
70  InputDataType& InputParameter() const { return inputParameter; }
72  InputDataType& InputParameter() { return inputParameter; }
73 
75  OutputDataType& OutputParameter() const { return outputParameter; }
77  OutputDataType& OutputParameter() { return outputParameter; }
78 
80  OutputDataType& Delta() const { return delta; }
82  OutputDataType& Delta() { return delta; }
83 
87  template<typename Archive>
88  void Serialize(Archive& ar, const unsigned int /* version */);
89 
90  private:
92  size_t inSize;
93 
95  size_t outSize;
96 
98  OutputDataType constantOutput;
99 
101  OutputDataType delta;
102 
104  InputDataType inputParameter;
105 
107  OutputDataType outputParameter;
108 }; // class ConstantLayer
109 
110 } // namespace ann
111 } // namespace mlpack
112 
113 // Include implementation.
114 #include "constant_impl.hpp"
115 
116 #endif
InputDataType & InputParameter()
Modify the input parameter.
Definition: constant.hpp:72
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: constant.hpp:77
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
size_t inSize
Locally-stored number of input units.
Definition: constant.hpp:92
OutputDataType delta
Locally-stored delta object.
Definition: constant.hpp:101
OutputDataType & Delta()
Modify the delta.
Definition: constant.hpp:82
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Backward(const DataType &&, DataType &&, DataType &&g)
Ordinary feed backward pass of a neural network.
OutputDataType outputParameter
Locally-stored output parameter object.
Definition: constant.hpp:107
OutputDataType constantOutput
Locally-stored constant output matrix.
Definition: constant.hpp:98
Constant(const size_t outSize, const double scalar)
Create the Constant object that outputs a given constant scalar value given any input value...
InputDataType inputParameter
Locally-stored input parameter object.
Definition: constant.hpp:104
InputDataType & InputParameter() const
Get the input parameter.
Definition: constant.hpp:70
OutputDataType & OutputParameter() const
Get the output parameter.
Definition: constant.hpp:75
void Forward(const InputType &&input, OutputType &&output)
Ordinary feed forward pass of a neural network.
Implementation of the constant layer.
Definition: constant.hpp:34
size_t outSize
Locally-stored number of output units.
Definition: constant.hpp:95
OutputDataType & Delta() const
Get the delta.
Definition: constant.hpp:80