function d = generate_datasets(cfreq, omega, omgpar, iswithin, iswpar)
% Creates a "small data" dataset of interest.
%
% cfreq    = vector of class frequencies; exact numbers generated
% omega    = random generator function for points in whole space
% omgpar   = parameter structure given on each call to omega
% iswithin = indicator function for class ic. f(point, ic) -> bool
% iswpar   = parameter structure given on each call to iswithin
%

if (nargin < 5)
  iswpar = [];
end

% These as parameters:
max_shots=3000;
nclasses=numel(cfreq);

d=[];
for ic=1:nclasses
  for ip=1:cfreq(ic)
    for is=1:max_shots
      p = omega(omgpar);
      if ~iswithin(p,ic,iswpar) continue ; end
      break
    end
    if (is==max_shots)
      error('Could not shoot inside class %d with %d shots.', ...
	    ic, max_shots);
    end
    d = [d ; p ic];
  end
end

