mlpack
add_impl.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_ADD_IMPL_HPP
14 #define MLPACK_METHODS_ANN_LAYER_ADD_IMPL_HPP
15 
16 // In case it hasn't yet been included.
17 #include "add.hpp"
18 
19 namespace mlpack {
20 namespace ann {
21 
22 template<typename InputDataType, typename OutputDataType>
24  outSize(outSize)
25 {
26  weights.set_size(WeightSize(), 1);
27 }
28 
29 template<typename InputDataType, typename OutputDataType>
30 template<typename eT>
32  const arma::Mat<eT>& input, arma::Mat<eT>& output)
33 {
34  output = input;
35  output.each_col() += weights;
36 }
37 
38 template<typename InputDataType, typename OutputDataType>
39 template<typename eT>
41  const arma::Mat<eT>& /* input */,
42  const arma::Mat<eT>& gy,
43  arma::Mat<eT>& g)
44 {
45  g = gy;
46 }
47 
48 template<typename InputDataType, typename OutputDataType>
49 template<typename eT>
51  const arma::Mat<eT>& /* input */,
52  const arma::Mat<eT>& error,
53  arma::Mat<eT>& gradient)
54 {
55  gradient = error;
56 }
57 
58 template<typename InputDataType, typename OutputDataType>
59 template<typename Archive>
61  Archive& ar, const uint32_t /* version */)
62 {
63  ar(CEREAL_NVP(outSize));
64 
65  if (cereal::is_loading<Archive>())
66  weights.set_size(outSize, 1);
67 }
68 
69 } // namespace ann
70 } // namespace mlpack
71 
72 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
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: add_impl.hpp:40
OutputDataType const & Gradient() const
Get the gradient.
Definition: add.hpp:96
Add(const size_t outSize=0)
Create the Add object using the specified number of output units.
Definition: add_impl.hpp:23
size_t WeightSize() const
Get the size of weights.
Definition: add.hpp:104
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: add_impl.hpp:31
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: add_impl.hpp:60