wolffd@0
|
1 function [data, c, prior, sd] = dem2ddat(ndata)
|
wolffd@0
|
2 %DEM2DDAT Generates two dimensional data for demos.
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Description
|
wolffd@0
|
5 % The data is drawn from three spherical Gaussian distributions with
|
wolffd@0
|
6 % priors 0.3, 0.5 and 0.2; centres (2, 3.5), (0, 0) and (0,2); and
|
wolffd@0
|
7 % standard deviations 0.2, 0.5 and 1.0. DATA = DEM2DDAT(NDATA)
|
wolffd@0
|
8 % generates NDATA points.
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % [DATA, C] = DEM2DDAT(NDATA) also returns a matrix containing the
|
wolffd@0
|
11 % centres of the Gaussian distributions.
|
wolffd@0
|
12 %
|
wolffd@0
|
13 % See also
|
wolffd@0
|
14 % DEMGMM1, DEMKMEAN, DEMKNN1
|
wolffd@0
|
15 %
|
wolffd@0
|
16
|
wolffd@0
|
17 % Copyright (c) Ian T Nabney (1996-2001)
|
wolffd@0
|
18
|
wolffd@0
|
19 input_dim = 2;
|
wolffd@0
|
20
|
wolffd@0
|
21 % Fix seed for reproducible results
|
wolffd@0
|
22 randn('state', 42);
|
wolffd@0
|
23
|
wolffd@0
|
24 % Generate mixture of three Gaussians in two dimensional space
|
wolffd@0
|
25 data = randn(ndata, input_dim);
|
wolffd@0
|
26
|
wolffd@0
|
27 % Priors for the three clusters
|
wolffd@0
|
28 prior(1) = 0.3;
|
wolffd@0
|
29 prior(2) = 0.5;
|
wolffd@0
|
30 prior(3) = 0.2;
|
wolffd@0
|
31
|
wolffd@0
|
32 % Cluster centres
|
wolffd@0
|
33 c = [2.0, 3.5; 0.0, 0.0; 0.0, 2.0];
|
wolffd@0
|
34
|
wolffd@0
|
35 % Cluster standard deviations
|
wolffd@0
|
36 sd = [0.2 0.5 1.0];
|
wolffd@0
|
37
|
wolffd@0
|
38 % Put first cluster at (2, 3.5)
|
wolffd@0
|
39 data(1:prior(1)*ndata, 1) = data(1:prior(1)*ndata, 1) * 0.2 + c(1,1);
|
wolffd@0
|
40 data(1:prior(1)*ndata, 2) = data(1:prior(1)*ndata, 2) * 0.2 + c(1,2);
|
wolffd@0
|
41
|
wolffd@0
|
42 % Leave second cluster at (0,0)
|
wolffd@0
|
43 data((prior(1)*ndata + 1):(prior(2)+prior(1))*ndata, :) = ...
|
wolffd@0
|
44 data((prior(1)*ndata + 1):(prior(2)+prior(1))*ndata, :) * 0.5;
|
wolffd@0
|
45
|
wolffd@0
|
46 % Put third cluster at (0,2)
|
wolffd@0
|
47 data((prior(1)+prior(2))*ndata +1:ndata, 2) = ...
|
wolffd@0
|
48 data((prior(1)+prior(2))*ndata+1:ndata, 2) + c(3, 2);
|