% Generates random data for the dual averaging problem. The problem to
% be solved (after executing this method) is
%
% minimize (1/N) * sum(max(1 - A * x, 0)).
%
% The data matrix A given at the end of this method is of size N-by-n,
% and each individual data term is a single row of this matrix.

randn('state',1); rand('state',1);
N = 50;
n = 500;
A = .25 * randn(N, n);
x = zeros(n,1);
x(1) = .5; x(2) = .5;
y = sign(A * x);
flip_indices = (rand(N,1) > .95);
y(flip_indices) = -y(flip_indices);
A = sparse(diag(y)) * A;

fprintf('The objective value of the x generating the data is %d\n', sum(max(1 - A * x, 0)) / N);