sum(Y,2)/size(Y,2);
else
    G = @(x) G*x;
end

%% Loop until all sub-problems have been solved to within desired accuracy
iter = 0;
test=[];
dn=[[1:2:2*opts.sample]', ones(opts.sample,1)];
Xi=inv(dn'*dn)*dn';
tic
while ~isempty(x)
    iter = iter + 1;

    %% Projected gradient descent with exact line search update
    x_ = gather(x);
    df = -h + G(x);
    passive=max(x>0,df<0);
    df_=df.*passive;
    alpha=sum(df_.^2,1)./sum(df_.*(G(df_)),1);
    alpha(isnan(alpha))=0;
    x = x - df_.*alpha;
    x(x<