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