1 %X is generated following a gaussian mixture \sum pi_r N(meanX_k, covX_r)
2 %Y is generated then, with Y_i ~ \sum pi_r N(Beta_r.X_i, covY_r)
3 function[X,Y,Z] = generateIO(meanX, covX, covY, pi, beta, n)
5 [p, ~, k] = size(covX);
6 [m, ~, ~] = size(covY);
7 if exist('octave_config_info')
8 %Octave statistics package doesn't have gmdistribution()
13 %TODO: vectorize ? http://stackoverflow.com/questions/2977497/weighted-random-numbers-in-matlab
15 [~,Z(i)] = min(cs - tmpRand01 >= 0);
16 X(i,:) = mvnrnd(meanX(Z(i),:), covX(:,:,Z(i)), 1);
19 gmDistX = gmdistribution(meanX, covX, pi);
20 [X, Z] = random(gmDistX, n);
30 BXir(mm) = dot(X(i,:), beta(:,mm,r));
32 %add pi(r) * N(beta_r . X_i, covY) to Y_i
33 Y(i,:) = Y(i,:) + pi(r) * mvnrnd(BXir, covY(:,:,r), 1);