gradient_visitor.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_VISITOR_HPP
14 #define MLPACK_METHODS_ANN_VISITOR_GRADIENT_VISITOR_HPP
15 
18 
19 #include <boost/variant.hpp>
20 
21 namespace mlpack {
22 namespace ann {
23 
28 class GradientVisitor : public boost::static_visitor<void>
29 {
30  public:
33  GradientVisitor(arma::mat&& input, arma::mat&& delta);
34 
36  GradientVisitor(arma::mat&& input, arma::mat&& delta, const size_t index);
37 
39  template<typename LayerType>
40  void operator()(LayerType* layer) const;
41 
42  void operator()(MoreTypes layer) const;
43 
44  private:
46  arma::mat&& input;
47 
49  arma::mat&& delta;
50 
52  size_t index;
53 
55  bool hasIndex;
56 
59  template<typename T>
60  typename std::enable_if<
61  HasGradientCheck<T, arma::mat&(T::*)()>::value &&
62  !HasRunCheck<T, bool&(T::*)(void)>::value, void>::type
63  LayerGradients(T* layer, arma::mat& input) const;
64 
67  template<typename T>
68  typename std::enable_if<
69  HasGradientCheck<T, arma::mat&(T::*)()>::value &&
70  HasRunCheck<T, bool&(T::*)(void)>::value, void>::type
71  LayerGradients(T* layer, arma::mat& input) const;
72 
75  template<typename T, typename P>
76  typename std::enable_if<
77  !HasGradientCheck<T, P&(T::*)()>::value, void>::type
78  LayerGradients(T* layer, P& input) const;
79 };
80 
81 } // namespace ann
82 } // namespace mlpack
83 
84 // Include implementation.
85 #include "gradient_visitor_impl.hpp"
86 
87 #endif
boost::variant< Recurrent< arma::mat, arma::mat > *, RecurrentAttention< arma::mat, arma::mat > *, ReinforceNormal< arma::mat, arma::mat > *, Reparametrization< arma::mat, arma::mat > *, Select< arma::mat, arma::mat > *, Sequential< arma::mat, arma::mat, false > *, Sequential< arma::mat, arma::mat, true > *, Subview< arma::mat, arma::mat > *, VRClassReward< arma::mat, arma::mat > *, VirtualBatchNorm< arma::mat, arma::mat > *> MoreTypes
strip_type.hpp
Definition: add_to_po.hpp:21
SearchModeVisitor executes the Gradient() method of the given module using the input and delta parame...
void operator()(LayerType *layer) const
Executes the Gradient() method.
GradientVisitor(arma::mat &&input, arma::mat &&delta)
Executes the Gradient() method of the given module using the input and delta parameter.