msvq#

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

See this page for details.

Parameters:
orderint >= 0

Order of vector, \(M\).

codebook_sizeint >= 1

Codebook size, \(K\).

n_stageint >= 1

Number of stages (quantizers), \(Q\).

**kwargsadditional keyword arguments

See this page for details.

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

Perform residual vector quantization.

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

Input vectors.

codebooksTensor [shape=(Q, K, M+1)]

External codebooks. If None, use internal codebooks.

**kwargsadditional keyword arguments

See this page for details.

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

Quantized vectors.

indicesTensor [shape=(…, Q)]

Codebook indices.

lossesTensor [shape=(Q,)]

Commitment losses.

Examples

>>> x = diffsptk.nrand(4)
>>> x
tensor([-0.5206,  1.0048, -0.3370,  1.3364, -0.2933])
>>> msvq = diffsptk.MultiStageVectorQuantization(4, 3, 2).eval()
>>> xq, indices, _ = msvq(x)
>>> xq
tensor([-0.4561,  0.9835, -0.3787, -0.1488, -0.8025])
>>> indices
tensor([0, 2])

See also

vq imsvq