histogram#
- class diffsptk.Histogram(n_bin=10, lower_bound=0, upper_bound=1, norm=False, softness=0.001)[source]#
See this page for details. Note that the values at the edges of the bins cannot be counted correctly in the current implementation.
- Parameters:
- n_binint >= 1
The number of bins, \(K\).
- lower_boundfloat < U
The lower bound of the histogram, \(L\).
- upper_boundfloat > L
The upper bound of the histogram, \(U\).
- normbool
If True, normalizes 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)]
The input data.
- Returns:
- outTensor [shape=(…, K)]
The histogram.
Examples
>>> x = diffsptk.ramp(9) >>> histogram = diffsptk.Histogram(n_bin=4, lower_bound=0, upper_bound=9) >>> h = histogram(x) >>> h tensor([2.5000, 2.0000, 2.0000, 2.5000]) >>> 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)]
The input data.
- n_binint >= 1
The number of bins, \(K\).
- lower_boundfloat < U
The lower bound of the histogram, \(L\).
- upper_boundfloat > L
The upper bound of the histogram, \(U\).
- normbool
If True, normalizes 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)]
The histogram.
See also