wolffd@0: function [data, c, prior, sd] = dem2ddat(ndata) wolffd@0: %DEM2DDAT Generates two dimensional data for demos. wolffd@0: % wolffd@0: % Description wolffd@0: % The data is drawn from three spherical Gaussian distributions with wolffd@0: % priors 0.3, 0.5 and 0.2; centres (2, 3.5), (0, 0) and (0,2); and wolffd@0: % standard deviations 0.2, 0.5 and 1.0. DATA = DEM2DDAT(NDATA) wolffd@0: % generates NDATA points. wolffd@0: % wolffd@0: % [DATA, C] = DEM2DDAT(NDATA) also returns a matrix containing the wolffd@0: % centres of the Gaussian distributions. wolffd@0: % wolffd@0: % See also wolffd@0: % DEMGMM1, DEMKMEAN, DEMKNN1 wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: input_dim = 2; wolffd@0: wolffd@0: % Fix seed for reproducible results wolffd@0: randn('state', 42); wolffd@0: wolffd@0: % Generate mixture of three Gaussians in two dimensional space wolffd@0: data = randn(ndata, input_dim); wolffd@0: wolffd@0: % Priors for the three clusters wolffd@0: prior(1) = 0.3; wolffd@0: prior(2) = 0.5; wolffd@0: prior(3) = 0.2; wolffd@0: wolffd@0: % Cluster centres wolffd@0: c = [2.0, 3.5; 0.0, 0.0; 0.0, 2.0]; wolffd@0: wolffd@0: % Cluster standard deviations wolffd@0: sd = [0.2 0.5 1.0]; wolffd@0: wolffd@0: % Put first cluster at (2, 3.5) wolffd@0: data(1:prior(1)*ndata, 1) = data(1:prior(1)*ndata, 1) * 0.2 + c(1,1); wolffd@0: data(1:prior(1)*ndata, 2) = data(1:prior(1)*ndata, 2) * 0.2 + c(1,2); wolffd@0: wolffd@0: % Leave second cluster at (0,0) wolffd@0: data((prior(1)*ndata + 1):(prior(2)+prior(1))*ndata, :) = ... wolffd@0: data((prior(1)*ndata + 1):(prior(2)+prior(1))*ndata, :) * 0.5; wolffd@0: wolffd@0: % Put third cluster at (0,2) wolffd@0: data((prior(1)+prior(2))*ndata +1:ndata, 2) = ... wolffd@0: data((prior(1)+prior(2))*ndata+1:ndata, 2) + c(3, 2);