vq#

class diffsptk.VectorQuantization(order, codebook_size, **kwargs)[source]#

See this page for details.

Parameters:
orderint >= 0 [scalar]

Order of vector, \(M\).

codebook_sizeint >= 1 [scalar]

Codebook size, \(K\).

**kwargsadditional keyword arguments

See this page for details.

forward(x, codebook=None, **kwargs)[source]#

Perform vector quantization.

Parameters:
xTensor [shape=(…, M+1)]

Input vectors.

codebookTensor [shape=(K, M+1)]

External codebook. If None, use internal codebook.

**kwargsadditional keyword arguments

See this page for details.

Returns:
xqTensor [shape=(…, M+1)]

Quantized vectors.

indicesTensor [shape=(…,)]

Codebook indices.

lossTensor [scalar]

Commitment loss.

Examples

>>> x = diffsptk.nrand(4)
>>> x
tensor([ 0.7947,  0.1007,  1.2290, -0.5019,  1.5552])
>>> vq = diffsptk.VectorQuantization(4, 2).eval()
>>> xq, _, _ = vq(x)
>>> xq
tensor([0.3620, 0.2736, 0.7098, 0.7106, 0.6494]

See also

ivq lbg