mlpack  master
hard_tanh.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LAYER_HARD_TANH_HPP
13 #define MLPACK_METHODS_ANN_LAYER_HARD_TANH_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace ann {
19 
45 template <
46  typename InputDataType = arma::mat,
47  typename OutputDataType = arma::mat
48 >
49 class HardTanH
50 {
51  public:
60  HardTanH(const double maxValue = 1, const double minValue = -1);
61 
69  template<typename InputType, typename OutputType>
70  void Forward(const InputType&& input, OutputType&& output);
71 
81  template<typename DataType>
82  void Backward(const DataType&& input,
83  DataType&& gy,
84  DataType&& g);
85 
87  InputDataType const& InputParameter() const { return inputParameter; }
89  InputDataType& InputParameter() { return inputParameter; }
90 
92  OutputDataType const& OutputParameter() const { return outputParameter; }
94  OutputDataType& OutputParameter() { return outputParameter; }
95 
97  OutputDataType const& Delta() const { return delta; }
99  OutputDataType& Delta() { return delta; }
100 
102  double const& MaxValue() const { return maxValue; }
104  double& MaxValue() { return maxValue; }
105 
107  double const& MinValue() const { return minValue; }
109  double& MinValue() { return minValue; }
110 
114  template<typename Archive>
115  void Serialize(Archive& ar, const unsigned int /* version */);
116 
117  private:
119  OutputDataType delta;
120 
122  InputDataType inputParameter;
123 
125  OutputDataType outputParameter;
126 
128  double maxValue;
129 
131  double minValue;
132 }; // class HardTanH
133 
134 } // namespace ann
135 } // namespace mlpack
136 
137 // Include implementation.
138 #include "hard_tanh_impl.hpp"
139 
140 #endif
double maxValue
Maximum value for the HardTanH function.
Definition: hard_tanh.hpp:128
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
double const & MaxValue() const
Get the maximum value.
Definition: hard_tanh.hpp:102
double & MaxValue()
Modify the maximum value.
Definition: hard_tanh.hpp:104
double & MinValue()
Modify the minimum value.
Definition: hard_tanh.hpp:109
The Hard Tanh activation function, defined by.
Definition: hard_tanh.hpp:49
OutputDataType & Delta()
Modify the delta.
Definition: hard_tanh.hpp:99
double const & MinValue() const
Get the minimum value.
Definition: hard_tanh.hpp:107
HardTanH(const double maxValue=1, const double minValue=-1)
Create the HardTanH object using the specified parameters.
double minValue
Minimum value for the HardTanH function.
Definition: hard_tanh.hpp:131
OutputDataType const & Delta() const
Get the delta.
Definition: hard_tanh.hpp:97
InputDataType & InputParameter()
Modify the input parameter.
Definition: hard_tanh.hpp:89
OutputDataType delta
Locally-stored delta object.
Definition: hard_tanh.hpp:119
InputDataType const & InputParameter() const
Get the input parameter.
Definition: hard_tanh.hpp:87
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: hard_tanh.hpp:94
InputDataType inputParameter
Locally-stored input parameter object.
Definition: hard_tanh.hpp:122
void Backward(const DataType &&input, DataType &&gy, DataType &&g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: hard_tanh.hpp:92
void Forward(const InputType &&input, OutputType &&output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
OutputDataType outputParameter
Locally-stored output parameter object.
Definition: hard_tanh.hpp:125