Skip to main content
Tweeted twitter.com/StackMma/status/1103490541541564416
Became Hot Network Question
deleted 1 character in body
Source Link
bill s
  • 70.1k
  • 4
  • 105
  • 200

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMFGNNMF tries to solve is this: given a matrix $X$, factor it as $W.H$ where $W$ and $H$ both have all positive entries.

But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix $x$ -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see $x$ is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[w] Dimensions[h] 

So we can see that $w.h$ has the same dimensions as $x$. But

Norm[w.h - x] 

is very large, so $w.h$ is not a good approximation to $x$.

Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMFG tries to solve is this: given a matrix $X$, factor it as $W.H$ where $W$ and $H$ both have all positive entries.

But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix $x$ -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see $x$ is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[w] Dimensions[h] 

So we can see that $w.h$ has the same dimensions as $x$. But

Norm[w.h - x] 

is very large, so $w.h$ is not a good approximation to $x$.

Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMF tries to solve is this: given a matrix $X$, factor it as $W.H$ where $W$ and $H$ both have all positive entries.

But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix $x$ -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see $x$ is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[w] Dimensions[h] 

So we can see that $w.h$ has the same dimensions as $x$. But

Norm[w.h - x] 

is very large, so $w.h$ is not a good approximation to $x$.

Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

edited body
Source Link
Henrik Schumacher
  • 112.9k
  • 7
  • 197
  • 339

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMFG tries to solve is this: given a matrix $X$, factor it as $W.H$ where $W$ and $H$ both have all positive entries.

But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix $x$ -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see $x$ is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[W]Dimensions[w] Dimensions[H]Dimensions[h] 

So we can see that $w.h$ has the same dimensions as $x$. But

Norm[w.h - x] 

is very large, so $w.h$ is not a good approximation to $x$.

Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMFG tries to solve is this: given a matrix $X$, factor it as $W.H$ where $W$ and $H$ both have all positive entries.

But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix $x$ -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see $x$ is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[W] Dimensions[H] 

So we can see that $w.h$ has the same dimensions as $x$. But

Norm[w.h - x] 

is very large, so $w.h$ is not a good approximation to $x$.

Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMFG tries to solve is this: given a matrix $X$, factor it as $W.H$ where $W$ and $H$ both have all positive entries.

But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix $x$ -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see $x$ is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[w] Dimensions[h] 

So we can see that $w.h$ has the same dimensions as $x$. But

Norm[w.h - x] 

is very large, so $w.h$ is not a good approximation to $x$.

Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

Formatted code
Source Link
MarcoB
  • 68k
  • 19
  • 98
  • 205

NNMF -- using Using Non-Negative Matrix Factorization (NNMF)

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/\MathematicaForPredictionMathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMFG tries to solve is this: given a matrix X$X$, factor it as W.H$W.H$ where W$W$ and H$H$ both have all positive entries. 

But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix x$x$ -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see x$x$ is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[W] Dimensions[H] 

So we can see that w.h$w.h$ has the same dimensions as x$x$. But

Norm[w.h - x] 

is very large, so w.h$w.h$ is not a good approximation to x$x$. 

Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

NNMF -- using Non-Negative Matrix Factorization

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/\MathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMFG tries to solve is this: given a matrix X, factor it as W.H where W and H both have all positive entries. But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix x -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see x is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[W] Dimensions[H] 

So we can see that w.h has the same dimensions as x. But

Norm[w.h - x] 

is very large, so w.h is not a good approximation to x. Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

Using Non-Negative Matrix Factorization (NNMF)

I am trying to understand NNMF (Non-Negative Matrix Factorization). This is not a built-in function in Mathematica, but there is a package that implements it, which is refered to in this post. The package is loaded by:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/NonNegativeMatrixFactorization.m"] 

The problem that NNMFG tries to solve is this: given a matrix $X$, factor it as $W.H$ where $W$ and $H$ both have all positive entries. 

But when I try to apply this using the package, I cannot figure out what is happening. First, construct a matrix $x$ -- I build it random, but of low rank (rank 5):

xKer = RandomInteger[{0, 10}, {5, 5}]; xL = RandomInteger[{0, 10}, {50, 5}]; xR = RandomInteger[{0, 10}, {5, 100}]; x = xL.xKer.xR; Dimensions[x] MatrixRank[x] 

So you can see $x$ is 50 by 100, but is of rank only 5. Applying the NNMF command from the package:

{w, h} = GDCLS[x, 5, "MaxSteps" -> 1000]; Dimensions[W] Dimensions[H] 

So we can see that $w.h$ has the same dimensions as $x$. But

Norm[w.h - x] 

is very large, so $w.h$ is not a good approximation to $x$. 

Thus my questions: why doesn't NNMF seem to work? Am I expecting the wrong thing?

Source Link
bill s
  • 70.1k
  • 4
  • 105
  • 200
Loading