comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/HME/gen_data.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function [data, ndata1, ndata2, targets]=gen_data(ndata, seed)
2 % Generate data from three classes in 2d
3 % Setting 'seed' for reproducible results
4 % OUTPUT
5 % data : data set
6 % ndata1, ndata2: separator
7
8 if nargin<1,
9 error('Missing data size');
10 end
11
12 input_dim = 2;
13 num_classes = 3;
14
15 if nargin==2,
16 % Fix seeds for reproducible results
17 randn('state', seed);
18 rand('state', seed);
19 end
20
21 % Generate mixture of three Gaussians in two dimensional space
22 data = randn(ndata, input_dim);
23 targets = zeros(ndata, 3);
24
25 % Priors for the clusters
26 prior(1) = 0.4;
27 prior(2) = 0.3;
28 prior(3) = 0.3;
29
30 % Cluster centres
31 c = [2.0, 2.0; 0.0, 0.0; 1, -1];
32
33 ndata1 = round(prior(1)*ndata);
34 ndata2 = round((prior(1) + prior(2))*ndata);
35 % Put first cluster at (2, 2)
36 data(1:ndata1, 1) = data(1:ndata1, 1) * 0.5 + c(1,1);
37 data(1:ndata1, 2) = data(1:ndata1, 2) * 0.5 + c(1,2);
38 targets(1:ndata1, 1) = 1;
39
40 % Leave second cluster at (0,0)
41 data((ndata1 + 1):ndata2, :) = data((ndata1 + 1):ndata2, :);
42 targets((ndata1+1):ndata2, 2) = 1;
43
44 data((ndata2+1):ndata, 1) = data((ndata2+1):ndata,1) *0.6 + c(3, 1);
45 data((ndata2+1):ndata, 2) = data((ndata2+1):ndata,2) *0.6 + c(3, 2);
46 targets((ndata2+1):ndata, 3) = 1;
47
48 if 0
49 ndata = 1;
50 data = x;
51 targets = [1 0 0];
52 end