ssspy.special#

ssspy.special is a module related to special function.

Algorithms#

ssspy.special.logsumexp(X, axis=None, keepdims=False)#

Compute log-sum-exp values.

Parameters:
  • X (np.ndarray) – Elements to compute log-sum-exp.

  • axis (int or tuple[int], optional) – Axis or axes over which the sum is performed. Default: None.

  • keepdims (bool) – If True is given, axis dimension(s) is reduced. Default: False.

Return type:

ndarray

Returns:

np.ndarray of log-sum-exp values.

Examples

>>> import numpy as np

>>> X = np.array([[1, 2, 3], [4, 5, 6]])
>>> logsumexp(X, axis=0)
array([4.04858735, 5.04858735, 6.04858735])
>>> logsumexp(X, axis=1)
array([3.40760596, 6.40760596])
ssspy.special.softmax(X, axis=None)#

Compute softmax values.

Parameters:
  • X (np.ndarray) – Elements to compute softmax.

  • axis (int or tuple[int], optional) – Axis or axes over which the sum is performed. Default: None.

Return type:

ndarray

Returns:

np.ndarray of softmax values.

Examples

>>> import numpy as np

>>> X = np.array([[1, 2, 3], [4, 5, 6]])
>>> softmax(X, axis=0)
array([[0.04742587, 0.04742587, 0.04742587],
    [0.95257413, 0.95257413, 0.95257413]])
>>> softmax(X, axis=1)
array([[0.09003057, 0.24472847, 0.66524096],
    [0.09003057, 0.24472847, 0.66524096]])