Skip to content

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

@J-Fo-S

Description

@J-Fo-S

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions