/usr/include/mlpack/core/kernels/hyperbolic_tangent_kernel.hpp is in libmlpack-dev 1.0.10-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | /**
* @file hyperbolic_tangent_kernel.hpp
* @author Ajinkya Kale <kaleajinkya@gmail.com>
*
* Implementation of the hyperbolic tangent kernel.
*
* This file is part of MLPACK 1.0.10.
*
* MLPACK is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* MLPACK is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details (LICENSE.txt).
*
* You should have received a copy of the GNU General Public License along with
* MLPACK. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MLPACK_CORE_KERNELS_HYPERBOLIC_TANGENT_KERNEL_HPP
#define __MLPACK_CORE_KERNELS_HYPERBOLIC_TANGENT_KERNEL_HPP
#include <mlpack/core.hpp>
namespace mlpack {
namespace kernel {
/**
* Hyperbolic tangent kernel. For any two vectors @f$ x @f$, @f$ y @f$ and a
* given scale @f$ s @f$ and offset @f$ t @f$
*
* @f[
* K(x, y) = \tanh(s <x, y> + t)
* @f]
*/
class HyperbolicTangentKernel
{
public:
/**
* This constructor sets the default scale to 1.0 and offset to 0.0.
*/
HyperbolicTangentKernel() : scale(1.0), offset(0.0)
{ }
/**
* Construct the hyperbolic tangent kernel with custom scale factor and
* offset.
*
* @param scale Scaling factor for <x, y>.
* @param offset Kernel offset.
*/
HyperbolicTangentKernel(double scale, double offset) :
scale(scale), offset(offset)
{ }
/**
* Evaluate the hyperbolic tangent kernel. This evaluation uses Armadillo's
* dot() function.
*
* @tparam VecType Type of vector (should be arma::vec or arma::spvec).
* @param a First vector.
* @param b Second vector.
* @return K(a, b).
*/
template<typename VecType>
double Evaluate(const VecType& a, const VecType& b)
{
return tanh(scale * arma::dot(a, b) + offset);
}
//! Get scale factor.
double Scale() const { return scale; }
//! Modify scale factor.
double& Scale() { return scale; }
//! Get offset for the kernel.
double Offset() const { return offset; }
//! Modify offset for the kernel.
double& Offset() { return offset; }
//! Convert object to string.
std::string ToString() const
{
std::ostringstream convert;
convert << "HyperbolicTangentKernel [" << this << "]" << std::endl;
convert << " Scale: " << scale << std::endl;
convert << " Offset: " << offset << std::endl;
return convert.str();
}
private:
double scale;
double offset;
};
}; // namespace kernel
}; // namespace mlpack
#endif
|