Class Tanh

All Implemented Interfaces:
Activation

public class Tanh extends AbstractActivation
Hyperbolic tangent activation function.

For example:

Operand<TFloat32> input = tf.constant(new float[]
                                   {-3.0f,-1.0f, 0.0f, 1.0f, 3.0f});
Tanh<TFloat32> tanh = new Tanh<>(tf);
Operand<TFloat32> result = tanh.call(input);
// result = [-0.9950547f, -0.7615942f,  0.f,  0.7615942f,  0.9950547f]
  • Field Details

  • Constructor Details

    • Tanh

      public Tanh()
      Creates a Hyperbolic tangent activation.
    • Tanh

      public Tanh(Map<String,Object> config)
      Creates a new Tanh from a configuration Map
      Parameters:
      config - the configuration map, this class does not use any of the entries in the configuration map
      Throws:
      IllegalArgumentException - if the configuration contains unsupported keys for this class or if the value for the name key does not match the name for the Activation
  • Method Details

    • tanh

      public static <T extends TNumber> Operand<T> tanh(Ops tf, Operand<T> input)
      Applies the Hyperbolic tangent activation function, tanh(x) = sinh(x)/cosh(x) = ((exp(x) - exp(-x))/(exp(x) + exp(-x))).

      Example Usage:

      Operand<TFloat32> input = ...;
      Operand<TFloat32> result = Tanh.tanh(tf, input);
      
      Type Parameters:
      T - the data type for the input
      Parameters:
      tf - the TensorFlow Ops
      input - the input
      Returns:
      the Hyperbolic tangent activation, tanh(x) = sinh(x)/cosh(x) = ((exp(x) - exp(-x))/(exp(x) + exp(-x))).
    • call

      public <T extends TNumber> Operand<T> call(Ops tf, Operand<T> input)
      Gets the calculation operation for the activation.
      Type Parameters:
      T - the data type of the input and the result
      Parameters:
      tf - the TensorFlow Ops
      input - the input tensor
      Returns:
      The operand for the activation
    • getConfig

      public Map<String,Object> getConfig()
      Gets a configuration map
      Specified by:
      getConfig in class AbstractActivation
      Returns:
      the configuration map
    • getName

      public String getName()
      Get the name of the activation as known by the TensorFlow Engine
      Specified by:
      getName in class AbstractActivation
      Returns:
      the name of the activation as known by the TensorFlow Engine