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