Class HyperbolicTangentKernel

java.lang.Object
smile.math.kernel.HyperbolicTangent
smile.math.kernel.HyperbolicTangentKernel
All Implemented Interfaces:
Serializable, ToDoubleBiFunction<double[],double[]>, Function, DotProductKernel, MercerKernel<double[]>

public class HyperbolicTangentKernel extends HyperbolicTangent implements MercerKernel<double[]>
The hyperbolic tangent kernel.

k(u, v) = tanh(γ uTv - λ)

where γ is the scale of the used inner product and λ is the offset of the used inner product. If the offset is negative the likelihood of obtaining a kernel matrix that is not positive definite is much higher (since then even some diagonal elements may be negative), hence if this kernel has to be used, the offset should always be positive. Note, however, that this is no guarantee that the kernel will be positive.

The hyperbolic tangent kernel was quite popular for support vector machines due to its origin from neural networks. However, it should be used carefully since the kernel matrix may not be positive semi-definite. Besides, it was reported the hyperbolic tangent kernel is not better than the Gaussian kernel in general.

See Also:
  • Constructor Details

    • HyperbolicTangentKernel

      public HyperbolicTangentKernel()
      Constructor with scale 1.0 and offset 0.0.
    • HyperbolicTangentKernel

      public HyperbolicTangentKernel(double scale, double offset)
      Constructor.
      Parameters:
      scale - The scale parameter.
      offset - The offset parameter.
    • HyperbolicTangentKernel

      public HyperbolicTangentKernel(double scale, double offset, double[] lo, double[] hi)
      Constructor.
      Parameters:
      scale - The scale parameter.
      offset - The offset parameter.
      lo - The lower bound of scale and offset for hyperparameter tuning.
      hi - The upper bound of scale and offset for hyperparameter tuning.
  • Method Details

    • k

      public double k(double[] x, double[] y)
      Description copied from interface: MercerKernel
      Kernel function.
      Specified by:
      k in interface MercerKernel<double[]>
      Parameters:
      x - an object.
      y - an object.
      Returns:
      the kernel value.
    • kg

      public double[] kg(double[] x, double[] y)
      Description copied from interface: MercerKernel
      Computes the kernel and its gradient over hyperparameters.
      Specified by:
      kg in interface MercerKernel<double[]>
      Parameters:
      x - an object.
      y - an object.
      Returns:
      the kernel value and gradient.
    • of

      public HyperbolicTangentKernel of(double[] params)
      Description copied from interface: MercerKernel
      Returns the same kind kernel with the new hyperparameters.
      Specified by:
      of in interface MercerKernel<double[]>
      Parameters:
      params - the hyperparameters.
      Returns:
      the same kind kernel with the new hyperparameters.
    • hyperparameters

      public double[] hyperparameters()
      Description copied from interface: MercerKernel
      Returns the hyperparameters of kernel.
      Specified by:
      hyperparameters in interface MercerKernel<double[]>
      Returns:
      the hyperparameters of kernel.
    • lo

      public double[] lo()
      Description copied from interface: MercerKernel
      Returns the lower bound of hyperparameters (in hyperparameter tuning).
      Specified by:
      lo in interface MercerKernel<double[]>
      Returns:
      the lower bound of hyperparameters.
    • hi

      public double[] hi()
      Description copied from interface: MercerKernel
      Returns the upper bound of hyperparameters (in hyperparameter tuning).
      Specified by:
      hi in interface MercerKernel<double[]>
      Returns:
      the upper bound of hyperparameters.