Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug? Outer iterations using W_init and H_init cause index error #12

Open
J-Fo-S opened this issue Jun 25, 2021 · 1 comment
Open

Bug? Outer iterations using W_init and H_init cause index error #12

J-Fo-S opened this issue Jun 25, 2021 · 1 comment

Comments

@J-Fo-S
Copy link

J-Fo-S commented Jun 25, 2021

Hello, me again - I may have come across a bug, though of course it could simply be a mistake on my end. I was trying to replicate a line of code from the matlab demo where iterations are forced by and outside for-loop (i.e., each internal max_iter =1) What is happening is that when I try to run many iterations with W_init and H_init set to the previous W and H, I immediately receive this following error:

File "/home/jsherman/miniconda3/envs/mfadae/lib/python3.7/site-packages/seqnmf/seqnmf.py", line 58, in seqnmf
X[mask] = X_hat[mask]
IndexError: boolean index did not match indexed array along dimension 1; dimension is 96 but corresponding boolean dimension is 102

I am wondering if it has to do with the line below
ln 44 T = X.shape[1] + 2 * L

My simple reason is that for my case L is 3, so 2*L is 6 which is the amount of the index error

The original matlab shows
% zeropad data by L X = [zeros(N,L),X,zeros(N,L)]; [N, T] = size(X);

Their iterative code is

[W, H, ~,loadings,power]= seqNMF(X,'K',K,'L',L,...
            'lambda', .00002,'lambdaL1W', 0, 'lambdaL1H', 0, ...
            'lambdaOrthoW', 0, 'lambdaOrthoH', 0.1, 'maxiter', 1, 'showPlot', 0); `

for iteri = 1:1000
    
    if iteri<20 || mod(iteri,10)==0
        clf; SimpleWHPlotSpectrograms(W(:,:,:),H(:,tstart:end), [], 0)
        set(gcf, 'color', [0 0 0])
        title(['Iteration ' num2str(iteri)]); drawnow
        cdata = print(gcf, '-RGBImage', '-r300');
        [w, h, ~] = size(cdata);
        cdata = reshape(cdata, w*h,3);
        cdata(mean(cdata,2)==255,:)=1;
        cdata = reshape(cdata,w,h,3); 
        step(obj, cdata);
    end
    [W, H]= seqNMF(X,'K',K,'L',L,...
            'lambda', .00002,'lambdaL1W', 0.5, 'lambdaL1H', 0,...
            'maxiter', 1, 'showPlot', 0,...
            'lambdaOrthoW', 0, 'lambdaOrthoH', 0.1, 'W_init', W, 'H_init', H, 'SortFactors', 0);

Mine is

W, H, cost, loading, power = seqnmf(w_s, K=self.source_num, L=3, Lambda=0.001, lambda_L1W=0, lambda_OrthH=0,\
            max_iter=1, sort_factors=0)
for i in range(0, 1000):
    W, H, cost, loading, power = seqnmf(w_s, K=self.source_num, L=3, Lambda=0.001, lambda_L1W=0, lambda_OrthH=0,\
    W_init=W, H_init=H, max_iter=1, sort_factors=0)
@J-Fo-S J-Fo-S changed the title Bug? Iterative runs cause index error Bug? Outer iterations using W_init and H_init cause index error Jun 25, 2021
@jeremymanning
Copy link
Member

This could well be a bug-- as I had mentioned, this library hasn't been debugged or tested with any sort of rigor. For what it's worth, I think the right way to set up some initial tests would be something like:

  • Load in the sample dataset from the MATLAB toolbox
  • Modify the MATLAB code so that it saves the output of each line
  • In the Python version, load in the same sample dataset, and verify that every line of the Python version matches each saved output from the MATLAB version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants