mlpack
constant_impl.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_CONSTANT_IMPL_HPP
14 #define MLPACK_METHODS_ANN_LAYER_CONSTANT_IMPL_HPP
15 
16 // In case it hasn't yet been included.
17 #include "constant.hpp"
18 
19 namespace mlpack {
20 namespace ann {
21 
22 template<typename InputDataType, typename OutputDataType>
24  const size_t outSize,
25  const double scalar) :
26  inSize(0),
27  outSize(outSize)
28 {
29  constantOutput = OutputDataType(outSize, 1);
30  constantOutput.fill(scalar);
31 }
32 
33 template<typename InputDataType, typename OutputDataType>
34 template<typename InputType, typename OutputType>
36  const InputType& input, OutputType& output)
37 {
38  if (inSize == 0)
39  {
40  inSize = input.n_elem;
41  }
42 
43  output = constantOutput;
44 }
45 
46 template<typename InputDataType, typename OutputDataType>
47 template<typename DataType>
49  const DataType& /* input */, const DataType& /* gy */, DataType& g)
50 {
51  g = arma::zeros<DataType>(inSize, 1);
52 }
53 
54 template<typename InputDataType, typename OutputDataType>
55 template<typename Archive>
57  Archive& ar, const uint32_t /* version */)
58 {
59  ar(CEREAL_NVP(constantOutput));
60 }
61 
62 } // namespace ann
63 } // namespace mlpack
64 
65 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
Constant(const size_t outSize=0, const double scalar=0.0)
Create the Constant object that outputs a given constant scalar value given any input value...
Definition: constant_impl.hpp:23
void Forward(const InputType &input, OutputType &output)
Ordinary feed forward pass of a neural network.
Definition: constant_impl.hpp:35
void Backward(const DataType &, const DataType &, DataType &g)
Ordinary feed backward pass of a neural network.
Definition: constant_impl.hpp:48
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: constant_impl.hpp:56