mlpack: src/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp Source File
hyperbolic_tangent_kernel.hpp
Go to the documentation of this file.
1 
14 #ifndef mlpack_CORE_KERNELS_HYPERBOLIC_TANGENT_KERNEL_HPP
15 #define mlpack_CORE_KERNELS_HYPERBOLIC_TANGENT_KERNEL_HPP
16 
17 #include <mlpack/core.hpp>
18 
19 namespace mlpack {
20 namespace kernel {
21 
31 {
32  public:
37  { }
38 
47  scale(scale), offset(offset)
48  { }
49 
61  template<typename VecTypeA, typename VecTypeB>
62  double Evaluate(const VecTypeA& a, const VecTypeB& b)
63  {
64  return tanh(scale * arma::dot(a, b) + offset);
65  }
66 
68  double Scale() const { return scale; }
70  double& Scale() { return scale; }
71 
73  double Offset() const { return offset; }
75  double& Offset() { return offset; }
76 
78  template<typename Archive>
79  void Serialize(Archive& ar, const unsigned int /* version */)
80  {
81  ar & data::CreateNVP(scale, "scale");
82  ar & data::CreateNVP(offset, "offset");
83  }
84 
85  private:
86  double scale;
87  double offset;
88 };
89 
90 } // namespace kernel
91 } // namespace mlpack
92 
93 #endif
HyperbolicTangentKernel()
This constructor sets the default scale to 1.0 and offset to 0.0.
Linear algebra utility functions, generally performed on matrices or vectors.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename boost::enable_if< HasSerialize< T >>::type *=0)
Call this function to produce a name-value pair; this is similar to BOOST_SERIALIZATION_NVP(), but should be used for types that have a Serialize() function (or contain a type that has a Serialize() function) instead of a serialize() function.
void Serialize(Archive &ar, const unsigned int)
Serialize the kernel.
double Evaluate(const VecTypeA &a, const VecTypeB &b)
Evaluate the hyperbolic tangent kernel.
double & Offset()
Modify offset for the kernel.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
HyperbolicTangentKernel(double scale, double offset)
Construct the hyperbolic tangent kernel with custom scale factor and offset.
double Offset() const
Get offset for the kernel.