mlpack  2.2.5
hyperbolic_tangent_kernel.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_KERNELS_HYPERBOLIC_TANGENT_KERNEL_HPP
13 #define MLPACK_CORE_KERNELS_HYPERBOLIC_TANGENT_KERNEL_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace kernel {
19 
29 {
30  public:
34  HyperbolicTangentKernel() : scale(1.0), offset(0.0)
35  { }
36 
44  HyperbolicTangentKernel(double scale, double offset) :
45  scale(scale), offset(offset)
46  { }
47 
59  template<typename VecTypeA, typename VecTypeB>
60  double Evaluate(const VecTypeA& a, const VecTypeB& b)
61  {
62  return tanh(scale * arma::dot(a, b) + offset);
63  }
64 
66  double Scale() const { return scale; }
68  double& Scale() { return scale; }
69 
71  double Offset() const { return offset; }
73  double& Offset() { return offset; }
74 
76  template<typename Archive>
77  void Serialize(Archive& ar, const unsigned int /* version */)
78  {
79  ar & data::CreateNVP(scale, "scale");
80  ar & data::CreateNVP(offset, "offset");
81  }
82 
83  private:
84  double scale;
85  double offset;
86 };
87 
88 } // namespace kernel
89 } // namespace mlpack
90 
91 #endif
double Evaluate(const VecTypeA &a, const VecTypeB &b)
Evaluate the hyperbolic tangent kernel.
HyperbolicTangentKernel(double scale, double offset)
Construct the hyperbolic tangent kernel with custom scale factor and offset.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
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.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Offset() const
Get offset for the kernel.
void Serialize(Archive &ar, const unsigned int)
Serialize the kernel.
HyperbolicTangentKernel()
This constructor sets the default scale to 1.0 and offset to 0.0.
double & Offset()
Modify offset for the kernel.