nmf#

diffsptk.NMF#

alias of NonnegativeMatrixFactorization

class diffsptk.NonnegativeMatrixFactorization(n_data, order, n_comp, *, beta=0, n_iter=100, eps=1e-05, act_norm=False, batch_size=None, seed=None, verbose=False)[source]#

Nonnegative matrix factorization module. Note that the forward method is not differentiable.

Parameters:
n_dataint >= 1

The number of vectors, \(T\).

orderint >= 0

The order of the vector, \(M\).

n_compint >= 1

The number of principal components, \(K\).

betafloat

A control parameter of beta-divergence, \(\beta\). 0: Itakura-Saito divergence, 1: generalized Kullback-Leibler divergence, 2: Euclidean distance.

n_iterint >= 1

The number of iterations.

epsfloat >= 0

The convergence threshold.

act_normbool

If True, normalizes the activation to sum to one.

seedint or None

The random seed.

batch_sizeint >= 1 or None

The bBatch size.

verbosebool or int

If 1, shows the distance at each iteration; if 2, shows progress bars.

References

[1]

M. Nakano et al., “Convergence-guaranteed multiplicative algorithms for nonnegative matrix factorization with beta-divergence,” IEEE International Workshop on Machine Learning for Signal Processing, pp. 283-288, 2010.

forward(x)[source]#

Estimate the coefficient matrix and dictionary matrix.

Parameters:
xTensor [shape=(T, M+1)] or DataLoader

The input vectors or a DataLoader that yields the input vectors.

Returns:
paramstuple of Tensors [shape=((T, K), (K, M+1))]

The estimated coefficient matrix and dictionary matrix.

divergenceTensor [scalar]

The divergence between the input and reconstructed vectors.

Examples

>>> x = diffsptk.nrand(10, 3) ** 2
>>> nmf = diffsptk.NMF(10, 3, 2)
>>> (U, H), _ = nmf(x)
>>> U.shape
torch.Size([10, 2])
>>> H.shape
torch.Size([2, 4])
>>> y = U @ H
>>> y.shape
torch.Size([10, 4])
transform(x)[source]#

Transform the input vectors using the estimated parameters.

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

The input vectors.

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

The transformed vectors.

warmup(x, **lbg_params)[source]#

Initialize the dictionary matrix by K-means clustering.

Parameters:
xTensor [shape=(T, M+1)] or DataLoader

The training data.

lbg_paramsadditional keyword arguments

The parameters for the Linde-Buzo-Gray algorithm.

See also

pca lbg