function sample = subsample_data(data, n)

m = size(data,1);
p = cumsum(data(:,end)/sum(data(:,end)));
sample = data(1+sum(repmat(rand([1 n]), [m-1 1]) > repmat(p(1:end-1), [1 n])),1:(end-1));
sample = [sample ones([size(sample,1) 1])];
sample = marginalize(sample, 1:(size(sample,2)-1));