0) = 0;
    
    %% If max. iterations has not been reached, log consecutive error history (see function help)
    % wait for two times opts.sample and then use the error estimator
    if iter>opts.max_iter
        ids=true(1,size(x,2));
        if opts.display
            disp('Max. number of iterations has been reached.');
        end
    elseif ~opts.use_std
        if mod(iter,2)==1
            test = [test' log((sum(gather(x)-x_,1).^2)./sum(x_.^2,1))'/2]';
            if size(test,1)>opts.sample
      