histogram#

class diffsptk.Histogram(n_bin=10, lower_bound=0, upper_bound=1, norm=False, softness=0.001)[source]#

See this page for details.

Parameters:
n_binint >= 1

Number of bins, \(K\).

lower_boundfloat < U

Lower bound of the histogram, \(L\).

upper_boundfloat > L

Upper bound of the histogram, \(U\).

normbool

If True, normalize the histogram.

softnessfloat > 0

A smoothing parameter. The smaller value makes the output closer to the true histogram, but the gradient vanishes.

References

[1]

M. Avi-Aharon et al., “DeepHist: Differentiable joint and color histogram layers for image-to-image translation,” arXiv preprint arXiv:2005.03995, 2020.

forward(x)[source]#

Compute histogram.

Parameters:
xTensor [shape=(…, T)]

Input data.

Returns:
outTensor [shape=(…, K)]

Histogram.

Examples

>>> x = diffsptk.ramp(9)
>>> histogram = diffsptk.Histogram(n_bin=4, lower_bound=-0.1, upper_bound=9.1)
>>> h = histogram(x)
>>> h
tensor([3., 2., 2., 3.])
diffsptk.functional.histogram(x, n_bin=10, lower_bound=0, upper_bound=1, norm=False, softness=0.001)[source]#

Compute histogram.

Parameters:
xTensor [shape=(…, T)]

Input data.

n_binint >= 1

Number of bins, \(K\).

lower_boundfloat < U

Lower bound of the histogram, \(L\).

upper_boundfloat > L

Upper bound of the histogram, \(U\).

normbool

If True, normalize the histogram.

softnessfloat > 0

A smoothing parameter. The smaller value makes the output closer to the true histogram, but the gradient vanishes.

Returns:
outTensor [shape=(…, K)]

Histogram in [L, U].

See also

entropy