entropy#

class diffsptk.Entropy(out_format='nat')[source]#

See this page for details.

Parameters:
out_format[‘bit’, ‘nat’, ‘dit’]

The unit of the entropy.

forward(p)[source]#

Compute entropy from probability sequence.

Parameters:
pTensor [shape=(…, N)]

The probability sequence.

Returns:
outTensor [shape=(…,)]

The entropy.

Examples

>>> p = diffsptk.step(3) / 4
>>> p
tensor([0.2500, 0.2500, 0.2500, 0.2500])
>>> entropy = diffsptk.Entropy("bit")
>>> h = entropy(p)
>>> h
tensor(2.)
diffsptk.functional.entropy(p, out_format='nat')[source]#

Calculate the entropy of a probability distribution.

Parameters:
pTensor [shape=(…, N)]

The probability.

out_format[‘bit’, ‘nat’, ‘dit’]

The output format.

Returns:
outTensor [shape=(…,)]

The entropy.

See also

histogram