function [ attDataOut ] = AddMissingNodesAttrFromNeighborsNeighbors( data, attData, last_known_node, addMissingAttPerc, add2level)
    if nargin<4
        addMissingAttPerc = 1;
    end
    first_missing_node = last_known_node + 1;
    
    attDataOut = attData;
    m = size(data,1); % num rows
    ma = size(attDataOut,1);
    na = size(attDataOut,2);
    if (ma < m)
        attDataOut = [attDataOut; zeros(m-ma,na)];
    end

    for i = first_missing_node : size(data,1)

        neighbor = find(data(i,:), 1 ); %the missing node could have more than one neighbor if in a previous iteration we added a neighbor to it. The min should be the original neighbor

        %fprintf('i = %d, neighbor = %d\n', i, neighbor);
        %sum(data(i,:))

        if size(neighbor,2) > 0
            if add2level == 1
                neighborNeighbors = find(data(neighbor,:));
            else
                neighborNeighbors = neighbor;
            end
            if addMissingAttPerc == 1
                attDataOut(i,:) = attDataOut(i,:) | attDataOut(neighbor,:);
                for j = neighborNeighbors
                    attDataOut(i,:) = attDataOut(i,:) | attDataOut(j,:);
                end
            else
                attDataOut(i,:) = attDataOut(i,:) | chooseAttData(attDataOut(neighbor,:),addMissingAttPerc) ;
                for j = neighborNeighbors
                    attDataOut(i,:) = attDataOut(i,:) | chooseAttData(attDataOut(j,:),addMissingAttPerc);
                end
            end
        else
            fprintf('Warning: node %d doesnt have any neighbors\n', i);
        end
    end
end % function AddMissingNodesAttrFromNeighborsNeighbors


function [choosenAtt] = chooseAttData(inAttData, chooseAttPerc)
    choosenAtt = inAttData;
    attIndices = find(inAttData==1);
    for i= attIndices
        if rand(1)>chooseAttPerc
            choosenAtt(i) = 0;
        end
    end
end % function chooseAtt

