% c10p11.m
%
% demonstration of the Helmholtz machine using the wake-sleep
% algorithm. 

rand('state',105);

ndim=4;        % dimension of the square of bars
ndimsq=ndim^2;
nu=400;        % number of examples
pbar=0.5;      % probability that a given bar is on
pout=0.05;      % extra noise added at the end

ii=ones(1,ndim);
oo=zeros(1,ndim);

conv=zeros(ndimsq,ndim);
for i=1:ndim
  conv((i-1)*ndim+(1:ndim),i)=ones(ndim,1);
end
	       
bars=conv*([rand(ndim/2,nu/2)<pbar zeros(ndim/2,nu/2); ...
      zeros(ndim/2,nu/2) rand(ndim/2,nu/2)<pbar]);  % which bars are on in which examples
u=bars.*(rand(ndimsq,nu)>pout) + (1-bars).*(rand(ndimsq,nu)<pout);
                                 % generate output noise
