Calculate Frobenius Norm using Non-Negative Matrix Factorization

After performing Non-Negative Matrix Factorization (using R's rnmf() function), I'm left with W, H, and the fitted matrix (W%*%H).

The Frobenius norm (squared error) is calculated by squaring the difference between our original X and fitted matrix WH.

So, how can I use norm("matrix",type="f")to get my Frobenius norm? I'm slightly confused as I thought calculating this norm includes two matrices (X and WH), but norm() only takes 1 matrix as an input. Do I use the fitted matrix WH as my input?

Non-Negative Matrix Factorization (NNMF) aims to factorise the non-negative $n \times m$ matrix $V$ into two non-negative factor matrices $W$ ($n \times k$) and $H$ ($k \times m$) such that : \begin{align} min_{W,H} || V - WH||_F \end{align} ie. the Frobenius norm of the residual matrix $D = V - WH$ is minimised, this suggests that $V \approx WH$. Sometimes additional constraints inducing sparsity and/or smoothness properties on the matrices $W$ and $H$ are added but these are not part of the fundamental task of NNMF. Therefore (using the example in the documentation of the function rnmf) after retrieving the NNMF results:

data("tumor")
tumor.corrupted <- tumor
set.seed(1)
tumor.corrupted[sample(1:4900, round(0.05 * 4900), replace = FALSE)] <- 1
res.rnmf1 <- rnmf(X = tumor.corrupted, gamma = FALSE, my.seed = 1)


We can calculate the associated Frobenius norm using:

norm( tumor.corrupted - res.rnmf1$W %*% res.rnmf1$H, type = 'f')


Notice that it is good practice to have a few runs using different random seeds to generate the initial solution when using an NNMF decomposition. The minimisation task solved has local minima which may lead to different matrices $W$ and $H$.

I strong recommend going through the Berry et al. paper "Algorithms and Applications for Approximate Nonnegative Matrix Factorization"; it is very nicely written and gives an all-round overview of NNMF's internal mechanics as well as applications.

• Thanks! After looking at it a bit more I managed to realize it was much simpler than I had initially thought about it. Appreciate the descriptive answer. Apr 12, 2017 at 0:12
• My pleasure. Best of luck with the rest of your analysis! :D Apr 12, 2017 at 0:29