mlpack  master
gradient_zero_visitor.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_VISITOR_GRADIENT_ZERO_VISITOR_HPP
14 #define MLPACK_METHODS_ANN_VISITOR_GRADIENT_ZERO_VISITOR_HPP
15 
18 
19 #include <boost/variant.hpp>
20 
21 namespace mlpack {
22 namespace ann {
23 
24 /*
25  * GradientZeroVisitor set the gradient to zero for the given module.
26  */
27 class GradientZeroVisitor : public boost::static_visitor<void>
28 {
29  public:
32 
34  template<typename LayerType>
35  void operator()(LayerType* layer) const;
36 
37  private:
39  template<typename T>
40  typename std::enable_if<
41  HasGradientCheck<T, arma::mat&(T::*)()>::value, void>::type
42  LayerGradients(T* layer, arma::mat& input) const;
43 
46  template<typename T, typename P>
47  typename std::enable_if<
48  !HasGradientCheck<T, P&(T::*)()>::value, void>::type
49  LayerGradients(T* layer, P& input) const;
50 };
51 
52 } // namespace ann
53 } // namespace mlpack
54 
55 // Include implementation.
56 #include "gradient_zero_visitor_impl.hpp"
57 
58 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
std::enable_if< HasGradientCheck< T, arma::mat &(T::*)()>::value, void >::type LayerGradients(T *layer, arma::mat &input) const
Set the gradient to zero if the module implements the Gradient() function.
GradientZeroVisitor()
Set the gradient to zero for the given module.
void operator()(LayerType *layer) const
Set the gradient to zero.