function x = dataset ( boxmin, boxmax, noise, ncluster, center, spread )

%  DATASET returns a set of data points with some clustering and noise.
%
%  function x = dataset ( boxmin, boxmax, noise, ncluster, center, spread )
%
%  BOXMIN(NDIM), the minimum coordinate values of the data box.
%  BOXMAX(NDIM), the maximum coordinate values of the data box.
%  NOISE, the number of "noise" data points to generate.
%  NCLUSTER, the number of clustered data points to generate.
%  CENTER(NDIM,NC), the coordinates of the cluster centers.
%  SPREAD(NC), the "spread" of each cluster.  A value of 1 means that
%    most values in the cluster will be within 1 unit of the center.
%
%  X(NDIM,NCLUSTER+NOISE), the data point values.
%
  ndim = length ( boxmin );
  x = zeros ( ndim, ncluster + noise );
  nc = size ( center, 2 );
  
  for i = 1 : ncluster
    ic = 1 + fix ( nc * rand );
    x(1:ndim,i) = center(1:ndim,ic) + spread(ic) * randn(ndim,1);
  end
  
  for i = 1 : ndim
    x(i,1:ncluster) = min ( x(i,1:ncluster), boxmax(i) );
    x(i,1:ncluster) = max ( x(i,1:ncluster), boxmin(i) );
  end

  for i = 1 : ndim
    x(i,ncluster+1:ncluster+noise) = ...
      boxmin(i) + rand(1,noise) * ( boxmax(i) - boxmin(i) );
  end
