Exemple #1
0
    def compute(self, arg):
        r"""
        Compute the hyperbolic tangent function value for a specified argument.

        :param arg: argument to the hyperbolic tangent function.

        :type arg: float

        :returns: the hyperbolic tangent function value.

        :rtype: float

        EXAMPLES:

        Once an instance is created, the activation function values are
        obtainted through invocation of :meth:`compute`:

        >>> from yaplf.utility.activation import \
        ... HyperbolicTangentActivationFunction
        >>> f = HyperbolicTangentActivationFunction()
        >>> f.compute(0)
        0.0
        >>> f.compute(1)
        0.46211715726000974

        The higher the value for :obj:`beta`, the more a sigmoidal function
        approximates a step function (i.e., that constantly equal
        to ``-1`` when its argument is negative, constantly equal to ``1``
        otherwise):

        >>> f = HyperbolicTangentActivationFunction(10)
        >>> f.compute(0)
        0.0
        >>> f.compute(1)
        0.99990920426259511

        AUTHORS:

        - Dario Malchiodi (2010-04-02)

        """

        return (exp(self.beta * arg) - 1) / (exp(self.beta * arg) + 1)
Exemple #2
0
    def compute(self, arg):
        r"""
        Compute the sigmoid function value for a specified argument.

        :param arg: argument to the sigmoid function.

        :type arg: float

        :returns: the sigmoid function value.

        :rtype: float

        EXAMPLES:

        Once an instance is created, the activation function values are
        obtainted through invocation of the :meth;`compute` method:

        >>> from yaplf.utility.activation import SigmoidActivationFunction
        >>> f = SigmoidActivationFunction()
        >>> f.compute(0)
        0.5
        >>> f.compute(1)
        0.7310585786300049

        The higher the value for :obj:`beta`, the more a sigmoidal function
        approximates the Heaviside step function (i.e., that constantly equal
        to ``0`` when its argument is negative, constantly equal to ``1``
        otherwise):

        >>> f = SigmoidActivationFunction(10)
        >>> f.compute(0)
        0.5
        >>> f.compute(1)
        0.99995460213129761

        AUTHORS:

        - Dario Malchiodi (2010-02-22)

        """

        return 1 / (1 + exp(-1 * self.beta * arg))