Search code examples
octavenmf

octave nmf_bpas error: vertical dimensions mismatch (8x1 vs 1x400)


I have a problem with non-negative matrix factorization in octave. I try to estimate synergies from Emg-data, but octave only lets me do this for two or more synergies, but not for one. I was able to reproduce the problem with the following code. nmf_bpas is from the linear-algebra pkg from octave-forge.

V=rand(4, 20);
k=1; k2=2;
[W, H, Iter, HIS]=nmf_bpas(V,k);

with this input I get the following error:

error: vertical dimensions mismatch (4x1 vs 1x20)
error: called from
    nmf_bpas>getStopCriterion at line 373 column 19
    nmf_bpas at line 266 column 26

when I define k>1 as in the following it works

[W2, H2, Iter2, HIS2]=nmf_bpas(V,k2);

with this input, it works fine, and the output matrices are W2 (4x2) and H2 (2x20).

same problem is when I try it with other codes for nnmf and specify the input data Winit and Hinit for matrices (4x1) and (1x20) (eg.:[W, H] = nmf_pg (V, Winit, Hinit, tol, timelimit, maxiter))

in matlab it works with the nnmf function.

I would be glad about help


Solution

  • This seems to be a bug in nmf_bpas.

    From what I can tell, the bug is on line 373. Change

    pGrad = [gradW(gradW<0|W>0); gradH(gradH<0|H>0)];
    

    to

    pGrad = [gradW(gradW<0|W>0); gradH(gradH<0|H>0)(:)];
    

    and it will work.